Implement start_order for containers
Allow for ordering containers execution within the same step. This hook uses `start_order` and it defaults to 0. Co-Authored-by: Ian Main <imain@redhat.com> Change-Id: Ib0804ee622e2889e6c18a76f07a194490f4721d4
This commit is contained in:
parent
4c86787c82
commit
4f6010da30
|
@ -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')
|
||||
|
||||
if action == 'run':
|
||||
|
@ -94,7 +95,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']
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
@ -114,14 +117,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([
|
||||
|
@ -130,7 +126,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([
|
||||
|
@ -169,14 +172,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([
|
||||
|
@ -185,7 +181,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'])
|
||||
|
||||
|
|
Loading…
Reference in New Issue