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 | |
Fei Long Wang | d39431f | 2015-05-14 11:30:48 +1200 | [diff] [blame] | 16 | from tempest.common.utils import data_utils |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 17 | from tempest import test |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 18 | from tempest.thirdparty.boto import test as boto_test |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 19 | |
| 20 | |
| 21 | def compare_key_pairs(a, b): |
| 22 | return (a.name == b.name and |
| 23 | a.fingerprint == b.fingerprint) |
| 24 | |
| 25 | |
Masayuki Igawa | 224a827 | 2014-02-17 15:07:43 +0900 | [diff] [blame] | 26 | class EC2KeysTest(boto_test.BotoTestCase): |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 27 | |
| 28 | @classmethod |
Emily Hugenbruch | e252a4a | 2015-02-27 15:43:12 +0000 | [diff] [blame] | 29 | def setup_clients(cls): |
| 30 | super(EC2KeysTest, cls).setup_clients() |
| 31 | cls.client = cls.os.ec2api_client |
| 32 | |
| 33 | @classmethod |
Andrea Frittoli | 29fea35 | 2014-09-15 13:31:14 +0100 | [diff] [blame] | 34 | def resource_setup(cls): |
| 35 | super(EC2KeysTest, cls).resource_setup() |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 36 | cls.ec = cls.ec2_error_code |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 37 | |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 38 | # TODO(afazekas): merge create, delete, get test cases |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 39 | @test.idempotent_id('54236804-01b7-4cfe-a6f9-bce1340feec8') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 40 | def test_create_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 41 | # EC2 create KeyPair |
Ken'ichi Ohmichi | a498b1d | 2015-03-23 01:56:52 +0000 | [diff] [blame] | 42 | key_name = data_utils.rand_name("keypair") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 43 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 44 | keypair = self.client.create_key_pair(key_name) |
| 45 | self.assertTrue(compare_key_pairs(keypair, |
| 46 | self.client.get_key_pair(key_name))) |
| 47 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 48 | @test.idempotent_id('3283b898-f90c-4952-b238-3e42b8c3f34f') |
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 |
Ken'ichi Ohmichi | a498b1d | 2015-03-23 01:56:52 +0000 | [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) |
llg8212 | e4cd392 | 2014-02-15 12:14:21 +0800 | [diff] [blame] | 54 | self.assertIsNone(self.client.get_key_pair(key_name)) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 55 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 56 | @test.idempotent_id('fd89bd26-4d4d-4cf3-a303-65dd9158fcdc') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 57 | def test_get_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 58 | # EC2 get KeyPair |
Ken'ichi Ohmichi | a498b1d | 2015-03-23 01:56:52 +0000 | [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 | |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 65 | @test.idempotent_id('daa73da1-e11c-4558-8d76-a716be79a401') |
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 |
Ken'ichi Ohmichi | a498b1d | 2015-03-23 01:56:52 +0000 | [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))) |