Skip to content

Commit 3f32bdf

Browse files
author
Alicja Filipek
committed
quota: Fix incorrect keypair usage in show command
Before this change, the 'quota show' command displayed incorrect keypair usage. While keypairs are listed under compute quotas, the Nova compute API does not actually gather or track keypair usage data on a per-project basis. As the result keypair usage output was always 0. Resolve this by checking whether the current user matches the target project scope. If the project IDs match, the code queries the compute SDK directly to retrieve the active keypair count for that user. Change-Id: I5592e1b797b4d18c6c2aae48580ff6f014ffd214 Signed-off-by: Alicja Filipek <alicja.filipek@cleura.com>
1 parent 0519e81 commit 3f32bdf

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

openstackclient/common/quota.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,10 @@ def take_action(
800800
info["usage"].update(volume_quota_info.pop("usage", {}))
801801
info["usage"].update(network_quota_info.pop("usage", {}))
802802

803+
# Keypair usage is tracked per-user rather than per-project.
804+
# To avoid mislead return N/A
805+
info["usage"]["key_pairs"] = "N/A"
806+
803807
info.update(compute_quota_info)
804808
info.update(volume_quota_info)
805809
info.update(network_quota_info)

openstackclient/tests/functional/common/test_quota.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ def test_quota_show_usage_option(self):
253253
self.assertEqual(sorted(expected_headers), sorted(row_headers))
254254
resources.append(row['Resource'])
255255
for header in expected_headers[1:]:
256-
self.assertIsInstance(row[header], int)
256+
if row['Resource'] == 'key-pairs' and header == 'In Use':
257+
self.assertEqual(row[header], "N/A")
258+
else:
259+
self.assertIsInstance(row[header], int)
257260
# Ensure that returned quota has network quota...
258261
self.assertIn("networks", resources)
259262
# ...and compute quota

openstackclient/tests/unit/common/test_quota.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,22 @@ def test_quota_show__with_usage(self):
12131213
details=True,
12141214
)
12151215

1216+
def test_quota_show__keypairs_usage_is_always_na(self):
1217+
"""Verify that key-pair usage is overridden to N/A for project views."""
1218+
arglist = [
1219+
'--usage',
1220+
self.projects[0].name,
1221+
]
1222+
parsed_args = self.check_parser(self.cmd, arglist, [('usage', True)])
1223+
1224+
_, data = self.cmd.take_action(parsed_args)
1225+
1226+
keypair_row = [row for row in data if row[0] == 'key-pairs']
1227+
1228+
self.assertTrue(keypair_row, "key-pairs row was missing from output")
1229+
# Ensure the third column (In Use / Usage) is exactly "N/A"
1230+
self.assertEqual("N/A", keypair_row[0][2])
1231+
12161232
def test_quota_show__no_project(self):
12171233
arglist = []
12181234
verifylist = [

0 commit comments

Comments
 (0)