ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 2 | # 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 Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 16 | from tempest import clients |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 17 | from tempest.common.utils import data_utils |
Chris Yeoh | 01cb279 | 2013-02-09 22:25:37 +1030 | [diff] [blame] | 18 | from tempest.test import attr |
Giulio Fidente | 83181a9 | 2013-10-01 06:02:24 +0200 | [diff] [blame] | 19 | from tempest.test import skip_because |
Sean Dague | 09761f6 | 2013-05-13 15:20:40 -0400 | [diff] [blame] | 20 | from tempest.thirdparty.boto.test import BotoTestCase |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 21 | |
| 22 | |
| 23 | def compare_key_pairs(a, b): |
| 24 | return (a.name == b.name and |
| 25 | a.fingerprint == b.fingerprint) |
| 26 | |
| 27 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 28 | class EC2KeysTest(BotoTestCase): |
| 29 | |
| 30 | @classmethod |
| 31 | def setUpClass(cls): |
| 32 | super(EC2KeysTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 33 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 34 | cls.client = cls.os.ec2api_client |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 35 | cls.ec = cls.ec2_error_code |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 36 | |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 37 | # TODO(afazekas): merge create, delete, get test cases |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 38 | @attr(type='smoke') |
| 39 | def test_create_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 40 | # EC2 create KeyPair |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 41 | key_name = data_utils.rand_name("keypair-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 42 | 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 Fidente | 83181a9 | 2013-10-01 06:02:24 +0200 | [diff] [blame] | 47 | @skip_because(bug="1072318") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 48 | @attr(type='smoke') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 49 | def test_delete_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 50 | # EC2 delete KeyPair |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 51 | key_name = data_utils.rand_name("keypair-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 52 | 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 Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 58 | # EC2 get KeyPair |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 59 | key_name = data_utils.rand_name("keypair-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 60 | 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 Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 66 | def test_duplicate_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 67 | # EC2 duplicate KeyPair |
Masayuki Igawa | 259c113 | 2013-10-31 17:48:44 +0900 | [diff] [blame] | 68 | key_name = data_utils.rand_name("keypair-") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 69 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 70 | keypair = self.client.create_key_pair(key_name) |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 71 | self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate, |
| 72 | self.client.create_key_pair, |
| 73 | key_name) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 74 | self.assertTrue(compare_key_pairs(keypair, |
| 75 | self.client.get_key_pair(key_name))) |