blob: b9e5508d51b9c65741cb19e8f0731ddae4bdd72d [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
19import unittest2 as unittest
Matthew Treinisha83a16e2012-12-07 13:44:02 -050020
Attila Fazekasa23f5002012-10-23 19:32:45 +020021from tempest.common.utils.data_utils import rand_name
22from tempest import openstack
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()
37 cls.os = openstack.Manager()
38 cls.client = cls.os.ec2api_client
39
40 @attr(type='smoke')
41 def test_create_ec2_keypair(self):
42 """EC2 create KeyPair"""
43 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')
50 @unittest.skip("Skipped until the Bug #1072318 is resolved")
51 def test_delete_ec2_keypair(self):
52 """EC2 delete KeyPair"""
53 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):
60 """EC2 get KeyPair"""
61 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')
68 @unittest.skip("Skipped until the Bug #1072762 is resolved")
69 def test_duplicate_ec2_keypair(self):
70 """EC2 duplicate KeyPair"""
71 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)))