Skip to content

Commit 0a93733

Browse files
committed
Fix quota usage and reservation display
Fix `openstack quota show --usage` to correctly display resource usage and reservations by applying proper name normalization for corresponding sections of data. Previously, name normalization was applied only for "limits" which is the root section, leaving 'usage' and 'reservation' sections untouched. Change-Id: Id14fe894b30a74b9b8d78b00c3d4ff151f8b4210 Closes-bug: #2137636 Signed-off-by: Andriy Kurilin <andr.kurilin@gmail.com>
1 parent d1a0ede commit 0a93733

3 files changed

Lines changed: 83 additions & 14 deletions

File tree

openstackclient/common/quota.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -797,20 +797,25 @@ def take_action(self, parsed_args):
797797
info.update(volume_quota_info)
798798
info.update(network_quota_info)
799799

800-
# Map the internal quota names to the external ones
801-
# COMPUTE_QUOTAS and NETWORK_QUOTAS share floating-ips,
802-
# secgroup-rules and secgroups as dict value, so when
803-
# neutron is enabled, quotas of these three resources
804-
# in nova will be replaced by neutron's.
805-
for k, v in itertools.chain(
806-
COMPUTE_QUOTAS.items(),
807-
NOVA_NETWORK_QUOTAS.items(),
808-
VOLUME_QUOTAS.items(),
809-
NETWORK_QUOTAS.items(),
810-
):
811-
if not k == v and info.get(k) is not None:
812-
info[v] = info[k]
813-
info.pop(k)
800+
def _normalize_names(section: dict) -> None:
801+
# Map the internal quota names to the external ones
802+
# COMPUTE_QUOTAS and NETWORK_QUOTAS share floating-ips,
803+
# secgroup-rules and secgroups as dict value, so when
804+
# neutron is enabled, quotas of these three resources
805+
# in nova will be replaced by neutron's.
806+
for k, v in itertools.chain(
807+
COMPUTE_QUOTAS.items(),
808+
NOVA_NETWORK_QUOTAS.items(),
809+
VOLUME_QUOTAS.items(),
810+
NETWORK_QUOTAS.items(),
811+
):
812+
if not k == v and section.get(k) is not None:
813+
section[v] = section.pop(k)
814+
815+
_normalize_names(info)
816+
if parsed_args.usage:
817+
_normalize_names(info["reservation"])
818+
_normalize_names(info["usage"])
814819

815820
# Remove the 'id' field since it's not very useful
816821
if 'id' in info:

openstackclient/tests/unit/common/test_quota.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import copy
1314
from unittest import mock
1415

1516
from openstack.block_storage.v3 import quota_set as _volume_quota_set
@@ -1122,6 +1123,64 @@ def test_quota_show__with_network(self):
11221123
)
11231124
self.assertNotCalled(self.network_client.get_quota_default)
11241125

1126+
def test_quota_show__with_network_and_usage(self):
1127+
# ensure we do not interfere with other tests
1128+
self._network_quota_details = copy.deepcopy(
1129+
self._network_quota_details
1130+
)
1131+
# set a couple of resources
1132+
self._network_quota_details["floating_ips"].update(
1133+
limit=30, reserved=20, used=7
1134+
)
1135+
self._network_quota_details["security_group_rules"].update(
1136+
limit=9, reserved=7, used=5
1137+
)
1138+
1139+
arglist = [
1140+
'--network',
1141+
'--usage',
1142+
self.projects[0].name,
1143+
]
1144+
verifylist = [
1145+
('service', 'network'),
1146+
('project', self.projects[0].name),
1147+
]
1148+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
1149+
1150+
headers, result_gen = self.cmd.take_action(parsed_args)
1151+
1152+
self.assertEqual(('Resource', 'Limit', 'In Use', 'Reserved'), headers)
1153+
1154+
result = sorted(result_gen)
1155+
1156+
self.assertEqual(
1157+
[
1158+
('floating-ips', 30, 7, 20),
1159+
('health_monitors', 0, 0, 0),
1160+
('l7_policies', 0, 0, 0),
1161+
('listeners', 0, 0, 0),
1162+
('load_balancers', 0, 0, 0),
1163+
('networks', 0, 0, 0),
1164+
('pools', 0, 0, 0),
1165+
('ports', 0, 0, 0),
1166+
('rbac_policies', 0, 0, 0),
1167+
('routers', 0, 0, 0),
1168+
('secgroup-rules', 9, 5, 7),
1169+
('secgroups', 0, 0, 0),
1170+
('subnet_pools', 0, 0, 0),
1171+
('subnets', 0, 0, 0),
1172+
],
1173+
result,
1174+
)
1175+
1176+
self.compute_client.get_quota_set.assert_not_called()
1177+
self.volume_sdk_client.get_quota_set.assert_not_called()
1178+
self.network_client.get_quota.assert_called_once_with(
1179+
self.projects[0].id,
1180+
details=True,
1181+
)
1182+
self.assertNotCalled(self.network_client.get_quota_default)
1183+
11251184
def test_quota_show__with_default(self):
11261185
arglist = [
11271186
'--default',
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
Fix ``openstack quota show --usage`` to correctly display resource usage
5+
and reservation.

0 commit comments

Comments
 (0)