diff --git a/doc/source/specification/murano-api.rst b/doc/source/specification/murano-api.rst index 609351e0..47983c45 100644 --- a/doc/source/specification/murano-api.rst +++ b/doc/source/specification/murano-api.rst @@ -286,9 +286,30 @@ Delete environment +----------+----------------------------------+----------------------------------+ | Method | URI | Description | +==========+==================================+==================================+ -| DELETE | /environments/{id} | Remove specified Environment. | +| DELETE | /environments/{id}?abandon | Remove specified Environment. | +----------+----------------------------------+----------------------------------+ + +*Parameters:* + +* `abandon` - boolean, indicates how to delete environment. *False* is used if + all resources used by environment must be destroyed; *True* is used when just + database must be cleaned + + +*Response* + ++----------------+-----------------------------------------------------------+ +| Code | Description | ++================+===========================================================+ +| 200 | OK. Environment deleted successfully | ++----------------+-----------------------------------------------------------+ +| 403 | User is not allowed to delete this resource | ++----------------+-----------------------------------------------------------+ +| 404 | Not found. Specified environment doesn`t exist | ++----------------+-----------------------------------------------------------+ + + Environment configuration API ============================= diff --git a/murano/api/v1/environments.py b/murano/api/v1/environments.py index b63824b7..ca4c8480 100644 --- a/murano/api/v1/environments.py +++ b/murano/api/v1/environments.py @@ -143,14 +143,18 @@ class Controller(object): @request_statistics.stats_count(API_NAME, 'Delete') def delete(self, request, environment_id): - LOG.debug('Environments:Delete '.format(environment_id)) target = {"environment_id": environment_id} policy.check('delete_environment', request.context, target) - sessions_controller = sessions.Controller() - session = sessions_controller.configure(request, environment_id) - session_id = session['id'] - envs.EnvironmentServices.delete(environment_id, session_id) - sessions_controller.deploy(request, environment_id, session_id) + if request.GET.get('abandon', '').lower() == 'true': + LOG.debug('Environments:Abandon '.format(environment_id)) + envs.EnvironmentServices.remove(environment_id) + else: + LOG.debug('Environments:Delete '.format(environment_id)) + sessions_controller = sessions.Controller() + session = sessions_controller.configure(request, environment_id) + session_id = session['id'] + envs.EnvironmentServices.delete(environment_id, session_id) + sessions_controller.deploy(request, environment_id, session_id) @request_statistics.stats_count(API_NAME, 'LastStatus') def last(self, request, environment_id): diff --git a/murano/tests/unit/api/base.py b/murano/tests/unit/api/base.py index 9c72f925..54c66824 100644 --- a/murano/tests/unit/api/base.py +++ b/murano/tests/unit/api/base.py @@ -172,9 +172,11 @@ class ControllerTest(object): return self._simple_request(path, params=params, user=user, tenant=tenant) - def _delete(self, path, user=DEFAULT_USER, tenant=DEFAULT_TENANT): - return self._simple_request(path, method='DELETE', user=user, - tenant=tenant) + def _delete(self, path, params=None, user=DEFAULT_USER, + tenant=DEFAULT_TENANT): + params = params or {} + return self._simple_request(path, params=params, method='DELETE', + user=user, tenant=tenant) def _data_request(self, path, data, content_type='application/json', method='POST', params={}, diff --git a/murano/tests/unit/api/v1/test_environments.py b/murano/tests/unit/api/v1/test_environments.py index 07facb1c..2ff21f18 100644 --- a/murano/tests/unit/api/v1/test_environments.py +++ b/murano/tests/unit/api/v1/test_environments.py @@ -201,47 +201,8 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase): {'update_environment': '@'} ) - fake_now = timeutils.utcnow() - timeutils.utcnow.override_time = fake_now - - expected = dict( - id='111', - name='env1', - version=0, - networking={}, - created=fake_now, - updated=fake_now, - tenant_id=self.tenant, - description={ - 'Objects': { - '?': {'id': '111'} - }, - 'Attributes': [] - } - ) - e = models.Environment(**expected) - test_utils.save_models(e) - - fake_now = timeutils.utcnow() - timeutils.utcnow.override_time = fake_now - - expected = dict( - id='222', - name='env2', - version=0, - networking={}, - created=fake_now, - updated=fake_now, - tenant_id=self.tenant, - description={ - 'Objects': { - '?': {'id': '222'} - }, - 'Attributes': [] - } - ) - e = models.Environment(**expected) - test_utils.save_models(e) + self._create_fake_environment('env1', '111') + self._create_fake_environment('env2', '222') self.expect_policy_check('update_environment', {'environment_id': '111'}) @@ -255,17 +216,17 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase): def test_delete_environment(self): """Test that environment deletion results in the correct rpc call.""" - self._set_policy_rules( - {'delete_environment': '@'} - ) - self.expect_policy_check( - 'delete_environment', {'environment_id': '12345'} - ) + self._test_delete_or_abandon(abandon=False) + def test_abandon_environment(self): + """Cjeck that abandon feature works""" + self._test_delete_or_abandon(abandon=True) + + def _create_fake_environment(self, env_name='my-env', env_id='123'): fake_now = timeutils.utcnow() expected = dict( - id='12345', - name='my-env', + id=env_id, + name=env_name, version=0, networking={}, created=fake_now, @@ -273,7 +234,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase): tenant_id=self.tenant, description={ 'Objects': { - '?': {'id': '12345'} + '?': {'id': '{0}'.format(env_id)} }, 'Attributes': {} } @@ -281,7 +242,21 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase): e = models.Environment(**expected) test_utils.save_models(e) - req = self._delete('/environments/12345') + def _test_delete_or_abandon(self, abandon, env_name='my-env', + env_id='123'): + self._set_policy_rules( + {'delete_environment': '@'} + ) + self.expect_policy_check( + 'delete_environment', + {'environment_id': '{0}'.format(env_id)} + ) + + self._create_fake_environment(env_name, env_id) + + path = '/environments/{0}'.format(env_id) + + req = self._delete(path, params={'abandon': abandon}) result = req.get_response(self.api) # Should this be expected behavior?