Remove log message when container doesn't exist
When we upgrade from docker, we stop the container regardless of its status, but we don't need to see the message if it doesn't exist. In the same vein, when we generate a container name, we don't need logs from the inspect calls. Change-Id: Ifcbcc3b7d3f0524882fa6a158375b26ca87a08d7 Closes-Bug: #1801939
This commit is contained in:
parent
328e983d52
commit
33042f3ce1
|
@ -64,7 +64,7 @@ class BaseBuilder(object):
|
|||
# Podman. The container will be removed later in THT during
|
||||
# upgrade_tasks.
|
||||
if self.runner.cont_cmd == 'podman' and self.which('docker'):
|
||||
self.runner.stop_container(container, 'docker')
|
||||
self.runner.stop_container(container, 'docker', quiet=True)
|
||||
|
||||
if action == 'run':
|
||||
if container in desired_names:
|
||||
|
|
|
@ -29,15 +29,17 @@ class BaseRunner(object):
|
|||
self.log = log or common.configure_logging(__name__)
|
||||
|
||||
@staticmethod
|
||||
def execute(cmd, log=None):
|
||||
def execute(cmd, log=None, quiet=False):
|
||||
if not log:
|
||||
log = common.configure_logging(__name__)
|
||||
log.debug('$ %s' % ' '.join(cmd))
|
||||
if not quiet:
|
||||
log.debug('$ %s' % ' '.join(cmd))
|
||||
subproc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
cmd_stdout, cmd_stderr = subproc.communicate()
|
||||
log.debug(cmd_stdout)
|
||||
log.debug(cmd_stderr)
|
||||
if not quiet:
|
||||
log.debug(cmd_stdout)
|
||||
log.debug(cmd_stderr)
|
||||
return (cmd_stdout.decode('utf-8'),
|
||||
cmd_stderr.decode('utf-8'),
|
||||
subproc.returncode)
|
||||
|
@ -73,13 +75,15 @@ class BaseRunner(object):
|
|||
|
||||
return [c for c in cmd_stdout.split()]
|
||||
|
||||
def inspect(self, name, output_format=None, o_type='container'):
|
||||
def inspect(self, name, output_format=None, o_type='container',
|
||||
quiet=False):
|
||||
cmd = [self.cont_cmd, 'inspect', '--type', o_type]
|
||||
if output_format:
|
||||
cmd.append('--format')
|
||||
cmd.append(output_format)
|
||||
cmd.append(name)
|
||||
(cmd_stdout, cmd_stderr, returncode) = self.execute(cmd, self.log)
|
||||
(cmd_stdout, cmd_stderr, returncode) = self.execute(
|
||||
cmd, self.log, quiet)
|
||||
if returncode != 0:
|
||||
return
|
||||
try:
|
||||
|
@ -93,7 +97,7 @@ class BaseRunner(object):
|
|||
|
||||
def unique_container_name(self, container):
|
||||
container_name = container
|
||||
while self.inspect(container_name, output_format='exists'):
|
||||
while self.inspect(container_name, output_format='exists', quiet=True):
|
||||
suffix = ''.join(random.choice(
|
||||
string.ascii_lowercase + string.digits) for i in range(8))
|
||||
container_name = '%s-%s' % (container, suffix)
|
||||
|
@ -169,11 +173,11 @@ class BaseRunner(object):
|
|||
self.log.error('Error removing container: %s' % container)
|
||||
self.log.error(cmd_stderr)
|
||||
|
||||
def stop_container(self, container, cont_cmd=None):
|
||||
def stop_container(self, container, cont_cmd=None, quiet=False):
|
||||
cont_cmd = cont_cmd or self.cont_cmd
|
||||
cmd = [cont_cmd, 'stop', container]
|
||||
cmd_stdout, cmd_stderr, returncode = self.execute(cmd)
|
||||
if returncode != 0:
|
||||
cmd_stdout, cmd_stderr, returncode = self.execute(cmd, quiet=quiet)
|
||||
if returncode != 0 and not quiet:
|
||||
self.log.error('Error stopping container: %s' % container)
|
||||
self.log.error(cmd_stderr)
|
||||
|
||||
|
|
|
@ -94,12 +94,12 @@ class TestBaseBuilder(base.TestCase):
|
|||
# inspect existing image centos:6
|
||||
mock.call(
|
||||
['docker', 'inspect', '--type', 'image',
|
||||
'--format', 'exists', 'centos:6'], mock.ANY
|
||||
'--format', 'exists', 'centos:6'], mock.ANY, False
|
||||
),
|
||||
# inspect and pull missing image centos:7
|
||||
mock.call(
|
||||
['docker', 'inspect', '--type', 'image',
|
||||
'--format', 'exists', 'centos:7'], mock.ANY
|
||||
'--format', 'exists', 'centos:7'], mock.ANY, False
|
||||
),
|
||||
# first pull attempt fails
|
||||
mock.call(
|
||||
|
@ -251,7 +251,7 @@ three-12345678 three''', '', 0),
|
|||
# inspect image centos:7
|
||||
mock.call(
|
||||
['docker', 'inspect', '--type', 'image',
|
||||
'--format', 'exists', 'centos:7'], mock.ANY
|
||||
'--format', 'exists', 'centos:7'], mock.ANY, False
|
||||
),
|
||||
# ps for delete_missing_and_updated container_names
|
||||
mock.call(
|
||||
|
@ -267,12 +267,12 @@ three-12345678 three''', '', 0),
|
|||
# rm two, changed config
|
||||
mock.call(['docker', 'inspect', '--type', 'container',
|
||||
'--format', '{{index .Config.Labels "config_data"}}',
|
||||
'two-12345678'], mock.ANY),
|
||||
'two-12345678'], mock.ANY, False),
|
||||
mock.call(['docker', 'rm', '-f', 'two-12345678'], mock.ANY),
|
||||
# check three, config hasn't changed
|
||||
mock.call(['docker', 'inspect', '--type', 'container',
|
||||
'--format', '{{index .Config.Labels "config_data"}}',
|
||||
'three-12345678'], mock.ANY),
|
||||
'three-12345678'], mock.ANY, False),
|
||||
# ps for after delete_missing_and_updated renames
|
||||
mock.call(
|
||||
['docker', 'ps', '-a',
|
||||
|
@ -376,12 +376,12 @@ three-12345678 three''', '', 0),
|
|||
# inspect existing image centos:6
|
||||
mock.call(
|
||||
['docker', 'inspect', '--type', 'image',
|
||||
'--format', 'exists', 'centos:6'], mock.ANY
|
||||
'--format', 'exists', 'centos:6'], mock.ANY, False
|
||||
),
|
||||
# inspect and pull missing image centos:7
|
||||
mock.call(
|
||||
['docker', 'inspect', '--type', 'image',
|
||||
'--format', 'exists', 'centos:7'], mock.ANY
|
||||
'--format', 'exists', 'centos:7'], mock.ANY, False
|
||||
),
|
||||
mock.call(
|
||||
['docker', 'pull', 'centos:7'], mock.ANY
|
||||
|
|
Loading…
Reference in New Issue