blob: 8df2e842c34a85882d25bb6d8177f2bd56311e77 [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):
zhufl36ef0892020-08-12 13:47:21 +080022 """Test keypairs API with compute microversion less than 2.2"""
23
ghanshyama1f87132015-11-13 14:49:27 +090024 max_microversion = '2.1'
25
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080026 @decorators.idempotent_id('1d1dbedb-d7a0-432a-9d09-83f543c3c19b')
kavan-patil2eb350f2012-01-19 11:17:26 +000027 def test_keypairs_create_list_delete(self):
zhufl36ef0892020-08-12 13:47:21 +080028 """Test create/list/delete keypairs
29
30 Keypairs created should be available in the response list
31 """
Attila Fazekasf7f34f92013-08-01 17:01:44 +020032 # Create 3 keypairs
kavan-patil2eb350f2012-01-19 11:17:26 +000033 key_list = list()
zhufl4311dc42017-01-26 16:26:18 +080034 for _ in range(3):
zhufl5bcd7ee2017-01-13 17:47:14 +080035 keypair = self.create_keypair()
Attila Fazekasf7f34f92013-08-01 17:01:44 +020036 # Need to pop these keys so that our compare doesn't fail later,
37 # as the keypair dicts from list API doesn't have them.
kavan-patil2eb350f2012-01-19 11:17:26 +000038 keypair.pop('private_key')
39 keypair.pop('user_id')
kavan-patil2eb350f2012-01-19 11:17:26 +000040 key_list.append(keypair)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020041 # Fetch all keypairs and verify the list
42 # has all created keypairs
PrernaDembla6b79aff2018-01-11 18:28:03 +053043 fetched_list = self.keypairs_client.list_keypairs()['keypairs']
kavan-patil2eb350f2012-01-19 11:17:26 +000044 new_list = list()
45 for keypair in fetched_list:
46 new_list.append(keypair['keypair'])
47 fetched_list = new_list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020048 # Now check if all the created keypairs are in the fetched list
kavan-patil2eb350f2012-01-19 11:17:26 +000049 missing_kps = [kp for kp in key_list if kp not in fetched_list]
50 self.assertFalse(missing_kps,
51 "Failed to find keypairs %s in fetched list"
52 % ', '.join(m_key['name'] for m_key in missing_kps))
kavan-patil2eb350f2012-01-19 11:17:26 +000053
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080054 @decorators.idempotent_id('6c1d3123-4519-4742-9194-622cb1714b7d')
kavan-patil2eb350f2012-01-19 11:17:26 +000055 def test_keypair_create_delete(self):
zhufl36ef0892020-08-12 13:47:21 +080056 """Test create/delete keypair"""
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000057 k_name = data_utils.rand_name('keypair')
zhufl5bcd7ee2017-01-13 17:47:14 +080058 keypair = self.create_keypair(k_name)
kavan-patil2eb350f2012-01-19 11:17:26 +000059 key_name = keypair['name']
60 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080061 "The created keypair name is not equal "
62 "to the requested name")
kavan-patil2eb350f2012-01-19 11:17:26 +000063
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080064 @decorators.idempotent_id('a4233d5d-52d8-47cc-9a25-e1864527e3df')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053065 def test_get_keypair_detail(self):
zhufl36ef0892020-08-12 13:47:21 +080066 """Test getting keypair detail by keypair name"""
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000067 k_name = data_utils.rand_name('keypair')
zhufl5bcd7ee2017-01-13 17:47:14 +080068 self.create_keypair(k_name)
PrernaDembla6b79aff2018-01-11 18:28:03 +053069 keypair_detail = self.keypairs_client.show_keypair(k_name)['keypair']
Giulio Fidente92f77192013-08-26 17:13:28 +020070 self.assertEqual(keypair_detail['name'], k_name,
71 "The created keypair name is not equal "
72 "to requested name")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053073
Ken'ichi Ohmichi6c92edf2017-01-27 17:32:10 -080074 @decorators.idempotent_id('39c90c6a-304a-49dd-95ec-2366129def05')
kavan-patil2eb350f2012-01-19 11:17:26 +000075 def test_keypair_create_with_pub_key(self):
zhufl36ef0892020-08-12 13:47:21 +080076 """Test creating keypair with a given public key"""
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000077 k_name = data_utils.rand_name('keypair')
kavan-patil2eb350f2012-01-19 11:17:26 +000078 pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
79 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
80 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
81 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
82 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
83 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
84 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
85 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
86 "snSA8wzBx3A/8y9Pp1B nova@ubuntu")
zhufl5bcd7ee2017-01-13 17:47:14 +080087 keypair = self.create_keypair(k_name, pub_key)
Béla Vancsics64862f72016-11-08 09:12:31 +010088 self.assertNotIn('private_key', keypair,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080089 "Field private_key is not empty!")
kavan-patil2eb350f2012-01-19 11:17:26 +000090 key_name = keypair['name']
91 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080092 "The created keypair name is not equal "
93 "to the requested name!")