blob: 85a99c0c1e8c2899fd043604c23e3995215d881b [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02004# All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License"); you may
7# not use this file except in compliance with the License. You may obtain
8# a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15# License for the specific language governing permissions and limitations
16# under the License.
17
ivan-zhu1feeb382013-01-24 10:14:39 +080018import testtools
Matthew Treinisha83a16e2012-12-07 13:44:02 -050019
Matthew Treinish481466b2012-12-20 17:16:01 -050020from tempest import clients
Attila Fazekasa23f5002012-10-23 19:32:45 +020021from tempest.common.utils.data_utils import rand_name
Chris Yeoh01cb2792013-02-09 22:25:37 +103022from tempest.test import attr
Sean Dague09761f62013-05-13 15:20:40 -040023from tempest.thirdparty.boto.test import BotoTestCase
Attila Fazekasa23f5002012-10-23 19:32:45 +020024
25
26def compare_key_pairs(a, b):
27 return (a.name == b.name and
28 a.fingerprint == b.fingerprint)
29
30
Attila Fazekasa23f5002012-10-23 19:32:45 +020031class EC2KeysTest(BotoTestCase):
32
33 @classmethod
34 def setUpClass(cls):
35 super(EC2KeysTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050036 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020037 cls.client = cls.os.ec2api_client
Attila Fazekas65e40082013-01-22 10:07:13 +010038 cls.ec = cls.ec2_error_code
Attila Fazekasa23f5002012-10-23 19:32:45 +020039
Attila Fazekas3e381f72013-08-01 16:52:23 +020040# TODO(afazekas): merge create, delete, get test cases
Attila Fazekasa23f5002012-10-23 19:32:45 +020041 @attr(type='smoke')
42 def test_create_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050043 # EC2 create KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020044 key_name = rand_name("keypair-")
45 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
46 keypair = self.client.create_key_pair(key_name)
47 self.assertTrue(compare_key_pairs(keypair,
48 self.client.get_key_pair(key_name)))
49
50 @attr(type='smoke')
ivan-zhu1feeb382013-01-24 10:14:39 +080051 @testtools.skip("Skipped until the Bug #1072318 is resolved")
Attila Fazekasa23f5002012-10-23 19:32:45 +020052 def test_delete_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050053 # EC2 delete KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020054 key_name = rand_name("keypair-")
55 self.client.create_key_pair(key_name)
56 self.client.delete_key_pair(key_name)
57 self.assertEqual(None, self.client.get_key_pair(key_name))
58
59 @attr(type='smoke')
60 def test_get_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050061 # EC2 get KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020062 key_name = rand_name("keypair-")
63 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
64 keypair = self.client.create_key_pair(key_name)
65 self.assertTrue(compare_key_pairs(keypair,
66 self.client.get_key_pair(key_name)))
67
68 @attr(type='smoke')
Attila Fazekasa23f5002012-10-23 19:32:45 +020069 def test_duplicate_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050070 # EC2 duplicate KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020071 key_name = rand_name("keypair-")
72 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
73 keypair = self.client.create_key_pair(key_name)
Attila Fazekas65e40082013-01-22 10:07:13 +010074 self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate,
75 self.client.create_key_pair,
76 key_name)
Attila Fazekasa23f5002012-10-23 19:32:45 +020077 self.assertTrue(compare_key_pairs(keypair,
78 self.client.get_key_pair(key_name)))