From 1adc59cef39a81cc9c943f907eae304537133659 Mon Sep 17 00:00:00 2001 From: visitor Date: Wed, 1 Jun 2016 12:10:32 +0200 Subject: [PATCH] Fixing application template deletion Deleting an application/service in a environment template does not work and murano got blocked. This patch solves that bug. Closes-Bug: #1587809 Change-Id: I871e3b0eca82c14354b9c7ff2abce90da7cb21b0 --- doc/source/specification/murano-env-temp.rst | 13 +++++++ murano/api/v1/template_applications.py | 3 +- murano/db/services/core_services.py | 1 + .../tests/unit/api/v1/test_env_templates.py | 38 +++++++++++++++++++ ...-app-in-env-template-d8e07d3b860f0441.yaml | 2 + 5 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/delete-app-in-env-template-d8e07d3b860f0441.yaml diff --git a/doc/source/specification/murano-env-temp.rst b/doc/source/specification/murano-env-temp.rst index 4c46b01a9..1fd67547d 100644 --- a/doc/source/specification/murano-env-temp.rst +++ b/doc/source/specification/murano-env-temp.rst @@ -325,6 +325,19 @@ Delete application from an environment template *Response* + +:: + + { + "updated": "2015-01-26T09:12:51", + "services": [], + "name": "template_name", + "created": "2015-01-26T09:12:51", + "tenant_id": "00000000000000000000000000000001", + "version": 0, + "id": "aa9033ca7ce245fca10e38e1c8c4bbf7", + } + +----------------+-----------------------------------------------------------+ | Code | Description | +================+===========================================================+ diff --git a/murano/api/v1/template_applications.py b/murano/api/v1/template_applications.py index 2bf60c549..983fe63ca 100644 --- a/murano/api/v1/template_applications.py +++ b/murano/api/v1/template_applications.py @@ -177,12 +177,13 @@ class Controller(object): path=path)) delete_data = core_services.CoreServices.delete_env_template_data try: - delete_data(env_template_id, path) + result = delete_data(env_template_id, path) except (KeyError, ValueError): msg = _('The template does not exist {templ_id}').format( templ_id=env_template_id) LOG.exception(msg) raise exc.HTTPNotFound(msg) + return result def create_resource(): diff --git a/murano/db/services/core_services.py b/murano/db/services/core_services.py index 02eac447f..95bc5ff39 100644 --- a/murano/db/services/core_services.py +++ b/murano/db/services/core_services.py @@ -228,3 +228,4 @@ class CoreServices(object): utils.TraverseHelper.remove(path, tmp_description) save_description(tmp_description, env_template_id) + return tmp_description diff --git a/murano/tests/unit/api/v1/test_env_templates.py b/murano/tests/unit/api/v1/test_env_templates.py index 0287da8be..fb349916b 100644 --- a/murano/tests/unit/api/v1/test_env_templates.py +++ b/murano/tests/unit/api/v1/test_env_templates.py @@ -588,6 +588,7 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): req = self._post('/templates', json.dumps(body)) result = req.get_response(self.api) self.assertEqual(200, result.status_code) + self.assertEqual(1, len(json.loads(result.body)['services'])) req = self._get('/templates/%s/services' % self.uuids[0]) result = req.get_response(self.api) @@ -603,7 +604,9 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): req = self._delete('/templates/' + self.uuids[0] + '/services/' + service_id) result = req.get_response(self.api) + self.assertEqual(200, result.status_code) + self.assertEqual(0, len(json.loads(result.body)['services'])) req = self._get('/templates/' + self.uuids[0] + '/services/' + service_id) @@ -678,6 +681,41 @@ class TestEnvTemplateApi(tb.ControllerTest, tb.MuranoApiTestCase): result = req.get_response(self.api) self.assertEqual(400, result.status_code) + def test_delete_notexisting_service(self): + """Check deleting a not existing service, return a 404 error.""" + self._set_policy_rules( + {'create_env_template': '@', + 'delete_env_application': '@'} + ) + self.expect_policy_check('create_env_template') + + fake_now = timeutils.utcnow() + timeutils.utcnow.override_time = fake_now + + body = { + "name": "mytemplate", + "services": [ + { + "name": "tomcat", + "port": "8080", + "?": { + "type": "io.murano.apps.apache.Tomcat", + "id": "ID1" + } + } + ] + } + + req = self._post('/templates', json.dumps(body)) + result = req.get_response(self.api) + self.assertEqual(200, result.status_code) + self.assertEqual(1, len(json.loads(result.body)['services'])) + + req = self._delete('/templates/{0}/services/{1}'.format(self.uuids[0], + "NO_EXIST")) + result = req.get_response(self.api) + self.assertEqual(404, result.status_code) + def test_create_env_notexisting_templatebody(self): """Check that an illegal temp name results in an HTTPClientError.""" self._set_policy_rules( diff --git a/releasenotes/notes/delete-app-in-env-template-d8e07d3b860f0441.yaml b/releasenotes/notes/delete-app-in-env-template-d8e07d3b860f0441.yaml new file mode 100644 index 000000000..058564284 --- /dev/null +++ b/releasenotes/notes/delete-app-in-env-template-d8e07d3b860f0441.yaml @@ -0,0 +1,2 @@ +fixes: + - Fix delete application in environment template