Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [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 | |
Sean Dague | 1937d09 | 2013-05-17 16:36:38 -0400 | [diff] [blame] | 18 | from tempest.api.compute import base |
Jay Pipes | 13b479b | 2012-06-11 14:52:27 -0400 | [diff] [blame] | 19 | from tempest.common.utils.data_utils import rand_name |
Matthew Treinish | a83a16e | 2012-12-07 13:44:02 -0500 | [diff] [blame] | 20 | from tempest import exceptions |
Chris Yeoh | 9465b0b | 2013-02-09 22:19:15 +1030 | [diff] [blame] | 21 | from tempest.test import attr |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 22 | |
| 23 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 24 | class KeyPairsTestJSON(base.BaseComputeTest): |
| 25 | _interface = 'json' |
| 26 | |
| 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(KeyPairsTestJSON, cls).setUpClass() |
| 30 | cls.client = cls.keypairs_client |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 31 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 32 | @attr(type=['positive', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 33 | def test_keypairs_create_list_delete(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 34 | # Keypairs created should be available in the response list |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 35 | #Create 3 keypairs |
| 36 | key_list = list() |
| 37 | for i in range(3): |
| 38 | k_name = rand_name('keypair-') |
| 39 | resp, keypair = self.client.create_keypair(k_name) |
| 40 | #Need to pop these keys so that our compare doesn't fail later, |
| 41 | #as the keypair dicts from list API doesn't have them. |
| 42 | keypair.pop('private_key') |
| 43 | keypair.pop('user_id') |
| 44 | self.assertEqual(200, resp.status) |
| 45 | key_list.append(keypair) |
| 46 | #Fetch all keypairs and verify the list |
| 47 | #has all created keypairs |
| 48 | resp, fetched_list = self.client.list_keypairs() |
| 49 | self.assertEqual(200, resp.status) |
| 50 | #We need to remove the extra 'keypair' element in the |
| 51 | #returned dict. See comment in keypairs_client.list_keypairs() |
| 52 | new_list = list() |
| 53 | for keypair in fetched_list: |
| 54 | new_list.append(keypair['keypair']) |
| 55 | fetched_list = new_list |
| 56 | #Now check if all the created keypairs are in the fetched list |
| 57 | missing_kps = [kp for kp in key_list if kp not in fetched_list] |
| 58 | self.assertFalse(missing_kps, |
| 59 | "Failed to find keypairs %s in fetched list" |
| 60 | % ', '.join(m_key['name'] for m_key in missing_kps)) |
| 61 | #Delete all the keypairs created |
| 62 | for keypair in key_list: |
| 63 | resp, _ = self.client.delete_keypair(keypair['name']) |
| 64 | self.assertEqual(202, resp.status) |
| 65 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 66 | @attr(type=['positive', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 67 | def test_keypair_create_delete(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 68 | # Keypair should be created, verified and deleted |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 69 | k_name = rand_name('keypair-') |
| 70 | resp, keypair = self.client.create_keypair(k_name) |
| 71 | self.assertEqual(200, resp.status) |
| 72 | private_key = keypair['private_key'] |
| 73 | key_name = keypair['name'] |
| 74 | self.assertEqual(key_name, k_name, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 75 | "The created keypair name is not equal " |
| 76 | "to the requested name") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 77 | self.assertTrue(private_key is not None, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 78 | "Field private_key is empty or not found.") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 79 | resp, _ = self.client.delete_keypair(k_name) |
| 80 | self.assertEqual(202, resp.status) |
| 81 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 82 | @attr(type=['positive', 'gate']) |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 83 | def test_get_keypair_detail(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 84 | # Keypair should be created, Got details by name and deleted |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 85 | k_name = rand_name('keypair-') |
| 86 | resp, keypair = self.client.create_keypair(k_name) |
| 87 | try: |
| 88 | resp, keypair_detail = self.client.get_keypair(k_name) |
| 89 | self.assertEqual(200, resp.status) |
| 90 | self.assertTrue('name' in keypair_detail) |
| 91 | self.assertTrue('public_key' in keypair_detail) |
| 92 | self.assertEqual(keypair_detail['name'], k_name, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 93 | "The created keypair name is not equal " |
| 94 | "to requested name") |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 95 | public_key = keypair_detail['public_key'] |
| 96 | self.assertTrue(public_key is not None, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 97 | "Field public_key is empty or not found.") |
Matthew Treinish | 05d9fb9 | 2012-12-07 16:14:05 -0500 | [diff] [blame] | 98 | except Exception: |
Zhongyue Luo | e0884a3 | 2012-09-25 17:24:17 +0800 | [diff] [blame] | 99 | self.fail("GET keypair details requested by keypair name " |
| 100 | "has failed") |
rajalakshmi-ganesan | b74a11a | 2012-05-16 10:37:58 +0530 | [diff] [blame] | 101 | finally: |
| 102 | resp, _ = self.client.delete_keypair(k_name) |
| 103 | self.assertEqual(202, resp.status) |
| 104 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 105 | @attr(type=['positive', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 106 | def test_keypair_create_with_pub_key(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 107 | # Keypair should be created with a given public key |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 108 | k_name = rand_name('keypair-') |
| 109 | pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs" |
| 110 | "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd" |
| 111 | "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw" |
| 112 | "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P" |
| 113 | "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip" |
| 114 | "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt" |
| 115 | "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90" |
| 116 | "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws" |
| 117 | "snSA8wzBx3A/8y9Pp1B nova@ubuntu") |
| 118 | resp, keypair = self.client.create_keypair(k_name, pub_key) |
| 119 | self.assertEqual(200, resp.status) |
| 120 | self.assertFalse('private_key' in keypair, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 121 | "Field private_key is not empty!") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 122 | key_name = keypair['name'] |
| 123 | self.assertEqual(key_name, k_name, |
Zhongyue Luo | 79d8d36 | 2012-09-25 13:49:27 +0800 | [diff] [blame] | 124 | "The created keypair name is not equal " |
| 125 | "to the requested name!") |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 126 | resp, _ = self.client.delete_keypair(k_name) |
| 127 | self.assertEqual(202, resp.status) |
| 128 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 129 | @attr(type=['negative', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 130 | def test_keypair_create_with_invalid_pub_key(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 131 | # Keypair should not be created with a non RSA public key |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 132 | k_name = rand_name('keypair-') |
| 133 | pub_key = "ssh-rsa JUNK nova@ubuntu" |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 134 | self.assertRaises(exceptions.BadRequest, |
| 135 | self.client.create_keypair, k_name, pub_key) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 136 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 137 | @attr(type=['negative', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 138 | def test_keypair_delete_nonexistant_key(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 139 | # Non-existant key deletion should throw a proper error |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 140 | k_name = rand_name("keypair-non-existant-") |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 141 | self.assertRaises(exceptions.NotFound, self.client.delete_keypair, |
| 142 | k_name) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 143 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 144 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 145 | def test_create_keypair_with_empty_public_key(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 146 | # Keypair should not be created with an empty public key |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 147 | k_name = rand_name("keypair-") |
| 148 | pub_key = ' ' |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 149 | self.assertRaises(exceptions.BadRequest, self.client.create_keypair, |
| 150 | k_name, pub_key) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 151 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 152 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 153 | def test_create_keypair_when_public_key_bits_exceeds_maximum(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 154 | # Keypair should not be created when public key bits are too long |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 155 | k_name = rand_name("keypair-") |
| 156 | pub_key = 'ssh-rsa ' + 'A' * 2048 + ' openstack@ubuntu' |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 157 | self.assertRaises(exceptions.BadRequest, self.client.create_keypair, |
| 158 | k_name, pub_key) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 159 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 160 | @attr(type=['negative', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 161 | def test_create_keypair_with_duplicate_name(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 162 | # Keypairs with duplicate names should not be created |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 163 | k_name = rand_name('keypair-') |
| 164 | resp, _ = self.client.create_keypair(k_name) |
| 165 | self.assertEqual(200, resp.status) |
| 166 | #Now try the same keyname to ceate another key |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 167 | self.assertRaises(exceptions.Duplicate, self.client.create_keypair, |
| 168 | k_name) |
David Kranz | 5a23d86 | 2012-02-14 09:48:55 -0500 | [diff] [blame] | 169 | resp, _ = self.client.delete_keypair(k_name) |
| 170 | self.assertEqual(202, resp.status) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 171 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 172 | @attr(type=['negative', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 173 | def test_create_keypair_with_empty_name_string(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 174 | # Keypairs with name being an empty string should not be created |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 175 | self.assertRaises(exceptions.BadRequest, self.client.create_keypair, |
| 176 | '') |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 177 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 178 | @attr(type=['negative', 'gate']) |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 179 | def test_create_keypair_with_long_keynames(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 180 | # Keypairs with name longer than 255 chars should not be created |
kavan-patil | 2eb350f | 2012-01-19 11:17:26 +0000 | [diff] [blame] | 181 | k_name = 'keypair-'.ljust(260, '0') |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 182 | self.assertRaises(exceptions.BadRequest, self.client.create_keypair, |
| 183 | k_name) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 184 | |
Giampaolo Lauria | e9c7702 | 2013-05-22 01:23:58 -0400 | [diff] [blame^] | 185 | @attr(type=['negative', 'gate']) |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 186 | def test_create_keypair_invalid_name(self): |
Sean Dague | 4dd2c0b | 2013-01-03 17:50:28 -0500 | [diff] [blame] | 187 | # Keypairs with name being an invalid name should not be created |
Rohit Karajgi | b4825c3 | 2012-04-24 13:52:34 -0700 | [diff] [blame] | 188 | k_name = 'key_/.\@:' |
Chris Yeoh | e04628e | 2013-02-25 17:12:21 +1030 | [diff] [blame] | 189 | self.assertRaises(exceptions.BadRequest, self.client.create_keypair, |
| 190 | k_name) |
Mauro S. M. Rodrigues | a636f53 | 2012-08-21 11:07:53 -0400 | [diff] [blame] | 191 | |
| 192 | |
Attila Fazekas | 19044d5 | 2013-02-16 07:35:06 +0100 | [diff] [blame] | 193 | class KeyPairsTestXML(KeyPairsTestJSON): |
| 194 | _interface = 'xml' |