summaryrefslogtreecommitdiff
path: root/novaclient/tests
diff options
context:
space:
mode:
authorSylvain Bauza <sbauza@redhat.com>2022-07-27 16:10:30 +0200
committerSylvain Bauza <sbauza@redhat.com>2022-07-28 14:59:47 +0200
commit2b5d989990b14ef81e3ca2a48df8e43b6b205d0e (patch)
tree74e17c9df17c194b82805f76069cf2f22cbd8f04 /novaclient/tests
parentee9b277c5f442f299b853118c900c3ee2996c67a (diff)
downloadpython-novaclient-2b5d989990b14ef81e3ca2a48df8e43b6b205d0e.tar.gz
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
Diffstat (limited to 'novaclient/tests')
-rw-r--r--novaclient/tests/unit/v2/fakes.py7
-rw-r--r--novaclient/tests/unit/v2/test_keypairs.py25
2 files changed, 31 insertions, 1 deletions
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)