blob: 66abb2168aee7924ac0ab860242786858f3be01f [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
Ken'ichi Ohmichi757833a2017-03-10 10:30:30 -080017from tempest.lib.common.utils import data_utils
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080018from tempest.lib import decorators
kavan-patil2eb350f2012-01-19 11:17:26 +000019
20
Marc Koderer78e5a8b2015-08-03 15:04:53 +020021class KeyPairsV2TestJSON(base.BaseKeypairTest):
ghanshyama1f87132015-11-13 14:49:27 +090022 max_microversion = '2.1'
23
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080024 @decorators.idempotent_id('1d1dbedb-d7a0-432a-9d09-83f543c3c19b')
kavan-patil2eb350f2012-01-19 11:17:26 +000025 def test_keypairs_create_list_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050026 # Keypairs created should be available in the response list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020027 # Create 3 keypairs
kavan-patil2eb350f2012-01-19 11:17:26 +000028 key_list = list()
zhufl4311dc42017-01-26 16:26:18 +080029 for _ in range(3):
zhufl5bcd7ee2017-01-13 17:47:14 +080030 keypair = self.create_keypair()
Attila Fazekasf7f34f92013-08-01 17:01:44 +020031 # Need to pop these keys so that our compare doesn't fail later,
32 # as the keypair dicts from list API doesn't have them.
kavan-patil2eb350f2012-01-19 11:17:26 +000033 keypair.pop('private_key')
34 keypair.pop('user_id')
kavan-patil2eb350f2012-01-19 11:17:26 +000035 key_list.append(keypair)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020036 # Fetch all keypairs and verify the list
37 # has all created keypairs
PrernaDembla6b79aff2018-01-11 18:28:03 +053038 fetched_list = self.keypairs_client.list_keypairs()['keypairs']
kavan-patil2eb350f2012-01-19 11:17:26 +000039 new_list = list()
40 for keypair in fetched_list:
41 new_list.append(keypair['keypair'])
42 fetched_list = new_list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020043 # Now check if all the created keypairs are in the fetched list
kavan-patil2eb350f2012-01-19 11:17:26 +000044 missing_kps = [kp for kp in key_list if kp not in fetched_list]
45 self.assertFalse(missing_kps,
46 "Failed to find keypairs %s in fetched list"
47 % ', '.join(m_key['name'] for m_key in missing_kps))
kavan-patil2eb350f2012-01-19 11:17:26 +000048
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080049 @decorators.idempotent_id('6c1d3123-4519-4742-9194-622cb1714b7d')
kavan-patil2eb350f2012-01-19 11:17:26 +000050 def test_keypair_create_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050051 # Keypair should be created, verified and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000052 k_name = data_utils.rand_name('keypair')
zhufl5bcd7ee2017-01-13 17:47:14 +080053 keypair = self.create_keypair(k_name)
kavan-patil2eb350f2012-01-19 11:17:26 +000054 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
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080059 @decorators.idempotent_id('a4233d5d-52d8-47cc-9a25-e1864527e3df')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053060 def test_get_keypair_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050061 # Keypair should be created, Got details by name and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000062 k_name = data_utils.rand_name('keypair')
zhufl5bcd7ee2017-01-13 17:47:14 +080063 self.create_keypair(k_name)
PrernaDembla6b79aff2018-01-11 18:28:03 +053064 keypair_detail = self.keypairs_client.show_keypair(k_name)['keypair']
Giulio Fidente92f77192013-08-26 17:13:28 +020065 self.assertEqual(keypair_detail['name'], k_name,
66 "The created keypair name is not equal "
67 "to requested name")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053068
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080069 @decorators.idempotent_id('39c90c6a-304a-49dd-95ec-2366129def05')
kavan-patil2eb350f2012-01-19 11:17:26 +000070 def test_keypair_create_with_pub_key(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050071 # Keypair should be created with a given public key
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000072 k_name = data_utils.rand_name('keypair')
kavan-patil2eb350f2012-01-19 11:17:26 +000073 pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
74 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
75 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
76 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
77 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
78 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
79 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
80 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
81 "snSA8wzBx3A/8y9Pp1B nova@ubuntu")
zhufl5bcd7ee2017-01-13 17:47:14 +080082 keypair = self.create_keypair(k_name, pub_key)
Béla Vancsics64862f72016-11-08 09:12:31 +010083 self.assertNotIn('private_key', keypair,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080084 "Field private_key is not empty!")
kavan-patil2eb350f2012-01-19 11:17:26 +000085 key_name = keypair['name']
86 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080087 "The created keypair name is not equal "
88 "to the requested name!")