Merge "Implement start_order for containers"

This commit is contained in:
Jenkins 2017-01-30 02:04:35 +00:00 committed by Gerrit Code Review
commit 301db11253
2 changed files with 29 additions and 24 deletions

View File

@ -37,7 +37,6 @@ def build_response(deploy_stdout, deploy_stderr, deploy_status_code):
def docker_arg_map(key, value):
value = str(value).encode('ascii', 'ignore')
return {
'container_step_config': None,
'environment': "--env=%s" % value,
'image': value,
'net': "--net=%s" % value,
@ -84,7 +83,9 @@ def main(argv=sys.argv):
if not isinstance(config, dict):
config = yaml.safe_load(config)
for container in sorted(config):
key_fltr = lambda k: config[k].get('start_order', 0)
for container in sorted(config, key=key_fltr):
log.debug("Running container: %s" % container)
action = config[container].get('action', 'run')
exit_codes = config[container].get('exit_codes', [0])
@ -95,7 +96,8 @@ def main(argv=sys.argv):
'--name',
container
]
cmd.append('--detach=%s' % config[container].get('detach', 'true'))
if config[container].get('detach', True):
cmd.append('--detach=true')
elif action == 'exec':
cmd = [DOCKER_CMD, 'exec']

View File

@ -27,17 +27,20 @@ class HookDockerCmdTest(common.RunScriptTest):
"name": "abcdef001",
"group": "docker-cmd",
"config": {
"web": {
"db": {
"name": "x",
"image": "xxx",
"privileged": False
"privileged": False,
"start_order": 0
},
"web-ls": {
"action": "exec",
"start_order": 2,
"command": ["web", "/bin/ls", "-l"]
},
"db": {
"web": {
"name": "y",
"start_order": 1,
"image": "xxx",
"net": "host",
"restart": "always",
@ -126,14 +129,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'--name',
'db',
'--detach=true',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
'--privileged=true',
'--restart=always',
'--user=root',
'--volume=/run:/run',
'--volume=db:/var/lib/db',
'--privileged=false',
'xxx'
], state_0['args'])
self.assertEqual([
@ -142,7 +138,14 @@ class HookDockerCmdTest(common.RunScriptTest):
'--name',
'web',
'--detach=true',
'--privileged=false',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
'--privileged=true',
'--restart=always',
'--user=root',
'--volume=/run:/run',
'--volume=db:/var/lib/db',
'xxx'
], state_1['args'])
self.assertEqual([
@ -208,14 +211,7 @@ class HookDockerCmdTest(common.RunScriptTest):
'--name',
'db',
'--detach=true',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
'--privileged=true',
'--restart=always',
'--user=root',
'--volume=/run:/run',
'--volume=db:/var/lib/db',
'--privileged=false',
'xxx'
], state_0['args'])
self.assertEqual([
@ -224,7 +220,14 @@ class HookDockerCmdTest(common.RunScriptTest):
'--name',
'web',
'--detach=true',
'--privileged=false',
'--env=KOLLA_CONFIG_STRATEGY=COPY_ALWAYS',
'--env=FOO=BAR',
'--net=host',
'--privileged=true',
'--restart=always',
'--user=root',
'--volume=/run:/run',
'--volume=db:/var/lib/db',
'xxx'
], state_1['args'])