From 31adbe7561b1ca3fd0f9ecd20ec0e50363a40f2b Mon Sep 17 00:00:00 2001 From: Ladislav Smola Date: Tue, 25 Feb 2014 06:47:02 -0500 Subject: [PATCH] Showing correctly errors from API -showing errors that API throw in stack-create action, there are lot of possible errors that needs to be exposed to the user -fixed worklow actions contributions to correct ones Change-Id: I0a352d0aac814864da1f40de05d1f91dc5ed9630 --- tuskar_ui/api.py | 5 +---- .../overcloud/workflows/undeployed.py | 17 +++++++++------- .../workflows/undeployed_configuration.py | 8 ++++---- .../workflows/undeployed_overview.py | 20 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tuskar_ui/api.py b/tuskar_ui/api.py index 8ed17e73b..9c43c2cb9 100644 --- a/tuskar_ui/api.py +++ b/tuskar_ui/api.py @@ -210,10 +210,7 @@ class Overcloud(base.APIResourceWrapper): # state of all inner entities and operations correctly. # Then also delete the try/except, it should not be caught on this # level. - try: - return heat.stack_get(self._request, 'overcloud') - except heatclient.exc.HTTPNotFound: - return None + return heat.stack_get(self._request, 'overcloud') @cached_property def stack_events(self): diff --git a/tuskar_ui/infrastructure/overcloud/workflows/undeployed.py b/tuskar_ui/infrastructure/overcloud/workflows/undeployed.py index 2661d6f0e..7dc44c106 100644 --- a/tuskar_ui/infrastructure/overcloud/workflows/undeployed.py +++ b/tuskar_ui/infrastructure/overcloud/workflows/undeployed.py @@ -11,9 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. - +from django.core import exceptions as django_exceptions from django.utils.translation import ugettext_lazy as _ -from horizon import exceptions + import horizon.workflows from tuskar_ui import api @@ -33,11 +33,14 @@ class Workflow(horizon.workflows.Workflow): success_url = 'horizon:infrastructure:overcloud:index' def handle(self, request, context): - success = True try: api.Overcloud.create(self.request, context['role_counts'], context['configuration']) - except Exception: - success = False - exceptions.handle(request, _('Unable to start deployment.')) - return success + except Exception as e: + # Showing error in both workflow tabs, because from the exception + # type we can't recognize where it should show + self.add_error_to_step(unicode(e), 'undeployed_overview') + self.add_error_to_step(unicode(e), 'deployed_configuration') + raise django_exceptions.ValidationError(unicode(e)) + + return True diff --git a/tuskar_ui/infrastructure/overcloud/workflows/undeployed_configuration.py b/tuskar_ui/infrastructure/overcloud/workflows/undeployed_configuration.py index 9b5a58c86..0fa2577e5 100644 --- a/tuskar_ui/infrastructure/overcloud/workflows/undeployed_configuration.py +++ b/tuskar_ui/infrastructure/overcloud/workflows/undeployed_configuration.py @@ -260,12 +260,12 @@ class Action(horizon.workflows.Action): for name, data in parameters: self.fields[name] = make_field(name, **data) - def handle(self, request, context): - context['configuration'] = self.cleaned_data - return context - class Step(horizon.workflows.Step): action_class = Action contributes = ('configuration',) template_name = 'infrastructure/overcloud/undeployed_configuration.html' + + def contribute(self, data, context): + context['configuration'] = data + return context diff --git a/tuskar_ui/infrastructure/overcloud/workflows/undeployed_overview.py b/tuskar_ui/infrastructure/overcloud/workflows/undeployed_overview.py index a3a18de73..b9552e112 100644 --- a/tuskar_ui/infrastructure/overcloud/workflows/undeployed_overview.py +++ b/tuskar_ui/infrastructure/overcloud/workflows/undeployed_overview.py @@ -90,16 +90,6 @@ class Action(horizon.workflows.Action): _("Can't deploy nodes without a node profile assigned.")) return self.cleaned_data - def handle(self, request, context): - counts = {} - for key, value in self.cleaned_data.iteritems(): - if not key.startswith('count_'): - continue - count, role_id, profile = key.split('__', 2) - counts[role_id, profile] = int(value) - context['role_counts'] = counts - return context - class Step(horizon.workflows.Step): action_class = Action @@ -110,3 +100,13 @@ class Step(horizon.workflows.Step): def get_free_nodes(self): """Get the count of nodes that are not assigned yet.""" return len(api.Node.list(self.workflow.request, False)) + + def contribute(self, data, context): + counts = {} + for key, value in data.iteritems(): + if not key.startswith('count_'): + continue + count, role_id, profile = key.split('__', 2) + counts[role_id, profile] = int(value) + context['role_counts'] = counts + return context