Merge "Fix mismatching fixed vs unique container names" into stable/stein

This commit is contained in:
Zuul 2019-08-17 00:02:05 +00:00 committed by Gerrit Code Review
commit 0be2e7a9b2
4 changed files with 25 additions and 9 deletions

View File

@ -187,13 +187,14 @@ def debug(config_id, container_name, action, config, managed_by, labels=None,
log=log log=log
) )
if action == 'print-cmd': if action == 'print-cmd':
uname = r.unique_container_name(container_name)
cmd = [ cmd = [
r.cont_cmd, r.cont_cmd,
'run', 'run',
'--name', '--name',
r.unique_container_name(container_name) uname
] ]
builder.container_run_args(cmd, container_name) builder.container_run_args(cmd, container_name, uname)
if '--health-cmd' in cmd: if '--health-cmd' in cmd:
health_check_arg_index = cmd.index('--health-cmd') + 1 health_check_arg_index = cmd.index('--health-cmd') + 1
@ -208,13 +209,14 @@ def debug(config_id, container_name, action, config, managed_by, labels=None,
print(' '.join(cmd)) print(' '.join(cmd))
elif action == 'run': elif action == 'run':
uname = r.unique_container_name(container_name)
cmd = [ cmd = [
r.cont_cmd, r.cont_cmd,
'run', 'run',
'--name', '--name',
r.unique_container_name(container_name) uname
] ]
if builder.container_run_args(cmd, container_name): if builder.container_run_args(cmd, container_name, uname):
return r.execute_interactive(cmd, log) return r.execute_interactive(cmd, log)
elif action == 'dump-yaml': elif action == 'dump-yaml':
print(yaml.safe_dump(config, default_flow_style=False)) print(yaml.safe_dump(config, default_flow_style=False))

View File

@ -105,7 +105,9 @@ class BaseBuilder(object):
] ]
self.label_arguments(cmd, container) self.label_arguments(cmd, container)
self.log.debug("Start container {}.".format(container)) self.log.debug("Start container {}.".format(container))
validations_passed = self.container_run_args(cmd, container) validations_passed = self.container_run_args(cmd,
container,
container_name)
elif action == 'exec': elif action == 'exec':
cmd = [self.runner.cont_cmd, 'exec'] cmd = [self.runner.cont_cmd, 'exec']
validations_passed = self.cont_exec_args(cmd, container) validations_passed = self.cont_exec_args(cmd, container)

View File

@ -22,13 +22,18 @@ class ComposeV1Builder(base.BaseBuilder):
super(ComposeV1Builder, self).__init__(config_id, config, runner, super(ComposeV1Builder, self).__init__(config_id, config, runner,
labels, log) labels, log)
def container_run_args(self, cmd, container): def container_run_args(self, cmd, container, delegate=None):
"""Prepare the run command args, from the container configuration. """Prepare the run command args, from the container configuration.
:param cmd: The list of command options to be modified :param cmd: The list of command options to be modified
:param container: A dict with container configurations :param container: A dict with container configurations
:delegate: A compatibility parameter for podman, does nothing here
:returns: True if configuration is valid, otherwise False :returns: True if configuration is valid, otherwise False
""" """
if delegate and container != delegate:
self.log.debug("Delegate {} of container {} has no special "
"meanings for this context and will be "
"ignored".format(delegate, container))
cconfig = self.config[container] cconfig = self.config[container]
if cconfig.get('detach', True): if cconfig.get('detach', True):
cmd.append('--detach=true') cmd.append('--detach=true')

View File

@ -23,17 +23,24 @@ class PodmanBuilder(base.BaseBuilder):
labels, log, cont_log_path, labels, log, cont_log_path,
healthcheck_disabled) healthcheck_disabled)
def container_run_args(self, cmd, container): def container_run_args(self, cmd, container, delegate=None):
"""Prepare the run command args, from the container configuration. """Prepare the run command args, from the container configuration.
:param cmd: The list of command options to be modified :param cmd: The list of command options to be modified
:param container: A dict with container configurations :param container: A dict with container configurations
:param delegate: A predictable/unique name of the actual container
:returns: True if configuration is valid, otherwise False :returns: True if configuration is valid, otherwise False
""" """
if delegate and container != delegate:
self.log.debug("Container {} has a delegate "
"{}".format(container, delegate))
if not delegate:
delegate = container
cconfig = self.config[container] cconfig = self.config[container]
# write out a pid file so we can restart the container via systemd # write out a pid file so we can restart the container delegate
cmd.append('--conmon-pidfile=/var/run/{}.pid'.format(container)) # via systemd
cmd.append('--conmon-pidfile=/var/run/{}.pid'.format(delegate))
if cconfig.get('detach', True): if cconfig.get('detach', True):
cmd.append('--detach=true') cmd.append('--detach=true')