Merge "Zun execute without command returned 500"

This commit is contained in:
Jenkins 2017-05-17 07:16:36 +00:00 committed by Gerrit Code Review
commit c11caef091
4 changed files with 34 additions and 0 deletions

View File

@ -414,6 +414,8 @@ class ContainersController(base.Controller):
@pecan.expose('json')
@exception.wrap_pecan_controller_exception
@validation.validate_query_param(pecan.request,
schema.query_param_execute_command)
def execute(self, container_id, run=True, interactive=False, **kw):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:execute")

View File

@ -126,3 +126,13 @@ query_param_signal = {
},
'additionalProperties': False
}
query_param_execute_command = {
'type': 'object',
'properties': {
'run': parameter_types.boolean,
'interactive': parameter_types.boolean,
'command': parameter_types.exec_command,
},
'additionalProperties': False
}

View File

@ -184,3 +184,8 @@ signal = {
'type': ['string', 'null'],
'enum': SIGNALS
}
exec_command = {
'type': ['string'],
'minLength': 1,
}

View File

@ -862,6 +862,23 @@ class TestContainerController(api_base.FunctionalTest):
self.app.post('/v1/containers/%s/%s/' % (test_object.uuid,
'execute'), cmd)
@patch('zun.common.utils.validate_container_state')
@patch('zun.compute.api.API.container_exec')
@patch('zun.objects.Container.get_by_uuid')
def test_execute_without_command_by_uuid(self, mock_get_by_uuid,
mock_container_exec,
mock_validate):
test_container = utils.get_test_container()
test_container_obj = objects.Container(self.context, **test_container)
mock_get_by_uuid.return_value = test_container_obj
container_uuid = test_container.get('uuid')
cmd = {'command': ''}
self.assertRaises(AppError, self.app.post,
'/v1/containers/%s/execute' %
container_uuid, cmd)
self.assertFalse(mock_container_exec.called)
@patch('zun.common.utils.validate_container_state')
@patch('zun.compute.api.API.container_delete')
@patch('zun.objects.Container.get_by_uuid')