Fix discovering container names
Make discover_container_name returning None, if the ps command failed or returned nothing useful. * For 'run', if no container name has been discovered, use its predictable (fixed) container service name. * For 'exec', also raise an error, if no name has been discovered for the fixed/service container. Do not use additional checks as the None returned by discover_container_name() already tells us all we need to know about the subject container. Related-Bug: #1839929 Co-Authored-By: Cédric Jeanneret <cjeanner@redhat.com> Change-Id: I8a495d2c98617bb5edbe13ccf737d6c630eea7ad Signed-off-by: Bogdan Dobrelya <bdobreli@redhat.com>
This commit is contained in:
parent
f20c8f8158
commit
3dcbe5e68c
|
@ -78,17 +78,20 @@ class BaseBuilder(object):
|
|||
container)
|
||||
continue
|
||||
|
||||
c_name = self.runner.discover_container_name(
|
||||
container, self.config_id) or container
|
||||
cmd = [
|
||||
self.runner.cont_cmd,
|
||||
start_cmd,
|
||||
'--name',
|
||||
container_name
|
||||
c_name
|
||||
]
|
||||
|
||||
self.label_arguments(cmd, container)
|
||||
validations_passed = self.container_run_args(cmd,
|
||||
container,
|
||||
container_name)
|
||||
self.log.debug("Start container {} as {}.".format(container,
|
||||
c_name))
|
||||
validations_passed = self.container_run_args(
|
||||
cmd, container, c_name)
|
||||
elif action == 'exec':
|
||||
# for exec, the first argument is the fixed named container
|
||||
# used when running the command into the running container.
|
||||
|
@ -102,7 +105,7 @@ class BaseBuilder(object):
|
|||
# Before running the exec, we want to make sure the container
|
||||
# is running.
|
||||
# https://bugs.launchpad.net/bugs/1839559
|
||||
if not self.runner.container_running(c_name):
|
||||
if not c_name or not self.runner.container_running(c_name):
|
||||
msg = ('Failing to apply action exec for '
|
||||
'container: %s' % container)
|
||||
raise RuntimeError(msg)
|
||||
|
|
|
@ -170,7 +170,6 @@ class BaseRunner(object):
|
|||
return names[0]
|
||||
|
||||
self.log.warning('Did not find container with "%s"' % cmd)
|
||||
return container
|
||||
|
||||
def delete_missing_configs(self, config_ids):
|
||||
if not config_ids:
|
||||
|
|
|
@ -142,7 +142,7 @@ class TestBaseRunner(base.TestCase):
|
|||
self.mock_execute(popen, '', '', 0)
|
||||
|
||||
self.assertEqual(
|
||||
'one',
|
||||
None,
|
||||
self.runner.discover_container_name('one', 'foo')
|
||||
)
|
||||
|
||||
|
@ -151,7 +151,7 @@ class TestBaseRunner(base.TestCase):
|
|||
self.mock_execute(popen, '', 'ouch', 1)
|
||||
|
||||
self.assertEqual(
|
||||
'one',
|
||||
None,
|
||||
self.runner.discover_container_name('one', 'foo')
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue