Skip to content

Commit 0933bda

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "quota: Fix incorrect keypair usage in show command"
2 parents 7b037ca + 3f32bdf commit 0933bda

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
@@ -804,6 +804,10 @@ def take_action(
804804
info["usage"].update(volume_quota_info.pop("usage", {}))
805805
info["usage"].update(network_quota_info.pop("usage", {}))
806806

807+
# Keypair usage is tracked per-user rather than per-project.
808+
# To avoid mislead return N/A
809+
info["usage"]["key_pairs"] = "N/A"
810+
807811
info.update(compute_quota_info)
808812
info.update(volume_quota_info)
809813
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
@@ -1220,6 +1220,22 @@ def test_quota_show__with_usage(self):
12201220
details=True,
12211221
)
12221222

1223+
def test_quota_show__keypairs_usage_is_always_na(self):
1224+
"""Verify that key-pair usage is overridden to N/A for project views."""
1225+
arglist = [
1226+
'--usage',
1227+
self.projects[0].name,
1228+
]
1229+
parsed_args = self.check_parser(self.cmd, arglist, [('usage', True)])
1230+
1231+
_, data = self.cmd.take_action(parsed_args)
1232+
1233+
keypair_row = [row for row in data if row[0] == 'key-pairs']
1234+
1235+
self.assertTrue(keypair_row, "key-pairs row was missing from output")
1236+
# Ensure the third column (In Use / Usage) is exactly "N/A"
1237+
self.assertEqual("N/A", keypair_row[0][2])
1238+
12231239
def test_quota_show__no_project(self):
12241240
arglist = []
12251241
verifylist = [

0 commit comments

Comments
 (0)