Immediately validate the state of container after checking policy

If the state of the container is not in conformity with the rules,
it will raise exception earlier and needn't handle the parameters.

Change-Id: I8251a1ef92342be8638b84b7aad1c876cacb0896
This commit is contained in:
Feng Shengqin
2017-04-06 09:39:26 +08:00
parent 9289330373
commit d4815fabbe

View File

@@ -414,13 +414,13 @@ class ContainersController(rest.RestController):
def execute(self, container_id, run=True, interactive=False, **kw):
container = _get_container(container_id)
check_policy_on_container(container.as_dict(), "container:execute")
utils.validate_container_state(container, 'execute')
try:
run = strutils.bool_from_string(run, strict=True)
interactive = strutils.bool_from_string(interactive, strict=True)
except ValueError:
msg = _('Valid run values are true, false, 0, 1, yes and no')
raise exception.InvalidValue(msg)
utils.validate_container_state(container, 'execute')
LOG.debug('Calling compute.container_exec with %s command %s'
% (container.uuid, kw['command']))
context = pecan.request.context