Merge "Change exception type when restart_policy is invalid"

This commit is contained in:
Jenkins 2017-01-27 05:32:57 +00:00 committed by Gerrit Code Review
commit f2c2b4d929
3 changed files with 14 additions and 2 deletions

View File

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

View File

@ -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')

View File

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