Check if container is running before doing an exec

(a partial backport limited only to discover_container_name)

It only consolidates the discover_container_name method in order to get
more chance to actually get a name.

Co-Authored-By: Cédric Jeanneret <cjeanner@redhat.com>
Closes-Bug: #1839559
Change-Id: If4d8c268218bf83abed877a699fc583fb55ccbed
(cherry picked from commit 983ab98f61)
This commit is contained in:
Emilien Macchi 2019-08-21 22:06:34 -04:00 committed by Bogdan Dobrelya
parent 1c590fc76d
commit d66ba71100
1 changed files with 23 additions and 5 deletions

View File

@ -176,11 +176,29 @@ class DockerRunner(object):
'{{.Names}}' '{{.Names}}'
] ]
(cmd_stdout, cmd_stderr, returncode) = self.execute(cmd, self.log) (cmd_stdout, cmd_stderr, returncode) = self.execute(cmd, self.log)
if returncode != 0: if returncode == 0:
return container names = cmd_stdout.split()
names = cmd_stdout.split() if names:
if names: return names[0]
return names[0] self.log.warning('Did not find container with "%s" - retrying without '
'config_id' % cmd)
cmd = [
self.docker_cmd,
'ps',
'-a',
'--filter',
'label=container_name=%s' % container,
'--format',
'{{.Names}}'
]
(cmd_stdout, cmd_stderr, returncode) = self.execute(cmd, self.log)
if returncode == 0:
names = cmd_stdout.split()
if names:
return names[0]
self.log.warning('Did not find container with "%s"' % cmd)
return container return container
def delete_missing_configs(self, config_ids): def delete_missing_configs(self, config_ids):