diff options
author | Zuul <zuul@review.opendev.org> | 2022-07-06 13:57:26 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2022-07-06 13:57:26 +0000 |
commit | d6675983c493f654685cb8ee8a01a5c55e9d65f6 (patch) | |
tree | fb53cd333ba5a9846bb88d19bf7e7dc1c058db9c | |
parent | 324d4b0bf5d965ced4b985d73e8331e2383086cc (diff) | |
parent | b948e74b88befca67eab57573444e81f44eb75c9 (diff) | |
download | python-openstackclient-stable/train.tar.gz |
Merge "Remove None valued network quota entries" into stable/trainstable/train
-rw-r--r-- | openstackclient/common/quota.py | 13 | ||||
-rw-r--r-- | openstackclient/tests/unit/common/test_quota.py | 23 | ||||
-rw-r--r-- | releasenotes/notes/remove-nlbaas-quota-8b38e0c91ab113cb.yaml | 4 |
3 files changed, 36 insertions, 4 deletions
diff --git a/openstackclient/common/quota.py b/openstackclient/common/quota.py index 6d122642..b697c24c 100644 --- a/openstackclient/common/quota.py +++ b/openstackclient/common/quota.py @@ -161,6 +161,13 @@ class BaseQuota(object): raise return quota._info + def _network_quota_to_dict(self, network_quota): + if type(network_quota) is not dict: + dict_quota = network_quota.to_dict() + else: + dict_quota = network_quota + return {k: v for k, v in dict_quota.items() if v is not None} + def get_network_quota(self, parsed_args): quota_class = ( parsed_args.quota_class if 'quota_class' in parsed_args else False) @@ -174,13 +181,11 @@ class BaseQuota(object): client = self.app.client_manager.network if default: network_quota = client.get_quota_default(project) - if type(network_quota) is not dict: - network_quota = network_quota.to_dict() + network_quota = self._network_quota_to_dict(network_quota) else: network_quota = client.get_quota(project, details=detail) - if type(network_quota) is not dict: - network_quota = network_quota.to_dict() + network_quota = self._network_quota_to_dict(network_quota) if detail: # NOTE(slaweq): Neutron returns values with key "used" but # Nova for example returns same data with key "in_use" diff --git a/openstackclient/tests/unit/common/test_quota.py b/openstackclient/tests/unit/common/test_quota.py index f025354f..6d9ec451 100644 --- a/openstackclient/tests/unit/common/test_quota.py +++ b/openstackclient/tests/unit/common/test_quota.py @@ -1037,3 +1037,26 @@ class TestQuotaShow(TestQuota): identity_fakes.project_id, details=False ) self.assertNotCalled(self.network.get_quota_default) + + def test_network_quota_show_remove_empty(self): + arglist = [ + self.projects[0].name, + ] + verifylist = [ + ('project', self.projects[0].name), + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + + # First check that all regular values are returned + result = self.cmd.get_network_quota(parsed_args) + self.assertEqual(len(network_fakes.QUOTA), len(result)) + + # set 1 of the values to None, and verify it is not returned + orig_get_quota = self.network.get_quota + network_quotas = copy.copy(network_fakes.QUOTA) + network_quotas['healthmonitor'] = None + self.network.get_quota = mock.Mock(return_value=network_quotas) + result = self.cmd.get_network_quota(parsed_args) + self.assertEqual(len(network_fakes.QUOTA) - 1, len(result)) + # Go back to default mock + self.network.get_quota = orig_get_quota diff --git a/releasenotes/notes/remove-nlbaas-quota-8b38e0c91ab113cb.yaml b/releasenotes/notes/remove-nlbaas-quota-8b38e0c91ab113cb.yaml new file mode 100644 index 00000000..572e215b --- /dev/null +++ b/releasenotes/notes/remove-nlbaas-quota-8b38e0c91ab113cb.yaml @@ -0,0 +1,4 @@ +--- +other: + - | + Remove deprecated neutron-lbaas results from ``quota show`` command. |