blob: 562a508387d93dd9223be3b4ee397e5627633dcc [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):
ghanshyama1f87132015-11-13 14:49:27 +090022 max_microversion = '2.1'
23
Chris Hoge7579c1a2015-02-26 14:12:15 -080024 @test.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()
29 for i in range(3):
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000030 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050031 keypair = self._create_keypair(k_name)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020032 # Need to pop these keys so that our compare doesn't fail later,
33 # as the keypair dicts from list API doesn't have them.
kavan-patil2eb350f2012-01-19 11:17:26 +000034 keypair.pop('private_key')
35 keypair.pop('user_id')
kavan-patil2eb350f2012-01-19 11:17:26 +000036 key_list.append(keypair)
Attila Fazekasf7f34f92013-08-01 17:01:44 +020037 # Fetch all keypairs and verify the list
38 # has all created keypairs
ghanshyamdee01f22015-08-17 11:41:47 +090039 fetched_list = self.client.list_keypairs()['keypairs']
kavan-patil2eb350f2012-01-19 11:17:26 +000040 new_list = list()
41 for keypair in fetched_list:
42 new_list.append(keypair['keypair'])
43 fetched_list = new_list
Attila Fazekasf7f34f92013-08-01 17:01:44 +020044 # Now check if all the created keypairs are in the fetched list
kavan-patil2eb350f2012-01-19 11:17:26 +000045 missing_kps = [kp for kp in key_list if kp not in fetched_list]
46 self.assertFalse(missing_kps,
47 "Failed to find keypairs %s in fetched list"
48 % ', '.join(m_key['name'] for m_key in missing_kps))
kavan-patil2eb350f2012-01-19 11:17:26 +000049
Chris Hoge7579c1a2015-02-26 14:12:15 -080050 @test.idempotent_id('6c1d3123-4519-4742-9194-622cb1714b7d')
kavan-patil2eb350f2012-01-19 11:17:26 +000051 def test_keypair_create_delete(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050052 # Keypair should be created, verified and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000053 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050054 keypair = self._create_keypair(k_name)
kavan-patil2eb350f2012-01-19 11:17:26 +000055 private_key = keypair['private_key']
56 key_name = keypair['name']
57 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080058 "The created keypair name is not equal "
59 "to the requested name")
Béla Vancsics64862f72016-11-08 09:12:31 +010060 self.assertIsNotNone(private_key,
61 "Field private_key is empty or not found.")
kavan-patil2eb350f2012-01-19 11:17:26 +000062
Chris Hoge7579c1a2015-02-26 14:12:15 -080063 @test.idempotent_id('a4233d5d-52d8-47cc-9a25-e1864527e3df')
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053064 def test_get_keypair_detail(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050065 # Keypair should be created, Got details by name and deleted
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000066 k_name = data_utils.rand_name('keypair')
David Kranz173f0e02015-02-06 13:47:57 -050067 self._create_keypair(k_name)
ghanshyamdee01f22015-08-17 11:41:47 +090068 keypair_detail = self.client.show_keypair(k_name)['keypair']
Giulio Fidente92f77192013-08-26 17:13:28 +020069 self.assertIn('name', keypair_detail)
70 self.assertIn('public_key', keypair_detail)
71 self.assertEqual(keypair_detail['name'], k_name,
72 "The created keypair name is not equal "
73 "to requested name")
74 public_key = keypair_detail['public_key']
Béla Vancsics64862f72016-11-08 09:12:31 +010075 self.assertIsNotNone(public_key,
76 "Field public_key is empty or not found.")
rajalakshmi-ganesanb74a11a2012-05-16 10:37:58 +053077
Chris Hoge7579c1a2015-02-26 14:12:15 -080078 @test.idempotent_id('39c90c6a-304a-49dd-95ec-2366129def05')
kavan-patil2eb350f2012-01-19 11:17:26 +000079 def test_keypair_create_with_pub_key(self):
Sean Dague4dd2c0b2013-01-03 17:50:28 -050080 # Keypair should be created with a given public key
Ken'ichi Ohmichi4937f562015-03-23 00:15:01 +000081 k_name = data_utils.rand_name('keypair')
kavan-patil2eb350f2012-01-19 11:17:26 +000082 pub_key = ("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCs"
83 "Ne3/1ILNCqFyfYWDeTKLD6jEXC2OQHLmietMWW+/vd"
84 "aZq7KZEwO0jhglaFjU1mpqq4Gz5RX156sCTNM9vRbw"
85 "KAxfsdF9laBYVsex3m3Wmui3uYrKyumsoJn2g9GNnG1P"
86 "I1mrVjZ61i0GY3khna+wzlTpCCmy5HNlrmbj3XLqBUpip"
87 "TOXmsnr4sChzC53KCd8LXuwc1i/CZPvF+3XipvAgFSE53pCt"
88 "LOeB1kYMOBaiUPLQTWXR3JpckqFIQwhIH0zoHlJvZE8hh90"
89 "XcPojYN56tI0OlrGqojbediJYD0rUsJu4weZpbn8vilb3JuDY+jws"
90 "snSA8wzBx3A/8y9Pp1B nova@ubuntu")
David Kranz173f0e02015-02-06 13:47:57 -050091 keypair = self._create_keypair(k_name, pub_key)
Béla Vancsics64862f72016-11-08 09:12:31 +010092 self.assertNotIn('private_key', keypair,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080093 "Field private_key is not empty!")
kavan-patil2eb350f2012-01-19 11:17:26 +000094 key_name = keypair['name']
95 self.assertEqual(key_name, k_name,
Zhongyue Luo79d8d362012-09-25 13:49:27 +080096 "The created keypair name is not equal "
97 "to the requested name!")