Improve exception handling during enviroment editing
Change-Id: Ie40cc99bb9b69caf4fe552a95c55c31a4d191f5a Partial-Bug: #1455142
This commit is contained in:
parent
1a84e6f729
commit
2eaedf2d79
@ -204,6 +204,21 @@ Update Environment
|
||||
"version": 0
|
||||
}
|
||||
|
||||
+----------------+-----------------------------------------------------------+
|
||||
| Code | Description |
|
||||
+================+===========================================================+
|
||||
| 200 | Edited environment |
|
||||
+----------------+-----------------------------------------------------------+
|
||||
| 400 | Environment name must contain only alphanumeric or '_-.' |
|
||||
| | characters, must start with alpha |
|
||||
+----------------+-----------------------------------------------------------+
|
||||
| 401 | User is not authorized to access environment |
|
||||
+----------------+-----------------------------------------------------------+
|
||||
| 404 | Environment not found |
|
||||
+----------------+-----------------------------------------------------------+
|
||||
| 409 | Environment with specified name already exists |
|
||||
+----------------+-----------------------------------------------------------+
|
||||
|
||||
Get Environment Details
|
||||
-----------------------
|
||||
|
||||
|
@ -126,8 +126,13 @@ class Controller(object):
|
||||
|
||||
LOG.debug('ENV NAME: {0}>'.format(body['name']))
|
||||
if VALID_NAME_REGEX.match(str(body['name'])):
|
||||
environment.update(body)
|
||||
environment.save(session)
|
||||
try:
|
||||
environment.update(body)
|
||||
environment.save(session)
|
||||
except db_exc.DBDuplicateEntry:
|
||||
msg = _('Environment with specified name already exists')
|
||||
LOG.exception(msg)
|
||||
raise exc.HTTPConflict(explanation=msg)
|
||||
else:
|
||||
msg = _('Environment name must contain only alphanumeric '
|
||||
'or "_-." characters, must start with alpha')
|
||||
|
@ -196,6 +196,63 @@ class TestEnvironmentApi(tb.ControllerTest, tb.MuranoApiTestCase):
|
||||
|
||||
self.assertEqual(expected, json.loads(result.body))
|
||||
|
||||
def test_update_environment_with_existing_name(self):
|
||||
self._set_policy_rules(
|
||||
{'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.expect_policy_check('update_environment',
|
||||
{'environment_id': '111'})
|
||||
|
||||
body = {
|
||||
'name': 'env2'
|
||||
}
|
||||
req = self._put('/environments/111', json.dumps(body))
|
||||
result = req.get_response(self.api)
|
||||
self.assertEqual(409, result.status_code)
|
||||
|
||||
def test_delete_environment(self):
|
||||
"""Test that environment deletion results in the correct rpc call."""
|
||||
self._set_policy_rules(
|
||||
|
Loading…
Reference in New Issue
Block a user