Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 1 | # vim: tabstop=4 shiftwidth=4 softtabstop=4 |
| 2 | |
ZhiQiang Fan | 39f9722 | 2013-09-20 04:49:44 +0800 | [diff] [blame] | 3 | # Copyright 2012 OpenStack Foundation |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 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 | |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 31 | class EC2KeysTest(BotoTestCase): |
| 32 | |
| 33 | @classmethod |
| 34 | def setUpClass(cls): |
| 35 | super(EC2KeysTest, cls).setUpClass() |
Matthew Treinish | 481466b | 2012-12-20 17:16:01 -0500 | [diff] [blame] | 36 | cls.os = clients.Manager() |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 37 | cls.client = cls.os.ec2api_client |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 38 | cls.ec = cls.ec2_error_code |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 39 | |
Attila Fazekas | 3e381f7 | 2013-08-01 16:52:23 +0200 | [diff] [blame] | 40 | # TODO(afazekas): merge create, delete, get test cases |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 41 | @attr(type='smoke') |
| 42 | def test_create_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 43 | # EC2 create KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 44 | key_name = rand_name("keypair-") |
| 45 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 46 | keypair = self.client.create_key_pair(key_name) |
| 47 | self.assertTrue(compare_key_pairs(keypair, |
| 48 | self.client.get_key_pair(key_name))) |
| 49 | |
| 50 | @attr(type='smoke') |
ivan-zhu | 1feeb38 | 2013-01-24 10:14:39 +0800 | [diff] [blame] | 51 | @testtools.skip("Skipped until the Bug #1072318 is resolved") |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 52 | def test_delete_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 53 | # EC2 delete KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 54 | key_name = rand_name("keypair-") |
| 55 | self.client.create_key_pair(key_name) |
| 56 | self.client.delete_key_pair(key_name) |
| 57 | self.assertEqual(None, self.client.get_key_pair(key_name)) |
| 58 | |
| 59 | @attr(type='smoke') |
| 60 | def test_get_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 61 | # EC2 get KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 62 | key_name = rand_name("keypair-") |
| 63 | self.addResourceCleanUp(self.client.delete_key_pair, key_name) |
| 64 | keypair = self.client.create_key_pair(key_name) |
| 65 | self.assertTrue(compare_key_pairs(keypair, |
| 66 | self.client.get_key_pair(key_name))) |
| 67 | |
| 68 | @attr(type='smoke') |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 69 | def test_duplicate_ec2_keypair(self): |
Sean Dague | 64ef48d | 2013-01-03 17:54:36 -0500 | [diff] [blame] | 70 | # EC2 duplicate KeyPair |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 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) |
Attila Fazekas | 65e4008 | 2013-01-22 10:07:13 +0100 | [diff] [blame] | 74 | self.assertBotoError(self.ec.client.InvalidKeyPair.Duplicate, |
| 75 | self.client.create_key_pair, |
| 76 | key_name) |
Attila Fazekas | a23f500 | 2012-10-23 19:32:45 +0200 | [diff] [blame] | 77 | self.assertTrue(compare_key_pairs(keypair, |
| 78 | self.client.get_key_pair(key_name))) |