blob: 50b6c771ad9849d7d6e230334bbefe9f2ea894cf [file] [log] [blame]
Jay Pipes13b479b2012-06-11 14:52:27 -04001# vim: tabstop=4 shiftwidth=4 softtabstop=4
2
ZhiQiang Fan39f97222013-09-20 04:49:44 +08003# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04004# 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 Dague1937d092013-05-17 16:36:38 -040018from tempest.api.compute import base
Masayuki Igawa259c1132013-10-31 17:48:44 +090019from tempest.common.utils import data_utils
Chris Yeoh9465b0b2013-02-09 22:19:15 +103020from tempest.test import attr
kavan-patil2eb350f2012-01-19 11:17:26 +000021
22
ivan-zhuf2b00502013-10-18 10:06:52 +080023class KeyPairsTestJSON(base.BaseV2ComputeTest):
Attila Fazekas19044d52013-02-16 07:35:06 +010024 _interface = 'json'
25
26 @classmethod
27 def setUpClass(cls):
28 super(KeyPairsTestJSON, cls).setUpClass()
29 cls.client = cls.keypairs_client
kavan-patil2eb350f2012-01-19 11:17:26 +000030
Giulio Fidenteba3985a2013-05-29 01:46:36 +020031 @attr(type='gate')
kavan-patil2eb350f2012-01-19 11:17:26 +000032 def test_keypairs_create_list_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050033 # Keypairs created should be available in the response list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020034 # Create 3 keypairs
kavan-patil2eb350f2012-01-19 11:17:26 +000035 key_list = list()
36 for i in range(3):
Masayuki Igawa259c1132013-10-31 17:48:44 +090037 k_name = data_utils.rand_name('keypair-')
kavan-patil2eb350f2012-01-19 11:17:26 +000038 resp, keypair = self.client.create_keypair(k_name)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020039 # Need to pop these keys so that our compare doesn't fail later,
40 # as the keypair dicts from list API doesn't have them.
kavan-patil2eb350f2012-01-19 11:17:26 +000041 keypair.pop('private_key')
42 keypair.pop('user_id')
43 self.assertEqual(200, resp.status)
44 key_list.append(keypair)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020045 # Fetch all keypairs and verify the list
46 # has all created keypairs
kavan-patil2eb350f2012-01-19 11:17:26 +000047 resp, fetched_list = self.client.list_keypairs()
48 self.assertEqual(200, resp.status)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020049 # We need to remove the extra 'keypair' element in the
50 # returned dict. See comment in keypairs_client.list_keypairs()
kavan-patil2eb350f2012-01-19 11:17:26 +000051 new_list = list()
52 for keypair in fetched_list:
53 new_list.append(keypair['keypair'])
54 fetched_list = new_list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020055 # Now check if all the created keypairs are in the fetched list
kavan-patil2eb350f2012-01-19 11:17:26 +000056 missing_kps = [kp for kp in key_list if kp not in fetched_list]
57 self.assertFalse(missing_kps,
58 "Failed to find keypairs %s in fetched list"
59 % ', '.join(m_key['name'] for m_key in missing_kps))
Attila Fazekasf7f34f92013-08-01 17:01:44 +020060 # Delete all the keypairs created
kavan-patil2eb350f2012-01-19 11:17:26 +000061 for keypair in key_list:
62 resp, _ = self.client.delete_keypair(keypair['name'])
63 self.assertEqual(202, resp.status)
64
Giulio Fidenteba3985a2013-05-29 01:46:36 +020065 @attr(type='gate')
kavan-patil2eb350f2012-01-19 11:17:26 +000066 def test_keypair_create_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050067 # Keypair should be created, verified and deleted
Masayuki Igawa259c1132013-10-31 17:48:44 +090068 k_name = data_utils.rand_name('keypair-')
kavan-patil2eb350f2012-01-19 11:17:26 +000069 resp, keypair = self.client.create_keypair(k_name)
70 self.assertEqual(200, resp.status)
71 private_key = keypair['private_key']
72 key_name = keypair['name']
73 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080074 "The created keypair name is not equal "
75 "to the requested name")
kavan-patil2eb350f2012-01-19 11:17:26 +000076 self.assertTrue(private_key is not None,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080077 "Field private_key is empty or not found.")
kavan-patil2eb350f2012-01-19 11:17:26 +000078 resp, _ = self.client.delete_keypair(k_name)
79 self.assertEqual(202, resp.status)
80
Giulio Fidenteba3985a2013-05-29 01:46:36 +020081 @attr(type='gate')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053082 def test_get_keypair_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050083 # Keypair should be created, Got details by name and deleted
Masayuki Igawa259c1132013-10-31 17:48:44 +090084 k_name = data_utils.rand_name('keypair-')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053085 resp, keypair = self.client.create_keypair(k_name)
Giulio Fidente2732fca2013-08-29 13:40:22 +020086 self.addCleanup(self.client.delete_keypair, k_name)
Giulio Fidente92f77192013-08-26 17:13:28 +020087 resp, keypair_detail = self.client.get_keypair(k_name)
88 self.assertEqual(200, resp.status)
Giulio Fidente92f77192013-08-26 17:13:28 +020089 self.assertIn('name', keypair_detail)
90 self.assertIn('public_key', keypair_detail)
91 self.assertEqual(keypair_detail['name'], k_name,
92 "The created keypair name is not equal "
93 "to requested name")
94 public_key = keypair_detail['public_key']
95 self.assertTrue(public_key is not None,
96 "Field public_key is empty or not found.")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053097
Giulio Fidenteba3985a2013-05-29 01:46:36 +020098 @attr(type='gate')
kavan-patil2eb350f2012-01-19 11:17:26 +000099 def test_keypair_create_with_pub_key(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -0500100 # Keypair should be created with a given public key
Masayuki Igawa259c1132013-10-31 17:48:44 +0900101 k_name = data_utils.rand_name('keypair-')
kavan-patil2eb350f2012-01-19 11:17:26 +0000102 pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
103 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
104 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
105 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
106 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
107 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
108 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
109 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
110 "snSA8wzBx3A/8y9Pp1B nova@ubuntu")
111 resp, keypair = self.client.create_keypair(k_name, pub_key)
112 self.assertEqual(200, resp.status)
113 self.assertFalse('private_key' in keypair,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800114 "Field private_key is not empty!")
kavan-patil2eb350f2012-01-19 11:17:26 +0000115 key_name = keypair['name']
116 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +0800117 "The created keypair name is not equal "
118 "to the requested name!")
kavan-patil2eb350f2012-01-19 11:17:26 +0000119 resp, _ = self.client.delete_keypair(k_name)
120 self.assertEqual(202, resp.status)
121
Mauro S. M. Rodriguesa636f532012-08-21 11:07:53 -0400122
Attila Fazekas19044d52013-02-16 07:35:06 +0100123class KeyPairsTestXML(KeyPairsTestJSON):
124 _interface = 'xml'