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
This commit is contained in:
Itxaka 2017-01-11 12:23:18 +01:00 committed by Itxaka Serrano Garcia
parent 50b20770ee
commit 4958805863
8 changed files with 24 additions and 19 deletions

View File

@ -754,9 +754,7 @@ class DefaultQuotaSets(generic.View):
if api.base.is_service_enabled(request, 'compute'): if api.base.is_service_enabled(request, 'compute'):
disabled_quotas = quotas.get_disabled_quotas(request) disabled_quotas = quotas.get_disabled_quotas(request)
all_quotas = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS filtered_quotas = [quota for quota in quotas.NOVA_QUOTA_FIELDS
filtered_quotas = [quota for quota in all_quotas
if quota not in disabled_quotas] if quota not in disabled_quotas]
request_data = { request_data = {

View File

@ -83,7 +83,9 @@ class ServicesViewTests(test.BaseAdminViewTests):
'<Quota: (floating_ips, 1)>', '<Quota: (floating_ips, 1)>',
'<Quota: (fixed_ips, 10)>', '<Quota: (fixed_ips, 10)>',
'<Quota: (security_groups, 10)>', '<Quota: (security_groups, 10)>',
'<Quota: (security_group_rules, 20)>'] '<Quota: (security_group_rules, 20)>',
'<Quota: (key_pairs, 100)>',
'<Quota: (injected_file_path_bytes, 255)>']
if neutron_enabled: if neutron_enabled:
expected_tabs.remove('<Quota: (floating_ips, 1)>') expected_tabs.remove('<Quota: (floating_ips, 1)>')
expected_tabs.remove('<Quota: (fixed_ips, 10)>') expected_tabs.remove('<Quota: (fixed_ips, 10)>')
@ -99,7 +101,7 @@ class ServicesViewTests(test.BaseAdminViewTests):
class UpdateDefaultQuotasTests(test.BaseAdminViewTests): class UpdateDefaultQuotasTests(test.BaseAdminViewTests):
def _get_quota_info(self, quota): def _get_quota_info(self, quota):
quota_data = {} quota_data = {}
for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS): for field in quotas.QUOTA_FIELDS:
if field != 'fixed_ips': if field != 'fixed_ips':
limit = quota.get(field).limit or 10 limit = quota.get(field).limit or 10
quota_data[field] = int(limit) quota_data[field] = int(limit)
@ -123,7 +125,7 @@ class UpdateDefaultQuotasTests(test.BaseAdminViewTests):
updated_quota = self._get_quota_info(quota) updated_quota = self._get_quota_info(quota)
# handle # 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_updated_quota = dict([(key, updated_quota[key]) for key in
nova_fields if key != 'fixed_ips']) nova_fields if key != 'fixed_ips'])
api.nova.default_quota_update(IsA(http.HttpRequest), api.nova.default_quota_update(IsA(http.HttpRequest),

View File

@ -38,7 +38,7 @@ class UpdateDefaultQuotasView(workflows.WorkflowView):
# get initial quota defaults # get initial quota defaults
try: try:
quota_defaults = quotas.get_default_quota_data(self.request) 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 initial[field] = quota_defaults.get(field).limit
except Exception: except Exception:

View File

@ -24,7 +24,6 @@ from openstack_dashboard.api import cinder
from openstack_dashboard.api import nova from openstack_dashboard.api import nova
from openstack_dashboard.usage import quotas from openstack_dashboard.usage import quotas
ALL_NOVA_QUOTA_FIELDS = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -73,7 +72,7 @@ class UpdateDefaultQuotasAction(workflows.Action):
class UpdateDefaultQuotasStep(workflows.Step): class UpdateDefaultQuotasStep(workflows.Step):
action_class = UpdateDefaultQuotasAction action_class = UpdateDefaultQuotasAction
contributes = (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS) contributes = quotas.QUOTA_FIELDS
class UpdateDefaultQuotas(workflows.Workflow): class UpdateDefaultQuotas(workflows.Workflow):
@ -88,7 +87,7 @@ class UpdateDefaultQuotas(workflows.Workflow):
def handle(self, request, data): def handle(self, request, data):
# Update the default quotas. # Update the default quotas.
# `fixed_ips` update for quota class is not supported by novaclient # `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']) if key != 'fixed_ips'])
is_error_nova = False is_error_nova = False
is_error_cinder = False is_error_cinder = False

View File

@ -50,6 +50,7 @@ COMMON_HORIZONTAL_TEMPLATE = "identity/projects/_common_horizontal_form.html"
class ProjectQuotaAction(workflows.Action): class ProjectQuotaAction(workflows.Action):
ifcb_label = _("Injected File Content (Bytes)") ifcb_label = _("Injected File Content (Bytes)")
ifpb_label = _("Length of Injected File Path")
metadata_items = forms.IntegerField(min_value=-1, metadata_items = forms.IntegerField(min_value=-1,
label=_("Metadata Items")) label=_("Metadata Items"))
cores = forms.IntegerField(min_value=-1, label=_("VCPUs")) cores = forms.IntegerField(min_value=-1, label=_("VCPUs"))
@ -58,6 +59,9 @@ class ProjectQuotaAction(workflows.Action):
label=_("Injected Files")) label=_("Injected Files"))
injected_file_content_bytes = forms.IntegerField(min_value=-1, injected_file_content_bytes = forms.IntegerField(min_value=-1,
label=ifcb_label) 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")) volumes = forms.IntegerField(min_value=-1, label=_("Volumes"))
snapshots = forms.IntegerField(min_value=-1, label=_("Volume Snapshots")) snapshots = forms.IntegerField(min_value=-1, label=_("Volume Snapshots"))
gigabytes = forms.IntegerField( gigabytes = forms.IntegerField(

View File

@ -400,7 +400,9 @@ def data(TEST):
injected_files='1', injected_files='1',
cores='10', cores='10',
security_groups='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) quota = quotas.QuotaSet(quotas.QuotaSetManager(None), quota_data)
TEST.quotas.nova = base.QuotaSet(quota) TEST.quotas.nova = base.QuotaSet(quota)
TEST.quotas.add(base.QuotaSet(quota)) TEST.quotas.add(base.QuotaSet(quota))

View File

@ -50,7 +50,9 @@ class QuotaTests(test.APITestCase):
'ram': {'available': 8976, 'used': 1024, 'quota': 10000}, 'ram': {'available': 8976, 'used': 1024, 'quota': 10000},
'floating_ips': {'available': 0, 'used': 2, 'quota': 1}, 'floating_ips': {'available': 0, 'used': 2, 'quota': 1},
'instances': {'available': 8, 'used': 2, 'quota': 10}, '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: else:
inf = float('inf') inf = float('inf')
@ -162,7 +164,7 @@ class QuotaTests(test.APITestCase):
result_quotas = quotas.get_disabled_quotas(self.request) result_quotas = quotas.get_disabled_quotas(self.request)
expected_quotas = list(quotas.CINDER_QUOTA_FIELDS) + \ expected_quotas = list(quotas.CINDER_QUOTA_FIELDS) + \
list(quotas.NEUTRON_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) self.assertItemsEqual(result_quotas, expected_quotas)
@test.create_stubs({api.nova: ('server_list', @test.create_stubs({api.nova: ('server_list',

View File

@ -39,10 +39,11 @@ NOVA_QUOTA_FIELDS = ("metadata_items",
"floating_ips", "floating_ips",
"fixed_ips", "fixed_ips",
"security_groups", "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", CINDER_QUOTA_FIELDS = ("volumes",
"snapshots", "snapshots",
@ -276,9 +277,6 @@ def get_disabled_quotas(request):
if not (base.is_service_enabled(request, 'compute') and if not (base.is_service_enabled(request, 'compute') and
nova.can_set_quotas()): nova.can_set_quotas()):
disabled_quotas.update(NOVA_QUOTA_FIELDS) 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 # There appear to be no glance quota fields currently
return disabled_quotas return disabled_quotas