Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # 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 | |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 18 | import testtools |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 19 | |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 20 | from tempest import clients |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 21 | from tempest.common.utils.data_utils import rand_name |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 22 | from tempest.test import attr |
Sean Dague | 09761f6 | 2013-05-13 15:20:40 -0400 | [diff] [blame^] | 23 | from tempest.thirdparty.boto.test import BotoTestCase |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 24 | |
| 25 | |
| 26 | def compare_key_pairs(a, b): |
| 27 | return (a.name == b.name and |
| 28 | a.fingerprint == b.fingerprint) |
| 29 | |
| 30 | |
| 31 | @attr("EC2") |
| 32 | class EC2KeysTest(BotoTestCase): |
| 33 | |
| 34 | @classmethod |
| 35 | def setUpClass(cls): |
| 36 | super(EC2KeysTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 37 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 38 | cls.client = cls.os.ec2api_client |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 39 | cls.ec = cls.ec2_error_code |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 40 | |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 41 | #TODO(afazekas): merge create, delete, get test cases |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 42 | @attr(type='smoke') |
| 43 | def test_create_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 44 | # EC2 create KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 45 | key_name = rand_name("keypair-") |
| 46 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 47 | keypair = self.client.create_key_pair(key_name) |
| 48 | self.assertTrue(compare_key_pairs(keypair, |
| 49 | self.client.get_key_pair(key_name))) |
| 50 | |
| 51 | @attr(type='smoke') |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 52 | @testtools.skip("Skipped until the Bug #1072318 is resolved") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 53 | def test_delete_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 54 | # EC2 delete KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 55 | key_name = rand_name("keypair-") |
| 56 | self.client.create_key_pair(key_name) |
| 57 | self.client.delete_key_pair(key_name) |
| 58 | self.assertEqual(None, self.client.get_key_pair(key_name)) |
| 59 | |
| 60 | @attr(type='smoke') |
| 61 | def test_get_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 62 | # EC2 get KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 63 | key_name = rand_name("keypair-") |
| 64 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 65 | keypair = self.client.create_key_pair(key_name) |
| 66 | self.assertTrue(compare_key_pairs(keypair, |
| 67 | self.client.get_key_pair(key_name))) |
| 68 | |
| 69 | @attr(type='smoke') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 70 | def test_duplicate_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 71 | # EC2 duplicate KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 72 | key_name = rand_name("keypair-") |
| 73 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 74 | keypair = self.client.create_key_pair(key_name) |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 75 | self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate, |
| 76 | self.client.create_key_pair, |
| 77 | key_name) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 78 | self.assertTrue(compare_key_pairs(keypair, |
| 79 | self.client.get_key_pair(key_name))) |