blob: b4c1827c4a8121617de59cc5babddb6beb872f33 [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
Matthew Treinish481466b2012-12-20 17:16:01 -050016from tempest import clients
Masayuki Igawa259c1132013-10-31 17:48:44 +090017from tempest.common.utils import data_utils
Chris Yeoh01cb2792013-02-09 22:25:37 +103018from tempest.test import attr
Giulio Fidente83181a92013-10-01 06:02:24 +020019from tempest.test import skip_because
Sean Dague09761f62013-05-13 15:20:40 -040020from tempest.thirdparty.boto.test import BotoTestCase
Attila Fazekasa23f5002012-10-23 19:32:45 +020021
22
23def compare_key_pairs(a, b):
24 return (a.name == b.name and
25 a.fingerprint == b.fingerprint)
26
27
Attila Fazekasa23f5002012-10-23 19:32:45 +020028class EC2KeysTest(BotoTestCase):
29
30 @classmethod
31 def setUpClass(cls):
32 super(EC2KeysTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050033 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020034 cls.client = cls.os.ec2api_client
Attila Fazekas65e40082013-01-22 10:07:13 +010035 cls.ec = cls.ec2_error_code
Attila Fazekasa23f5002012-10-23 19:32:45 +020036
Attila Fazekas3e381f72013-08-01 16:52:23 +020037# TODO(afazekas): merge create, delete, get test cases
Attila Fazekasa23f5002012-10-23 19:32:45 +020038 @attr(type='smoke')
39 def test_create_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050040 # EC2 create KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090041 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020042 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
43 keypair = self.client.create_key_pair(key_name)
44 self.assertTrue(compare_key_pairs(keypair,
45 self.client.get_key_pair(key_name)))
46
Giulio Fidente83181a92013-10-01 06:02:24 +020047 @skip_because(bug="1072318")
Attila Fazekasa23f5002012-10-23 19:32:45 +020048 @attr(type='smoke')
Attila Fazekasa23f5002012-10-23 19:32:45 +020049 def test_delete_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050050 # EC2 delete 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.client.create_key_pair(key_name)
53 self.client.delete_key_pair(key_name)
54 self.assertEqual(None, self.client.get_key_pair(key_name))
55
56 @attr(type='smoke')
57 def test_get_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050058 # EC2 get 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)
62 self.assertTrue(compare_key_pairs(keypair,
63 self.client.get_key_pair(key_name)))
64
65 @attr(type='smoke')
Attila Fazekasa23f5002012-10-23 19:32:45 +020066 def test_duplicate_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050067 # EC2 duplicate KeyPair
Masayuki Igawa259c1132013-10-31 17:48:44 +090068 key_name = data_utils.rand_name("keypair-")
Attila Fazekasa23f5002012-10-23 19:32:45 +020069 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
70 keypair = self.client.create_key_pair(key_name)
Attila Fazekas65e40082013-01-22 10:07:13 +010071 self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate,
72 self.client.create_key_pair,
73 key_name)
Attila Fazekasa23f5002012-10-23 19:32:45 +020074 self.assertTrue(compare_key_pairs(keypair,
75 self.client.get_key_pair(key_name)))