From e05e6bdf13feed14c286a3385c5a0c67a76f684b Mon Sep 17 00:00:00 2001 From: Bogdan Dobrelya Date: Fri, 20 Nov 2020 12:00:21 +0100 Subject: [PATCH] TCIB: Fix debug mode for oslo process execute When pushing with buildah, there is no logfile options. It dumps results of work to stderr. In debug mode, we want those results logged. But we do not reconfigure oslo.log defaults, so it skips all details as it goes with INFO config instead. Capture debug results of process execution utility for buildah push and use the current logging context as well. Also oslo process utils will log the time it took to do buildah bud builds as a nice free bonus. Change-Id: I5177408258b6d33daa26239e7b5c4f017b9372cf Signed-off-by: Bogdan Dobrelya --- tripleo_common/image/builder/buildah.py | 12 +++++++++++- tripleo_common/utils/process.py | 9 +++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tripleo_common/image/builder/buildah.py b/tripleo_common/image/builder/buildah.py index d921e9f9e..74dab545a 100644 --- a/tripleo_common/image/builder/buildah.py +++ b/tripleo_common/image/builder/buildah.py @@ -67,6 +67,8 @@ class BuildahBuilder(base.BaseBuilder): """ logging.register_options(CONF) + if debug: + CONF.debug = True logging.setup(CONF, '') super(BuildahBuilder, self).__init__() @@ -212,7 +214,15 @@ class BuildahBuilder(base.BaseBuilder): 'docker://' + destination] self.log.info("Pushing %s image with: %s" % (destination, ' '.join(args))) - process.execute(*args, run_as_root=False, use_standard_locale=True) + if self.debug: + # buildah push logs to stderr, since there is no --log* opt + # so we'll use the current logging context for that + process.execute(*args, log_stdout=True, run_as_root=False, + use_standard_locale=True, logger=self.log, + loglevel=logging.DEBUG) + else: + process.execute(*args, run_as_root=False, + use_standard_locale=True) def build_all(self, deps=None): """Build all containers. diff --git a/tripleo_common/utils/process.py b/tripleo_common/utils/process.py index 3087340d6..f6600ce3f 100644 --- a/tripleo_common/utils/process.py +++ b/tripleo_common/utils/process.py @@ -43,6 +43,7 @@ def execute(*cmd, **kwargs): :raises: OSError """ + logger = kwargs.pop('logger', LOG) use_standard_locale = kwargs.pop('use_standard_locale', False) if use_standard_locale: env = kwargs.pop('env_variables', os.environ.copy()) @@ -50,9 +51,9 @@ def execute(*cmd, **kwargs): kwargs['env_variables'] = env log_stdout = kwargs.pop('log_stdout', True) result = processutils.execute(*cmd, **kwargs) - LOG.debug('Execution completed, command line is "%s"', - ' '.join(map(str, cmd))) + logger.debug('Execution completed, command line is "%s"', + ' '.join(map(str, cmd))) if log_stdout: - LOG.debug('Command stdout is: "%s"', result[0]) - LOG.debug('Command stderr is: "%s"', result[1]) + logger.debug('Command stdout is: "%s"', result[0]) + logger.debug('Command stderr is: "%s"', result[1]) return result