Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 1 | # Copyright 2012 OpenStack Foundation |
| 2 | # Copyright 2013 IBM Corp |
| 3 | # All Rights Reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 6 | # not use this file except in compliance with the License. You may obtain |
| 7 | # a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 13 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | # License for the specific language governing permissions and limitations |
| 15 | # under the License. |
| 16 | |
Matthew Treinish | 01472ff | 2015-02-20 17:26:52 -0500 | [diff] [blame] | 17 | from tempest_lib.common.utils import data_utils |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 18 | from tempest_lib import exceptions as lib_exc |
| 19 | |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 20 | from tempest.api.compute import base |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 21 | from tempest import test |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class KeyPairsNegativeTestJSON(base.BaseV2ComputeTest): |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 25 | |
| 26 | @classmethod |
Rohan Kanade | 60b7309 | 2015-02-04 17:58:19 +0530 | [diff] [blame] | 27 | def setup_clients(cls): |
| 28 | super(KeyPairsNegativeTestJSON, cls).setup_clients() |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 29 | cls.client = cls.keypairs_client |
| 30 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 31 | def _create_keypair(self, keypair_name, pub_key=None): |
| 32 | self.client.create_keypair(keypair_name, pub_key) |
| 33 | self.addCleanup(self.client.delete_keypair, keypair_name) |
| 34 | |
| 35 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 36 | @test.idempotent_id('29cca892-46ae-4d48-bc32-8fe7e731eb81') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 37 | def test_keypair_create_with_invalid_pub_key(self): |
| 38 | # Keypair should not be created with a non RSA public key |
| 39 | k_name = data_utils.rand_name('keypair-') |
| 40 | pub_key = "ssh-rsa JUNK nova@ubuntu" |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 41 | self.assertRaises(lib_exc.BadRequest, |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 42 | self._create_keypair, k_name, pub_key) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 43 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 44 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 45 | @test.idempotent_id('7cc32e47-4c42-489d-9623-c5e2cb5a2fa5') |
nayna-patel | 179077c | 2014-01-15 12:27:16 +0000 | [diff] [blame] | 46 | def test_keypair_delete_nonexistent_key(self): |
| 47 | # Non-existent key deletion should throw a proper error |
| 48 | k_name = data_utils.rand_name("keypair-non-existent-") |
Masayuki Igawa | bfa0760 | 2015-01-20 18:47:17 +0900 | [diff] [blame] | 49 | self.assertRaises(lib_exc.NotFound, self.client.delete_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 50 | k_name) |
| 51 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 52 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 53 | @test.idempotent_id('dade320e-69ca-42a9-ba4a-345300f127e0') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 54 | def test_create_keypair_with_empty_public_key(self): |
| 55 | # Keypair should not be created with an empty public key |
| 56 | k_name = data_utils.rand_name("keypair-") |
| 57 | pub_key = ' ' |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 58 | self.assertRaises(lib_exc.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 59 | k_name, pub_key) |
| 60 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 61 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 62 | @test.idempotent_id('fc100c19-2926-4b9c-8fdc-d0589ee2f9ff') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 63 | def test_create_keypair_when_public_key_bits_exceeds_maximum(self): |
| 64 | # Keypair should not be created when public key bits are too long |
| 65 | k_name = data_utils.rand_name("keypair-") |
| 66 | pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu' |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 67 | self.assertRaises(lib_exc.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 68 | k_name, pub_key) |
| 69 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 70 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 71 | @test.idempotent_id('0359a7f1-f002-4682-8073-0c91e4011b7c') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 72 | def test_create_keypair_with_duplicate_name(self): |
| 73 | # Keypairs with duplicate names should not be created |
| 74 | k_name = data_utils.rand_name('keypair-') |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 75 | self.client.create_keypair(k_name) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 76 | # Now try the same keyname to create another key |
Masayuki Igawa | d938876 | 2015-01-20 14:56:42 +0900 | [diff] [blame] | 77 | self.assertRaises(lib_exc.Conflict, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 78 | k_name) |
David Kranz | 173f0e0 | 2015-02-06 13:47:57 -0500 | [diff] [blame] | 79 | self.client.delete_keypair(k_name) |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 80 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 81 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 82 | @test.idempotent_id('1398abe1-4a84-45fb-9294-89f514daff00') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 83 | def test_create_keypair_with_empty_name_string(self): |
| 84 | # Keypairs with name being an empty string should not be created |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 85 | self.assertRaises(lib_exc.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 86 | '') |
| 87 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 88 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 89 | @test.idempotent_id('3faa916f-779f-4103-aca7-dc3538eee1b7') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 90 | def test_create_keypair_with_long_keynames(self): |
| 91 | # Keypairs with name longer than 255 chars should not be created |
| 92 | k_name = 'keypair-'.ljust(260, '0') |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 93 | self.assertRaises(lib_exc.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 94 | k_name) |
| 95 | |
ivan-zhu | 58d5077 | 2013-12-10 14:02:38 +0800 | [diff] [blame] | 96 | @test.attr(type=['negative', 'gate']) |
Chris Hoge | 7579c1a | 2015-02-26 14:12:15 -0800 | [diff] [blame] | 97 | @test.idempotent_id('45fbe5e0-acb5-49aa-837a-ff8d0719db91') |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 98 | def test_create_keypair_invalid_name(self): |
| 99 | # Keypairs with name being an invalid name should not be created |
| 100 | k_name = 'key_/.\@:' |
Masayuki Igawa | 4b29e47 | 2015-02-16 10:41:54 +0900 | [diff] [blame] | 101 | self.assertRaises(lib_exc.BadRequest, self._create_keypair, |
Hoisaleshwara Madan V S | 6a5dfb2 | 2013-11-28 14:31:40 +0530 | [diff] [blame] | 102 | k_name) |