Change exception type when restart_policy is invalid
This patch change the raised exception from ZunException to InvalidValue, when restart_policy is incorrect. It also adds test case to validate mandatory parameters of restart policy. Change-Id: I9915af0ff6f65df45261d929b6ab52353e90055c
This commit is contained in:
parent
17331e9f5a
commit
b9af596035
@ -164,7 +164,7 @@ class ContainersController(rest.RestController):
|
||||
count = int(num)
|
||||
if name in ['unless-stopped', 'always']:
|
||||
if count != 0:
|
||||
raise exception.ZunException(_LE("maximum retry "
|
||||
raise exception.InvalidValue(_LE("maximum retry "
|
||||
"count not valid "
|
||||
"with restart policy "
|
||||
"of %s") % name)
|
||||
|
@ -402,7 +402,7 @@ class TestContainerController(api_base.FunctionalTest):
|
||||
'"restart_policy": {"Name": "always",'
|
||||
'"MaximumRetryCount": "1"}}')
|
||||
with self.assertRaisesRegexp(
|
||||
AppError, "Bad response: 500 Internal Server Error"):
|
||||
AppError, "maximum retry count not valid with"):
|
||||
self.app.post('/v1/containers/',
|
||||
params=params,
|
||||
content_type='application/json')
|
||||
|
@ -142,3 +142,15 @@ class TestSchemaValidations(base.BaseTestCase):
|
||||
"Invalid input for field "
|
||||
"'MaximumRetryCount'"):
|
||||
self.schema_validator.validate(request_to_validate)
|
||||
|
||||
def test_create_schema_restart_policy(self):
|
||||
restart_policy = {'Name': 'no'}
|
||||
request_to_validate = {'name': 'test1', 'image': 'nginx',
|
||||
'restart_policy': restart_policy}
|
||||
self.schema_validator.validate(request_to_validate)
|
||||
restart_policy = {'MaximumRetryCount': 5}
|
||||
request_to_validate = {'name': 'test1', 'image': 'nginx',
|
||||
'restart_policy': restart_policy}
|
||||
with self.assertRaisesRegexp(exception.SchemaValidationError,
|
||||
"'Name' is a required property"):
|
||||
self.schema_validator.validate(request_to_validate)
|
||||
|
Loading…
x
Reference in New Issue
Block a user