Merge "Modify environment delete API endopoint to have "abandon" feature"
This commit is contained in:
commit
64ebdc11db
@ -286,9 +286,30 @@ Delete environment
|
|||||||
+----------+----------------------------------+----------------------------------+
|
+----------+----------------------------------+----------------------------------+
|
||||||
| Method | URI | Description |
|
| 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
|
Environment configuration API
|
||||||
=============================
|
=============================
|
||||||
|
|
||||||
|
@ -143,9 +143,13 @@ class Controller(object):
|
|||||||
|
|
||||||
@request_statistics.stats_count(API_NAME, 'Delete')
|
@request_statistics.stats_count(API_NAME, 'Delete')
|
||||||
def delete(self, request, environment_id):
|
def delete(self, request, environment_id):
|
||||||
LOG.debug('Environments:Delete <Id: {0}>'.format(environment_id))
|
|
||||||
target = {"environment_id": environment_id}
|
target = {"environment_id": environment_id}
|
||||||
policy.check('delete_environment', request.context, target)
|
policy.check('delete_environment', request.context, target)
|
||||||
|
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()
|
sessions_controller = sessions.Controller()
|
||||||
session = sessions_controller.configure(request, environment_id)
|
session = sessions_controller.configure(request, environment_id)
|
||||||
session_id = session['id']
|
session_id = session['id']
|
||||||
|
@ -172,9 +172,11 @@ class ControllerTest(object):
|
|||||||
return self._simple_request(path, params=params, user=user,
|
return self._simple_request(path, params=params, user=user,
|
||||||
tenant=tenant)
|
tenant=tenant)
|
||||||
|
|
||||||
def _delete(self, path, user=DEFAULT_USER, tenant=DEFAULT_TENANT):
|
def _delete(self, path, params=None, user=DEFAULT_USER,
|
||||||
return self._simple_request(path, method='DELETE', user=user,
|
tenant=DEFAULT_TENANT):
|
||||||
tenant=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',
|
def _data_request(self, path, data, content_type='application/json',
|
||||||
method='POST', params={},
|
method='POST', params={},
|
||||||
|
@ -201,47 +201,8 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
{'update_environment': '@'}
|
{'update_environment': '@'}
|
||||||
)
|
)
|
||||||
|
|
||||||
fake_now = timeutils.utcnow()
|
self._create_fake_environment('env1', '111')
|
||||||
timeutils.utcnow.override_time = fake_now
|
self._create_fake_environment('env2', '222')
|
||||||
|
|
||||||
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.expect_policy_check('update_environment',
|
self.expect_policy_check('update_environment',
|
||||||
{'environment_id': '111'})
|
{'environment_id': '111'})
|
||||||
@ -255,17 +216,17 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
|
|
||||||
def test_delete_environment(self):
|
def test_delete_environment(self):
|
||||||
"""Test that environment deletion results in the correct rpc call."""
|
"""Test that environment deletion results in the correct rpc call."""
|
||||||
self._set_policy_rules(
|
self._test_delete_or_abandon(abandon=False)
|
||||||
{'delete_environment': '@'}
|
|
||||||
)
|
|
||||||
self.expect_policy_check(
|
|
||||||
'delete_environment', {'environment_id': '12345'}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
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()
|
fake_now = timeutils.utcnow()
|
||||||
expected = dict(
|
expected = dict(
|
||||||
id='12345',
|
id=env_id,
|
||||||
name='my-env',
|
name=env_name,
|
||||||
version=0,
|
version=0,
|
||||||
networking={},
|
networking={},
|
||||||
created=fake_now,
|
created=fake_now,
|
||||||
@ -273,7 +234,7 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
tenant_id=self.tenant,
|
tenant_id=self.tenant,
|
||||||
description={
|
description={
|
||||||
'Objects': {
|
'Objects': {
|
||||||
'?': {'id': '12345'}
|
'?': {'id': '{0}'.format(env_id)}
|
||||||
},
|
},
|
||||||
'Attributes': {}
|
'Attributes': {}
|
||||||
}
|
}
|
||||||
@ -281,7 +242,21 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
|||||||
e = models.Environment(**expected)
|
e = models.Environment(**expected)
|
||||||
test_utils.save_models(e)
|
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)
|
result = req.get_response(self.api)
|
||||||
|
|
||||||
# Should this be expected behavior?
|
# Should this be expected behavior?
|
||||||
|
Loading…
Reference in New Issue
Block a user