blob: d10bf14881c20bec3cadf5f4b6b1f444b4ba1917 [file] [log] [blame]
ZhiQiang Fan39f97222013-09-20 04:49:44 +08001# Copyright 2012 OpenStack Foundation
Jay Pipes13b479b2012-06-11 14:52:27 -04002# 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
Marc Koderer78e5a8b2015-08-03 15:04:53 +020016from tempest.api.compute.keypairs import base
Fei Long Wangd39431f2015-05-14 11:30:48 +120017from tempest.common.utils import data_utils
ivan-zhu58d50772013-12-10 14:02:38 +080018from tempest import test
kavan-patil2eb350f2012-01-19 11:17:26 +000019
20
Marc Koderer78e5a8b2015-08-03 15:04:53 +020021class KeyPairsV2TestJSON(base.BaseKeypairTest):
Chris Hoge7579c1a2015-02-26 14:12:15 -080022 @test.idempotent_id('1d1dbedb-d7a0-432a-9d09-83f543c3c19b')
kavan-patil2eb350f2012-01-19 11:17:26 +000023 def test_keypairs_create_list_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050024 # Keypairs created should be available in the response list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020025 # Create 3 keypairs
kavan-patil2eb350f2012-01-19 11:17:26 +000026 key_list = list()
27 for i in range(3):
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000028 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050029 keypair = self._create_keypair(k_name)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020030 # Need to pop these keys so that our compare doesn't fail later,
31 # as the keypair dicts from list API doesn't have them.
kavan-patil2eb350f2012-01-19 11:17:26 +000032 keypair.pop('private_key')
33 keypair.pop('user_id')
kavan-patil2eb350f2012-01-19 11:17:26 +000034 key_list.append(keypair)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020035 # Fetch all keypairs and verify the list
36 # has all created keypairs
ghanshyamdee01f22015-08-17 11:41:47 +090037 fetched_list = self.client.list_keypairs()['keypairs']
kavan-patil2eb350f2012-01-19 11:17:26 +000038 new_list = list()
39 for keypair in fetched_list:
40 new_list.append(keypair['keypair'])
41 fetched_list = new_list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020042 # Now check if all the created keypairs are in the fetched list
kavan-patil2eb350f2012-01-19 11:17:26 +000043 missing_kps = [kp for kp in key_list if kp not in fetched_list]
44 self.assertFalse(missing_kps,
45 "Failed to find keypairs %s in fetched list"
46 % ', '.join(m_key['name'] for m_key in missing_kps))
kavan-patil2eb350f2012-01-19 11:17:26 +000047
Chris Hoge7579c1a2015-02-26 14:12:15 -080048 @test.idempotent_id('6c1d3123-4519-4742-9194-622cb1714b7d')
kavan-patil2eb350f2012-01-19 11:17:26 +000049 def test_keypair_create_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050050 # Keypair should be created, verified and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000051 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050052 keypair = self._create_keypair(k_name)
kavan-patil2eb350f2012-01-19 11:17:26 +000053 private_key = keypair['private_key']
54 key_name = keypair['name']
55 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080056 "The created keypair name is not equal "
57 "to the requested name")
kavan-patil2eb350f2012-01-19 11:17:26 +000058 self.assertTrue(private_key is not None,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080059 "Field private_key is empty or not found.")
kavan-patil2eb350f2012-01-19 11:17:26 +000060
Chris Hoge7579c1a2015-02-26 14:12:15 -080061 @test.idempotent_id('a4233d5d-52d8-47cc-9a25-e1864527e3df')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053062 def test_get_keypair_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050063 # Keypair should be created, Got details by name and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000064 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050065 self._create_keypair(k_name)
ghanshyamdee01f22015-08-17 11:41:47 +090066 keypair_detail = self.client.show_keypair(k_name)['keypair']
Giulio Fidente92f77192013-08-26 17:13:28 +020067 self.assertIn('name', keypair_detail)
68 self.assertIn('public_key', keypair_detail)
69 self.assertEqual(keypair_detail['name'], k_name,
70 "The created keypair name is not equal "
71 "to requested name")
72 public_key = keypair_detail['public_key']
73 self.assertTrue(public_key is not None,
74 "Field public_key is empty or not found.")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053075
Chris Hoge7579c1a2015-02-26 14:12:15 -080076 @test.idempotent_id('39c90c6a-304a-49dd-95ec-2366129def05')
kavan-patil2eb350f2012-01-19 11:17:26 +000077 def test_keypair_create_with_pub_key(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050078 # Keypair should be created with a given public key
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000079 k_name = data_utils.rand_name('keypair')
kavan-patil2eb350f2012-01-19 11:17:26 +000080 pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
81 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
82 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
83 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
84 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
85 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
86 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
87 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
88 "snSA8wzBx3A/8y9Pp1B nova@ubuntu")
David Kranz173f0e02015-02-06 13:47:57 -050089 keypair = self._create_keypair(k_name, pub_key)
kavan-patil2eb350f2012-01-19 11:17:26 +000090 self.assertFalse('private_key' in keypair,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080091 "Field private_key is not empty!")
kavan-patil2eb350f2012-01-19 11:17:26 +000092 key_name = keypair['name']
93 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080094 "The created keypair name is not equal "
95 "to the requested name!")