From eedac01a9c529868b5d9be1294d8ea0a955614e2 Mon Sep 17 00:00:00 2001 From: shlo Date: Thu, 1 Sep 2016 11:27:49 +0800 Subject: [PATCH] fix workflow exception on host aggregate create form Under the circumstance that there are existing aggregates, this bug happens when create button is clicked without the required "name" field filled. Error toast shows instead of the expected error message on the create form. When the form posts without name filed filled, the name attribute in the clean data is None instead of an empty string, which causes AttributeError on the following string operation. 1. patch an empty string as the fallback value for the 'name' variable 2. corresponding unit test is attached Change-Id: I0bdf469d87aa06ab58b73e6ce41bdf63bb36a538 Closes-Bug: #1617140 --- .../dashboards/admin/aggregates/tests.py | 11 +++++++++++ .../dashboards/admin/aggregates/workflows.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/openstack_dashboard/dashboards/admin/aggregates/tests.py b/openstack_dashboard/dashboards/admin/aggregates/tests.py index 31a929925b..61cb3b952b 100644 --- a/openstack_dashboard/dashboards/admin/aggregates/tests.py +++ b/openstack_dashboard/dashboards/admin/aggregates/tests.py @@ -117,6 +117,17 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests): self._test_generic_create_aggregate(workflow_data, aggregate, (), 1, u'This field is required') + def test_create_aggregate_fails_missing_fields_existing_aggregates(self): + aggregate = self.aggregates.first() + existing_aggregates = self.aggregates.list() + workflow_data = self._get_create_workflow_data(aggregate) + workflow_data['name'] = '' + workflow_data['availability_zone'] = '' + + self._test_generic_create_aggregate(workflow_data, aggregate, + existing_aggregates, 1, + u'This field is required') + def test_create_aggregate_fails_duplicated_name(self): aggregate = self.aggregates.first() existing_aggregates = self.aggregates.list() diff --git a/openstack_dashboard/dashboards/admin/aggregates/workflows.py b/openstack_dashboard/dashboards/admin/aggregates/workflows.py index b9fe82962d..15710a27da 100644 --- a/openstack_dashboard/dashboards/admin/aggregates/workflows.py +++ b/openstack_dashboard/dashboards/admin/aggregates/workflows.py @@ -37,7 +37,7 @@ class SetAggregateInfoAction(workflows.Action): def clean(self): cleaned_data = super(SetAggregateInfoAction, self).clean() - name = cleaned_data.get('name') + name = cleaned_data.get('name', '') try: aggregates = api.nova.aggregate_details_list(self.request)