diff options
author | Zuul <zuul@review.opendev.org> | 2022-08-02 16:03:40 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-08-02 16:03:40 +0000 |
commit | cdea416cce0b81b096a0907a7f283534c9f06323 (patch) | |
tree | fdecba8c04656324fef1cea3f0d3edaa51d85df4 | |
parent | 89a76edc8d68212d65b6189669f9a7207f09655d (diff) | |
parent | 2b5d989990b14ef81e3ca2a48df8e43b6b205d0e (diff) | |
download | python-novaclient-cdea416cce0b81b096a0907a7f283534c9f06323.tar.gz |
Merge "Add support for 2.92 : keypair import mandatory"
-rw-r--r-- | novaclient/__init__.py | 2 | ||||
-rw-r--r-- | novaclient/tests/unit/v2/fakes.py | 7 | ||||
-rw-r--r-- | novaclient/tests/unit/v2/test_keypairs.py | 25 | ||||
-rw-r--r-- | novaclient/v2/keypairs.py | 19 | ||||
-rw-r--r-- | releasenotes/notes/bp-keypair-generation-removal-1b5d84a8906d3918.yaml | 8 |
5 files changed, 58 insertions, 3 deletions
diff --git a/novaclient/__init__.py b/novaclient/__init__.py index bbfd9522..afffde0f 100644 --- a/novaclient/__init__.py +++ b/novaclient/__init__.py @@ -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") diff --git a/novaclient/tests/unit/v2/fakes.py b/novaclient/tests/unit/v2/fakes.py index 059a7147..c7687c1e 100644 --- a/novaclient/tests/unit/v2/fakes.py +++ b/novaclient/tests/unit/v2/fakes.py @@ -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) diff --git a/novaclient/tests/unit/v2/test_keypairs.py b/novaclient/tests/unit/v2/test_keypairs.py index cf310b0e..7e16438d 100644 --- a/novaclient/tests/unit/v2/test_keypairs.py +++ b/novaclient/tests/unit/v2/test_keypairs.py @@ -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) diff --git a/novaclient/v2/keypairs.py b/novaclient/v2/keypairs.py index 9b2e73b7..5d12f8cd 100644 --- a/novaclient/v2/keypairs.py +++ b/novaclient/v2/keypairs.py @@ -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): """ diff --git a/releasenotes/notes/bp-keypair-generation-removal-1b5d84a8906d3918.yaml b/releasenotes/notes/bp-keypair-generation-removal-1b5d84a8906d3918.yaml new file mode 100644 index 00000000..c7cdb642 --- /dev/null +++ b/releasenotes/notes/bp-keypair-generation-removal-1b5d84a8906d3918.yaml @@ -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 |