From b94f615873d712c359798b0afd1ea6aefd8a7fa7 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Wed, 11 Jan 2017 12:23:18 +0100 Subject: [PATCH] Merge "missing" quotas with nova quotas There was an extra variable for the so called "missing" quotas since 2013. This patch merges them with the normal nova quotas, cleans up the tests, removes any usage of that special var and as a side effect, adds the missing keys to the project quota update page. Change-Id: Icaac1ebb1749e13fdfc307e89dcc6bbd64bef922 Closes-Bug: 1655393 (cherry picked from commit 4958805863df463cebb79b0175fa2fe8cbb83c5e) --- openstack_dashboard/api/rest/nova.py | 4 +--- openstack_dashboard/dashboards/admin/defaults/tests.py | 8 +++++--- openstack_dashboard/dashboards/admin/defaults/views.py | 2 +- .../dashboards/admin/defaults/workflows.py | 5 ++--- .../dashboards/identity/projects/workflows.py | 4 ++++ openstack_dashboard/test/test_data/nova_data.py | 4 +++- openstack_dashboard/test/tests/quotas.py | 6 ++++-- openstack_dashboard/usage/quotas.py | 10 ++++------ 8 files changed, 24 insertions(+), 19 deletions(-) diff --git a/openstack_dashboard/api/rest/nova.py b/openstack_dashboard/api/rest/nova.py index ed96e2a568..bf7ff4c97b 100644 --- a/openstack_dashboard/api/rest/nova.py +++ b/openstack_dashboard/api/rest/nova.py @@ -754,9 +754,7 @@ class DefaultQuotaSets(generic.View): if api.base.is_service_enabled(request, 'compute'): disabled_quotas = quotas.get_disabled_quotas(request) - all_quotas = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS - - filtered_quotas = [quota for quota in all_quotas + filtered_quotas = [quota for quota in quotas.NOVA_QUOTA_FIELDS if quota not in disabled_quotas] request_data = { diff --git a/openstack_dashboard/dashboards/admin/defaults/tests.py b/openstack_dashboard/dashboards/admin/defaults/tests.py index 6c6faa5a6a..6e51597f65 100644 --- a/openstack_dashboard/dashboards/admin/defaults/tests.py +++ b/openstack_dashboard/dashboards/admin/defaults/tests.py @@ -83,7 +83,9 @@ class ServicesViewTests(test.BaseAdminViewTests): '', '', '', - ''] + '', + '', + ''] if neutron_enabled: expected_tabs.remove('') expected_tabs.remove('') @@ -99,7 +101,7 @@ class ServicesViewTests(test.BaseAdminViewTests): class UpdateDefaultQuotasTests(test.BaseAdminViewTests): def _get_quota_info(self, quota): quota_data = {} - for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS): + for field in quotas.QUOTA_FIELDS: if field != 'fixed_ips': limit = quota.get(field).limit or 10 quota_data[field] = int(limit) @@ -123,7 +125,7 @@ class UpdateDefaultQuotasTests(test.BaseAdminViewTests): updated_quota = self._get_quota_info(quota) # handle - nova_fields = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS + nova_fields = quotas.NOVA_QUOTA_FIELDS nova_updated_quota = dict([(key, updated_quota[key]) for key in nova_fields if key != 'fixed_ips']) api.nova.default_quota_update(IsA(http.HttpRequest), diff --git a/openstack_dashboard/dashboards/admin/defaults/views.py b/openstack_dashboard/dashboards/admin/defaults/views.py index 7cf156d38a..17199249ee 100644 --- a/openstack_dashboard/dashboards/admin/defaults/views.py +++ b/openstack_dashboard/dashboards/admin/defaults/views.py @@ -38,7 +38,7 @@ class UpdateDefaultQuotasView(workflows.WorkflowView): # get initial quota defaults try: quota_defaults = quotas.get_default_quota_data(self.request) - for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS): + for field in quotas.QUOTA_FIELDS: initial[field] = quota_defaults.get(field).limit except Exception: diff --git a/openstack_dashboard/dashboards/admin/defaults/workflows.py b/openstack_dashboard/dashboards/admin/defaults/workflows.py index f3f1159418..394e79f6c5 100644 --- a/openstack_dashboard/dashboards/admin/defaults/workflows.py +++ b/openstack_dashboard/dashboards/admin/defaults/workflows.py @@ -24,7 +24,6 @@ from openstack_dashboard.api import cinder from openstack_dashboard.api import nova from openstack_dashboard.usage import quotas -ALL_NOVA_QUOTA_FIELDS = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS LOG = logging.getLogger(__name__) @@ -73,7 +72,7 @@ class UpdateDefaultQuotasAction(workflows.Action): class UpdateDefaultQuotasStep(workflows.Step): action_class = UpdateDefaultQuotasAction - contributes = (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS) + contributes = quotas.QUOTA_FIELDS class UpdateDefaultQuotas(workflows.Workflow): @@ -88,7 +87,7 @@ class UpdateDefaultQuotas(workflows.Workflow): def handle(self, request, data): # Update the default quotas. # `fixed_ips` update for quota class is not supported by novaclient - nova_data = dict([(key, data[key]) for key in ALL_NOVA_QUOTA_FIELDS + nova_data = dict([(key, data[key]) for key in quotas.NOVA_QUOTA_FIELDS if key != 'fixed_ips']) is_error_nova = False is_error_cinder = False diff --git a/openstack_dashboard/dashboards/identity/projects/workflows.py b/openstack_dashboard/dashboards/identity/projects/workflows.py index d031db61b4..25cce5e933 100644 --- a/openstack_dashboard/dashboards/identity/projects/workflows.py +++ b/openstack_dashboard/dashboards/identity/projects/workflows.py @@ -51,6 +51,7 @@ COMMON_HORIZONTAL_TEMPLATE = "identity/projects/_common_horizontal_form.html" class ProjectQuotaAction(workflows.Action): ifcb_label = _("Injected File Content (Bytes)") + ifpb_label = _("Length of Injected File Path") metadata_items = forms.IntegerField(min_value=-1, label=_("Metadata Items")) cores = forms.IntegerField(min_value=-1, label=_("VCPUs")) @@ -59,6 +60,9 @@ class ProjectQuotaAction(workflows.Action): label=_("Injected Files")) injected_file_content_bytes = forms.IntegerField(min_value=-1, label=ifcb_label) + key_pairs = forms.IntegerField(min_value=-1, label=_("Key Pairs")) + injected_file_path_bytes = forms.IntegerField(min_value=-1, + label=ifpb_label) volumes = forms.IntegerField(min_value=-1, label=_("Volumes")) snapshots = forms.IntegerField(min_value=-1, label=_("Volume Snapshots")) gigabytes = forms.IntegerField( diff --git a/openstack_dashboard/test/test_data/nova_data.py b/openstack_dashboard/test/test_data/nova_data.py index b889ded41e..c55f8a69ed 100644 --- a/openstack_dashboard/test/test_data/nova_data.py +++ b/openstack_dashboard/test/test_data/nova_data.py @@ -400,7 +400,9 @@ def data(TEST): injected_files='1', cores='10', security_groups='10', - security_group_rules='20') + security_group_rules='20', + key_pairs=100, + injected_file_path_bytes=255) quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data) TEST.quotas.nova = base.QuotaSet(quota) TEST.quotas.add(base.QuotaSet(quota)) diff --git a/openstack_dashboard/test/tests/quotas.py b/openstack_dashboard/test/tests/quotas.py index b6c35724d6..550f4f6ae2 100644 --- a/openstack_dashboard/test/tests/quotas.py +++ b/openstack_dashboard/test/tests/quotas.py @@ -50,7 +50,9 @@ class QuotaTests(test.APITestCase): 'ram': {'available': 8976, 'used': 1024, 'quota': 10000}, 'floating_ips': {'available': 0, 'used': 2, 'quota': 1}, 'instances': {'available': 8, 'used': 2, 'quota': 10}, - 'cores': {'available': 8, 'used': 2, 'quota': 10} + 'cores': {'available': 8, 'used': 2, 'quota': 10}, + 'key_pairs': {'quota': 100}, + 'injected_file_path_bytes': {'quota': 255} }) else: inf = float('inf') @@ -162,7 +164,7 @@ class QuotaTests(test.APITestCase): result_quotas = quotas.get_disabled_quotas(self.request) expected_quotas = list(quotas.CINDER_QUOTA_FIELDS) + \ list(quotas.NEUTRON_QUOTA_FIELDS) + \ - list(quotas.NOVA_QUOTA_FIELDS) + list(quotas.MISSING_QUOTA_FIELDS) + list(quotas.NOVA_QUOTA_FIELDS) self.assertItemsEqual(result_quotas, expected_quotas) @test.create_stubs({api.nova: ('server_list', diff --git a/openstack_dashboard/usage/quotas.py b/openstack_dashboard/usage/quotas.py index 4ff3446e56..1db06ccdd7 100644 --- a/openstack_dashboard/usage/quotas.py +++ b/openstack_dashboard/usage/quotas.py @@ -39,10 +39,11 @@ NOVA_QUOTA_FIELDS = ("metadata_items", "floating_ips", "fixed_ips", "security_groups", - "security_group_rules",) + "security_group_rules", + "key_pairs", + "injected_file_path_bytes", + ) -MISSING_QUOTA_FIELDS = ("key_pairs", - "injected_file_path_bytes",) CINDER_QUOTA_FIELDS = ("volumes", "snapshots", @@ -276,9 +277,6 @@ def get_disabled_quotas(request): if not (base.is_service_enabled(request, 'compute') and nova.can_set_quotas()): disabled_quotas.update(NOVA_QUOTA_FIELDS) - # The 'missing' quota fields are all nova (this is hardcoded in - # dashboards.admin.defaults.workflows) - disabled_quotas.update(MISSING_QUOTA_FIELDS) # There appear to be no glance quota fields currently return disabled_quotas