Modify environment delete API endopoint to have "abandon" feature

Added an ability to abandon the environment, which hangs during
deployment or deleting in order to hide it from the list of other
environments.

Change-Id: Iab47cf57a7147b4fd46d3320cffa625397c6c5a5
Partial-Bug: #1438810
Partially implements bp environment-abandon
This commit is contained in:
Dmytro Dovbii 2015-06-03 17:01:45 +03:00
parent e1c468a489
commit 24f66c3f43
4 changed files with 63 additions and 61 deletions

View File

@ -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
=============================

View File

@ -143,14 +143,18 @@ class Controller(object):
@request_statistics.stats_count(API_NAME, 'Delete')
def delete(self, request, environment_id):
LOG.debug('Environments:Delete <Id: {0}>'.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 <Id: {0}>'.format(environment_id))
envs.EnvironmentServices.remove(environment_id)
else:
LOG.debug('Environments:Delete <Id: {0}>'.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):

View File

@ -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={},

View File

@ -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?