Example #1
0
 def test_service_create(self, mock_log, mock_api):
     parameters = {
         '?': {
             'type': 'test.Service'
         }
     }
     env_api.service_create(self.mock_request, self.env_id, parameters)
     env_api.api.muranoclient.assert_called_with(self.mock_request)
     mock_log.debug.assert_called_with('Service::Create {0}'
                                       .format(parameters['?']['type']))
Example #2
0
 def test_service_create(self, mock_log, mock_api):
     parameters = {
         '?': {
             'type': 'test.Service'
         }
     }
     env_api.service_create(self.mock_request, self.env_id, parameters)
     env_api.api.muranoclient.assert_called_with(self.mock_request)
     mock_log.debug.assert_called_with('Service::Create {0}'
                                       .format(parameters['?']['type']))
Example #3
0
    def done(self, form_list, **kwargs):
        app_name = self.storage.extra_data['app'].name

        service = form_list[0].service
        attributes = service.extract_attributes()
        attributes = helpers.insert_hidden_ids(attributes)

        storage = attributes.setdefault('?', {}).setdefault(
            consts.DASHBOARD_ATTRS_KEY, {})
        storage['name'] = app_name

        do_redirect = self.get_wizard_flag('do_redirect')
        wm_form_data = service.cleaned_data.get('workflowManagement')
        if wm_form_data:
            do_redirect = do_redirect or not wm_form_data.get(
                'stay_at_the_catalog', True)

        fail_url = reverse("horizon:murano:environments:index")
        environment_id = utils.ensure_python_obj(kwargs.get('environment_id'))
        quick_environment_id = self.request.session.get('quick_env_id')
        try:
            # NOTE (tsufiev): create new quick environment only if we came
            # here after pressing 'Quick Deploy' button and quick environment
            # wasn't created yet during addition of some referred App
            if environment_id is None:
                if quick_environment_id is None:
                    env = create_quick_environment(self.request)
                    self.request.session['quick_env_id'] = env.id
                    environment_id = env.id
                else:
                    environment_id = quick_environment_id
            env_url = reverse('horizon:murano:environments:services',
                              args=(environment_id, ))

            srv = env_api.service_create(self.request, environment_id,
                                         attributes)
        except exc.HTTPForbidden:
            msg = _("Sorry, you can't add application right now. "
                    "The environment is deploying.")
            exceptions.handle(self.request, msg, redirect=fail_url)
        except Exception:
            message = _('Adding application to an environment failed.')
            LOG.exception(message)
            if quick_environment_id:
                env_api.environment_delete(self.request, quick_environment_id)
                fail_url = reverse('horizon:murano:catalog:index')
            exceptions.handle(self.request, message, redirect=fail_url)
        else:
            message = _("The '{0}' application successfully added to "
                        "environment.").format(app_name)
            LOG.info(message)
            messages.success(self.request, message)

            if do_redirect:
                return http.HttpResponseRedirect(env_url)
            else:
                srv_id = getattr(srv, '?')['id']
                return self.create_hacked_response(
                    srv_id, attributes['?'].get('name')
                    or attributes.get('name'))
Example #4
0
    def done(self, form_list, **kwargs):
        app_name = self.storage.extra_data['app'].name

        service = form_list[0].service
        attributes = service.extract_attributes()
        attributes = helpers.insert_hidden_ids(attributes)

        storage = attributes.setdefault('?', {}).setdefault(
            consts.DASHBOARD_ATTRS_KEY, {})
        storage['name'] = app_name

        do_redirect = self.get_wizard_flag('do_redirect')
        wm_form_data = service.cleaned_data.get('workflowManagement')
        if wm_form_data:
            do_redirect = do_redirect or not wm_form_data.get(
                'stay_at_the_catalog', True)

        fail_url = reverse("horizon:murano:environments:index")
        environment_id = utils.ensure_python_obj(kwargs.get('environment_id'))
        quick_environment_id = self.request.session.get('quick_env_id')
        try:
            # NOTE (tsufiev): create new quick environment only if we came
            # here after pressing 'Quick Deploy' button and quick environment
            # wasn't created yet during addition of some referred App
            if environment_id is None:
                if quick_environment_id is None:
                    env = create_quick_environment(self.request)
                    self.request.session['quick_env_id'] = env.id
                    environment_id = env.id
                else:
                    environment_id = quick_environment_id
            env_url = reverse('horizon:murano:environments:services',
                              args=(environment_id,))

            srv = env_api.service_create(
                self.request, environment_id, attributes)
        except exc.HTTPForbidden:
            msg = _("Sorry, you can't add application right now. "
                    "The environment is deploying.")
            exceptions.handle(self.request, msg, redirect=fail_url)
        except Exception:
            message = _('Adding application to an environment failed.')
            LOG.exception(message)
            if quick_environment_id:
                env_api.environment_delete(self.request, quick_environment_id)
                fail_url = reverse('horizon:murano:catalog:index')
            exceptions.handle(self.request, message, redirect=fail_url)
        else:
            message = _("The '{0}' application successfully added to "
                        "environment.").format(app_name)
            LOG.info(message)
            messages.success(self.request, message)

            if do_redirect:
                return http.HttpResponseRedirect(env_url)
            else:
                srv_id = getattr(srv, '?')['id']
                return self.create_hacked_response(
                    srv_id,
                    attributes['?'].get('name') or attributes.get('name'))
