Skip to content

Commit 3082811

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Remove None valued network quota entries"
2 parents c7a4377 + e9bd4ef commit 3082811

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

openstackclient/common/quota.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,13 @@ def get_volume_quota(self, client, parsed_args):
161161
raise
162162
return quota._info
163163

164+
def _network_quota_to_dict(self, network_quota):
165+
if type(network_quota) is not dict:
166+
dict_quota = network_quota.to_dict()
167+
else:
168+
dict_quota = network_quota
169+
return {k: v for k, v in dict_quota.items() if v is not None}
170+
164171
def get_network_quota(self, parsed_args):
165172
quota_class = (
166173
parsed_args.quota_class if 'quota_class' in parsed_args else False)
@@ -174,13 +181,11 @@ def get_network_quota(self, parsed_args):
174181
client = self.app.client_manager.network
175182
if default:
176183
network_quota = client.get_quota_default(project)
177-
if type(network_quota) is not dict:
178-
network_quota = network_quota.to_dict()
184+
network_quota = self._network_quota_to_dict(network_quota)
179185
else:
180186
network_quota = client.get_quota(project,
181187
details=detail)
182-
if type(network_quota) is not dict:
183-
network_quota = network_quota.to_dict()
188+
network_quota = self._network_quota_to_dict(network_quota)
184189
if detail:
185190
# NOTE(slaweq): Neutron returns values with key "used" but
186191
# Nova for example returns same data with key "in_use"

openstackclient/tests/unit/common/test_quota.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,3 +1087,26 @@ def test_quota_show_no_project(self):
10871087
identity_fakes.project_id, details=False
10881088
)
10891089
self.assertNotCalled(self.network.get_quota_default)
1090+
1091+
def test_network_quota_show_remove_empty(self):
1092+
arglist = [
1093+
self.projects[0].name,
1094+
]
1095+
verifylist = [
1096+
('project', self.projects[0].name),
1097+
]
1098+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1099+
1100+
# First check that all regular values are returned
1101+
result = self.cmd.get_network_quota(parsed_args)
1102+
self.assertEqual(len(network_fakes.QUOTA), len(result))
1103+
1104+
# set 1 of the values to None, and verify it is not returned
1105+
orig_get_quota = self.network.get_quota
1106+
network_quotas = copy.copy(network_fakes.QUOTA)
1107+
network_quotas['healthmonitor'] = None
1108+
self.network.get_quota = mock.Mock(return_value=network_quotas)
1109+
result = self.cmd.get_network_quota(parsed_args)
1110+
self.assertEqual(len(network_fakes.QUOTA) - 1, len(result))
1111+
# Go back to default mock
1112+
self.network.get_quota = orig_get_quota
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
other:
3+
- |
4+
Remove deprecated neutron-lbaas results from ``quota show`` command.

0 commit comments

Comments
 (0)