From 3f3da92350bd4eaf58a80ae11c7717c92f0dfef8 Mon Sep 17 00:00:00 2001 From: kelfen Date: Fri, 31 Jul 2015 17:39:55 +0200 Subject: [PATCH] Swap and ephemeral fields should be optional Such as in Nova CLI, during flavor create/update the swap and ephemeral fields should be optional. If Nova receive an empty value in swap or ephemeral field sets it to "0" Change-Id: I896e4fa842a1cf6213f564d8890931a0818b657a Closes-Bug: #1480343 --- .../dashboards/admin/flavors/tests.py | 26 +++++++++++++++++++ .../dashboards/admin/flavors/workflows.py | 10 +++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/openstack_dashboard/dashboards/admin/flavors/tests.py b/openstack_dashboard/dashboards/admin/flavors/tests.py index 1f7a8d438a..c0cd4aaa22 100644 --- a/openstack_dashboard/dashboards/admin/flavors/tests.py +++ b/openstack_dashboard/dashboards/admin/flavors/tests.py @@ -257,6 +257,32 @@ class CreateFlavorWorkflowTests(BaseFlavorWorkflowTests): self.assertFormErrors(res) self.assertContains(res, "field is required") + @test.create_stubs({api.keystone: ('tenant_list',), + api.nova: ('flavor_list',)}) + def test_create_flavor_missing_swap_and_ephemeral_fields(self): + flavor = self.flavors.first() + projects = self.tenants.list() + + # init + api.keystone.tenant_list(IsA(http.HttpRequest)).AndReturn([projects, + False]) + + # handle + api.nova.flavor_list(IsA(http.HttpRequest), None) \ + .AndReturn(self.flavors.list()) + self.mox.ReplayAll() + + workflow_data = self._get_workflow_data(flavor) + # Swap field empty + workflow_data['swap'] = None + # Ephemeral field empty + workflow_data['eph'] = None + + url = reverse(constants.FLAVORS_CREATE_URL) + res = self.client.post(url, workflow_data) + + self.assertFormErrors(res) + class UpdateFlavorWorkflowTests(BaseFlavorWorkflowTests): @test.create_stubs({api.nova: ('flavor_get', diff --git a/openstack_dashboard/dashboards/admin/flavors/workflows.py b/openstack_dashboard/dashboards/admin/flavors/workflows.py index 73e17cbeb7..c2c841d99b 100644 --- a/openstack_dashboard/dashboards/admin/flavors/workflows.py +++ b/openstack_dashboard/dashboards/admin/flavors/workflows.py @@ -50,8 +50,12 @@ class CreateFlavorInfoAction(workflows.Action): disk_gb = forms.IntegerField(label=_("Root Disk (GB)"), min_value=0) eph_gb = forms.IntegerField(label=_("Ephemeral Disk (GB)"), + required=False, + initial=0, min_value=0) swap_mb = forms.IntegerField(label=_("Swap Disk (MB)"), + required=False, + initial=0, min_value=0) class Meta(object): @@ -188,6 +192,8 @@ class CreateFlavor(workflows.Workflow): def handle(self, request, data): flavor_id = data.get('flavor_id') or 'auto' + swap = data.get('swap_mb') or 0 + ephemeral = data.get('eph_gb') or 0 flavor_access = data['flavor_access'] is_public = not flavor_access @@ -198,8 +204,8 @@ class CreateFlavor(workflows.Workflow): memory=data['memory_mb'], vcpu=data['vcpus'], disk=data['disk_gb'], - ephemeral=data['eph_gb'], - swap=data['swap_mb'], + ephemeral=ephemeral, + swap=swap, flavorid=flavor_id, is_public=is_public) except Exception: