Merge "Add exit_codes option to docker-cmd hook"

This commit is contained in:
Jenkins 2017-01-17 14:39:13 +00:00 committed by Gerrit Code Review
commit 540b31413d
2 changed files with 44 additions and 1 deletions

View File

@ -86,6 +86,7 @@ def main(argv=sys.argv):
for container in sorted(config):
action = config[container].get('action', 'run')
exit_codes = config[container].get('exit_codes', [0])
if action == 'run':
cmd = [
@ -137,8 +138,11 @@ def main(argv=sys.argv):
else:
log.debug('Completed %s' % cmd)
if subproc.returncode != 0:
if subproc.returncode not in exit_codes:
log.error("Error running %s. [%s]\n" % (cmd, subproc.returncode))
deploy_status_code = subproc.returncode
else:
log.debug('Completed %s' % cmd)
json.dump(build_response(
'\n'.join(stdout), '\n'.join(stderr), deploy_status_code), sys.stdout)

View File

@ -56,6 +56,18 @@ class HookDockerCmdTest(common.RunScriptTest):
}
}
data_exit_code = {
"name": "abcdef001",
"group": "docker-cmd",
"config": {
"web-ls": {
"action": "exec",
"command": ["web", "/bin/ls", "-l"],
"exit_codes": [0, 1]
}
}
}
def setUp(self):
super(HookDockerCmdTest, self).setUp()
self.hook_path = self.relative_path(
@ -141,6 +153,33 @@ class HookDockerCmdTest(common.RunScriptTest):
'-l'
], state_2['args'])
def test_hook_exit_codes(self):
self.env.update({
'TEST_RESPONSE': json.dumps({
'stdout': '',
'stderr': 'Warning: custom exit code',
'returncode': 1
})
})
returncode, stdout, stderr = self.run_cmd(
[self.hook_path], self.env, json.dumps(self.data_exit_code))
self.assertEqual({
'deploy_stdout': '',
'deploy_stderr': 'Warning: custom exit code',
'deploy_status_code': 0
}, json.loads(stdout))
state_0 = self.json_from_file(self.test_state_path)
self.assertEqual([
self.fake_tool_path,
'exec',
'web',
'/bin/ls',
'-l'
], state_0['args'])
def test_hook_failed(self):
self.env.update({