Add support for 2.92 : keypair import mandatory

Now, when creating a keypair, the 'public_key' parameter is now mandatory.

Depends-On: https://review.opendev.org/c/openstack/nova/+/849133
Implements: blueprint keypair-generation-removal

Change-Id: I03570d0a49b73021de91dc50b65b1bbf5d4b878b
This commit is contained in:
Sylvain Bauza 2022-07-27 16:10:30 +02:00
parent ee9b277c5f
commit 2b5d989990
5 changed files with 58 additions and 3 deletions

View File

@ -25,4 +25,4 @@ API_MIN_VERSION = api_versions.APIVersion("2.1")
# when client supported the max version, and bumped sequentially, otherwise
# the client may break due to server side new version may include some
# backward incompatible change.
API_MAX_VERSION = api_versions.APIVersion("2.91")
API_MAX_VERSION = api_versions.APIVersion("2.92")

View File

@ -1228,8 +1228,13 @@ class FakeSessionClient(base_client.SessionClient):
def post_os_keypairs(self, body, **kw):
assert list(body) == ['keypair']
if self.api_version >= api_versions.APIVersion("2.92"):
# In 2.92, public_key becomes mandatory
required = ['name', 'public_key']
else:
required = ['name']
fakes.assert_has_keys(body['keypair'],
required=['name'])
required=required)
r = {'keypair': self.get_os_keypairs()[2]['keypairs'][0]['keypair']}
return (202, {}, r)

View File

@ -127,3 +127,28 @@ class KeypairsV35TestCase(KeypairsTest):
% self.keypair_prefix)
for kp in kps:
self.assertIsInstance(kp, keypairs.Keypair)
class KeypairsV92TestCase(KeypairsTest):
def setUp(self):
super(KeypairsV92TestCase, self).setUp()
self.cs.api_version = api_versions.APIVersion("2.92")
def test_create_keypair(self):
name = "foo"
key_type = "some_type"
public_key = "fake-public-key"
kp = self.cs.keypairs.create(name, public_key=public_key,
key_type=key_type)
self.assert_request_id(kp, fakes.FAKE_REQUEST_ID_LIST)
self.assert_called('POST', '/%s' % self.keypair_prefix,
body={'keypair': {'name': name,
'public_key': public_key,
'type': key_type}})
self.assertIsInstance(kp, keypairs.Keypair)
def test_create_keypair_without_pubkey(self):
name = "foo"
key_type = "some_type"
self.assertRaises(TypeError,
self.cs.keypairs.create, name, key_type=key_type)

View File

@ -114,7 +114,7 @@ class KeypairManager(base.ManagerWithFind):
body['keypair']['public_key'] = public_key
return self._create('/%s' % self.keypair_prefix, body, 'keypair')
@api_versions.wraps("2.10")
@api_versions.wraps("2.10", "2.91")
def create(self, name, public_key=None, key_type="ssh", user_id=None):
"""
Create a keypair
@ -132,6 +132,23 @@ class KeypairManager(base.ManagerWithFind):
body['keypair']['user_id'] = user_id
return self._create('/%s' % self.keypair_prefix, body, 'keypair')
@api_versions.wraps("2.92")
def create(self, name, public_key, key_type="ssh", user_id=None):
"""
Create a keypair
:param name: name for the keypair to create
:param public_key: existing public key to import
:param key_type: keypair type to create
:param user_id: user to add.
"""
body = {'keypair': {'name': name,
'type': key_type,
'public_key': public_key}}
if user_id:
body['keypair']['user_id'] = user_id
return self._create('/%s' % self.keypair_prefix, body, 'keypair')
@api_versions.wraps("2.0", "2.9")
def delete(self, key):
"""

View File

@ -0,0 +1,8 @@
---
features:
- |
Support has been added for `microversion 2.92`_. This microversion only
accepts to import a public key and no longer to generate one, hence now the
public_key parameter be mandatory.
.. _microversion 2.92: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#microversion-2-92