Example #5
0
    def done(self, form_list, **kwargs):
        environment_id = kwargs.get('environment_id')
        env_url = url.reverse('horizon:murano:environments:services',
                              args=(environment_id,))
        app_name = services.get_service_name(self.request,
                                             kwargs.get('app_id'))

        service = form_list[0].service
        attributes = service.extract_attributes()
        attributes = helpers.insert_hidden_ids(attributes)

        storage = attributes.setdefault('?', {}).setdefault(
            consts.DASHBOARD_ATTRS_KEY, {})
        storage['name'] = app_name

        wm_form_data = service.cleaned_data.get('workflowManagement')
        if wm_form_data:
            do_redirect = not wm_form_data['StayAtCatalog']
        else:
            do_redirect = self.get_wizard_flag('do_redirect')

        fail_url = url.reverse("horizon:murano:environments:index")
        try:
            srv = api.service_create(self.request, environment_id, attributes)
        except exc.HTTPForbidden:
            msg = _("Sorry, you can't add application right now. "
                    "The environment is deploying.")
            exceptions.handle(self.request, msg, redirect=fail_url)
        except Exception:
            exceptions.handle(self.request,
                              _("Sorry, you can't add application right now."),
                              redirect=fail_url)
        else:
            message = "The '{0}' application successfully " \
                      "added to environment.".format(app_name)

            messages.success(self.request, message)

            if do_redirect:
                return http.HttpResponseRedirect(env_url)
            else:
                srv_id = getattr(srv, '?')['id']
                return self.create_hacked_response(srv_id, attributes['name'])
Example #6
0
    def done(self, form_list, **kwargs):
        app_name = self.storage.extra_data['app'].name

        service = form_list[0].service
        attributes = service.extract_attributes()
        attributes = helpers.insert_hidden_ids(attributes)
        storage = attributes.setdefault('?', {}).setdefault(consts.DASHBOARD_ATTRS_KEY, {})
        storage['name'] = app_name

        do_redirect = self.get_wizard_flag('do_redirect')
        wm_form_data = service.cleaned_data.get('workflowManagement')
        if wm_form_data:
            do_redirect = do_redirect or not wm_form_data.get(
                'stay_at_the_catalog', True)

        fail_url = reverse("horizon:murano:scheduler:index")
        try:
            env_url = reverse('horizon:murano:scheduler:index')
            srv = api.service_create(self.request, self.environment_id, attributes)
        except exc.HTTPForbidden:
            msg = _("Sorry, you can't add task right now. The scheduler is deploying.")
            exceptions.handle(self.request, msg, redirect=fail_url)
        except Exception:
            message = _('Adding task to an schedule failed.')
            LOG.exception(message)
            exceptions.handle(self.request, message, redirect=fail_url)
        else:
            message = _("The '{0}' task successfully added to schedule.").format(app_name)
            LOG.info(message)
            messages.success(self.request, message)

            if do_redirect:
                return http.HttpResponseRedirect(env_url)
            else:
                srv_id = getattr(srv, '?')['id']
                return self.create_hacked_response(
                    srv_id,
                    attributes['?'].get('name') or attributes.get('name'))