From 33cf8fef380daa1983eb07eb3596cb49afa94a51 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 10 Jun 2025 10:52:55 +0100 Subject: [PATCH] api: Address issues with keypairs APIs Change-Id: I84ea28fc3ee255dea207e373c7064e3231e777f7 Signed-off-by: Stephen Finucane --- nova/api/openstack/compute/keypairs.py | 2 ++ .../api/openstack/compute/schemas/keypairs.py | 21 +++++++------------ nova/tests/unit/policies/test_keypairs.py | 2 +- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/nova/api/openstack/compute/keypairs.py b/nova/api/openstack/compute/keypairs.py index af5a115532..ebef4a0990 100644 --- a/nova/api/openstack/compute/keypairs.py +++ b/nova/api/openstack/compute/keypairs.py @@ -197,6 +197,8 @@ class KeypairController(wsgi.Controller): if api_version_request.is_supported(req, '2.35'): links = True + # TODO(stephenfin): Remove deleted, deleted_at, and updated_at from + # response in future microversion. return self._index( req, key_type=key_type, user_id=user_id, links=links ) diff --git a/nova/api/openstack/compute/schemas/keypairs.py b/nova/api/openstack/compute/schemas/keypairs.py index bba0f94e8c..89a316caf9 100644 --- a/nova/api/openstack/compute/schemas/keypairs.py +++ b/nova/api/openstack/compute/schemas/keypairs.py @@ -165,23 +165,18 @@ show_response = { 'type': 'object', 'properties': { 'created_at': {'type': 'string', 'format': 'date-time'}, - 'deleted': {'type': 'boolean'}, - 'deleted_at': { - 'oneOf': [ - {'type': 'string', 'format': 'date-time'}, - {'type': 'null'}, - ], - }, + # NOTE(stephenfin): While we expose these soft delete fields, + # we don't provide a mechanism to show actual soft deleted + # entries. As such, they're never populated. + 'deleted': {'type': 'boolean', 'const': False}, + 'deleted_at': {'type': 'null'}, 'fingerprint': {'type': 'string'}, 'id': {'type': 'integer'}, 'name': parameter_types.keypair_name_special_chars, 'public_key': {'type': 'string'}, - 'updated_at': { - 'oneOf': [ - {'type': 'string', 'format': 'date-time'}, - {'type': 'null'}, - ], - }, + # NOTE(stephenfin): There is no way to update an existing + # keypair, so this is never populated. + 'updated_at': {'type': 'null'}, 'user_id': parameter_types.user_id, }, 'required': [ diff --git a/nova/tests/unit/policies/test_keypairs.py b/nova/tests/unit/policies/test_keypairs.py index 42f508d837..a4967f5f55 100644 --- a/nova/tests/unit/policies/test_keypairs.py +++ b/nova/tests/unit/policies/test_keypairs.py @@ -33,7 +33,7 @@ FAKE_KEYPAIR = objects.KeyPair( private_key='ssh-rsa foo', public_key='ssh-rsa foo', type='ssh', - updated_at=datetime.datetime(2024, 10, 29, 13, 42, 2), + updated_at=None, user_id=uuids.user_alt_id, )