From 3dcbe5e68c50a09a503ab52a03e082949bfed594 Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Mon, 26 Aug 2019 16:23:00 +0200 Subject: [PATCH] Fix discovering container names MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Change-Id: I8a495d2c98617bb5edbe13ccf737d6c630eea7ad Signed-off-by: Bogdan Dobrelya --- paunch/builder/base.py | 13 ++++++++----- paunch/runner.py | 1 - paunch/tests/test_runner.py | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/paunch/builder/base.py b/paunch/builder/base.py index 523355a..8824ee6 100644 --- a/paunch/builder/base.py +++ b/paunch/builder/base.py @@ -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) diff --git a/paunch/runner.py b/paunch/runner.py index 58a7eb7..9620991 100644 --- a/paunch/runner.py +++ b/paunch/runner.py @@ -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: diff --git a/paunch/tests/test_runner.py b/paunch/tests/test_runner.py index fa9776d..f92132a 100644 --- a/paunch/tests/test_runner.py +++ b/paunch/tests/test_runner.py @@ -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') )