blob: 540374aa15ecc29f8918c1925dfd6d415e912fd3 [file] [log] [blame]
Attila Fazekasa23f5002012-10-23 19:32:45 +02001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
3# Copyright 2012 OpenStack, LLC
4# 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
Attila Fazekasa23f5002012-10-23 19:32:45 +020018from nose.plugins.attrib import attr
ivan-zhu1feeb382013-01-24 10:14:39 +080019import testtools
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020
Matthew Treinish481466b2012-12-20 17:16:01 -050021from tempest import clients
Attila Fazekasa23f5002012-10-23 19:32:45 +020022from tempest.common.utils.data_utils import rand_name
Matthew Treinisha83a16e2012-12-07 13:44:02 -050023from tempest.testboto 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
31@attr("EC2")
32class EC2KeysTest(BotoTestCase):
33
34 @classmethod
35 def setUpClass(cls):
36 super(EC2KeysTest, cls).setUpClass()
Matthew Treinish481466b2012-12-20 17:16:01 -050037 cls.os = clients.Manager()
Attila Fazekasa23f5002012-10-23 19:32:45 +020038 cls.client = cls.os.ec2api_client
39
40 @attr(type='smoke')
41 def test_create_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050042 # EC2 create KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020043 key_name = rand_name("keypair-")
44 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
45 keypair = self.client.create_key_pair(key_name)
46 self.assertTrue(compare_key_pairs(keypair,
47 self.client.get_key_pair(key_name)))
48
49 @attr(type='smoke')
ivan-zhu1feeb382013-01-24 10:14:39 +080050 @testtools.skip("Skipped until the Bug #1072318 is resolved")
Attila Fazekasa23f5002012-10-23 19:32:45 +020051 def test_delete_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050052 # EC2 delete KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020053 key_name = rand_name("keypair-")
54 self.client.create_key_pair(key_name)
55 self.client.delete_key_pair(key_name)
56 self.assertEqual(None, self.client.get_key_pair(key_name))
57
58 @attr(type='smoke')
59 def test_get_ec2_keypair(self):
Sean Dague64ef48d2013-01-03 17:54:36 -050060 # EC2 get KeyPair
Attila Fazekasa23f5002012-10-23 19:32:45 +020061 key_name = rand_name("keypair-")
62 self.addResourceCleanUp(self.client.delete_key_pair, key_name)
63 keypair = self.client.create_key_pair(key_name)
64 self.assertTrue(compare_key_pairs(keypair,
65 self.client.get_key_pair(key_name)))
66
67 @attr(type='smoke')
ivan-zhu1feeb382013-01-24 10:14:39 +080068 @testtools.skip("Skipped until the Bug #1072762 is resolved")
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)
74 self.assertEC2ResponseError(self.error_code.client.
75 InvalidKeyPair.Duplicate,
76 self.client.create_key_pair,
77 key_name)
78 self.assertTrue(compare_key_pairs(keypair,
79 self.client.get_key_pair(key_name)))