blob: be5db5530e8d3b2ff80cfe150624bb8d1b953ee6 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Attila Fazekasa23f5002012-10-23 19:32:45 +02002# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
Masayuki Igawa259c1132013-10-31 17:48:44 +090016from tempest.common.utils import data_utils
Masayuki Igawa224a8272014-02-17 15:07:43 +090017from tempest.thirdparty.boto import test as boto_test
Attila Fazekasa23f5002012-10-23 19:32:45 +020018
19
20def compare_key_pairs(a, b):
21 return (a.name == b.name and
22 a.fingerprint == b.fingerprint)
23
24
Masayuki Igawa224a8272014-02-17 15:07:43 +090025class EC2KeysTest(boto_test.BotoTestCase):
Attila Fazekasa23f5002012-10-23 19:32:45 +020026
27 @classmethod
Andrea Frittoli29fea352014-09-15 13:31:14 +010028 def resource_setup(cls):
29 super(EC2KeysTest, cls).resource_setup()
Attila Fazekasa23f5002012-10-23 19:32:45 +020030 cls.client = cls.os.ec2api_client
Attila Fazekas65e40082013-01-22 10:07:13 +010031 cls.ec = cls.ec2_error_code
Attila Fazekasa23f5002012-10-23 19:32:45 +020032
Attila Fazekas3e381f72013-08-01 16:52:23 +020033# TODO(afazekas): merge create, delete, get test cases
Attila Fazekasa23f5002012-10-23 19:32:45 +020034 def test_create_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050035 # EC2 create KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090036 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020037 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
38 keypair = self.client.create_key_pair(key_name)
39 self.assertTrue(compare_key_pairs(keypair,
40 self.client.get_key_pair(key_name)))
41
Attila Fazekasa23f5002012-10-23 19:32:45 +020042 def test_delete_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050043 # EC2 delete KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090044 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020045 self.client.create_key_pair(key_name)
46 self.client.delete_key_pair(key_name)
llg8212e4cd3922014-02-15 12:14:21 +080047 self.assertIsNone(self.client.get_key_pair(key_name))
Attila Fazekasa23f5002012-10-23 19:32:45 +020048
Attila Fazekasa23f5002012-10-23 19:32:45 +020049 def test_get_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050050 # EC2 get KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090051 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020052 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
53 keypair = self.client.create_key_pair(key_name)
54 self.assertTrue(compare_key_pairs(keypair,
55 self.client.get_key_pair(key_name)))
56
Attila Fazekasa23f5002012-10-23 19:32:45 +020057 def test_duplicate_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050058 # EC2 duplicate KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090059 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020060 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
61 keypair = self.client.create_key_pair(key_name)
Attila Fazekas65e40082013-01-22 10:07:13 +010062 self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate,
63 self.client.create_key_pair,
64 key_name)
Attila Fazekasa23f5002012-10-23 19:32:45 +020065 self.assertTrue(compare_key_pairs(keypair,
66 self.client.get_key_pair(key_name)))