summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-08-17 01:54:22 +0000
committerGerrit Code Review <review@openstack.org>2022-08-17 01:54:22 +0000
commit6d0d04560cb440015ec7357eb3dde09fd12dd739 (patch)
tree20d6ce2b02899d87e9c1cde444d515270d02be59
parentec11ee916265b4cf80685c81a3c589fcadedaf18 (diff)
parentf8677cddb9dd397081acc30c47128b83b4061ae1 (diff)
downloadzuul-6d0d04560cb440015ec7357eb3dde09fd12dd739.tar.gz
Merge "zuul-stream : don't write out logfile for tasks in loops"
-rwxr-xr-xzuul/ansible/2.8/library/command.py10
-rwxr-xr-xzuul/ansible/2.9/library/command.py10
-rw-r--r--zuul/ansible/base/action/command.py28
-rwxr-xr-xzuul/ansible/base/library/command.py10
4 files changed, 44 insertions, 14 deletions
diff --git a/zuul/ansible/2.8/library/command.py b/zuul/ansible/2.8/library/command.py
index 26830e4a7..5f7f31947 100755
--- a/zuul/ansible/2.8/library/command.py
+++ b/zuul/ansible/2.8/library/command.py
@@ -168,7 +168,15 @@ _log_lines = []
class Console(object):
def __init__(self, log_uuid):
- self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
+ # The streamer currently will not ask us for output from
+ # loops. This flag uuid was set in the action plugin if this
+ # call was part of a loop. This avoids us leaving behind
+ # files that will never be read, but also means no other
+ # special-casing for any of this path.
+ if log_uuid == 'in-loop-ignore':
+ self.logfile_name = os.devnull
+ else:
+ self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
def __enter__(self):
self.logfile = open(self.logfile_name, 'ab', buffering=0)
diff --git a/zuul/ansible/2.9/library/command.py b/zuul/ansible/2.9/library/command.py
index 26830e4a7..5f7f31947 100755
--- a/zuul/ansible/2.9/library/command.py
+++ b/zuul/ansible/2.9/library/command.py
@@ -168,7 +168,15 @@ _log_lines = []
class Console(object):
def __init__(self, log_uuid):
- self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
+ # The streamer currently will not ask us for output from
+ # loops. This flag uuid was set in the action plugin if this
+ # call was part of a loop. This avoids us leaving behind
+ # files that will never be read, but also means no other
+ # special-casing for any of this path.
+ if log_uuid == 'in-loop-ignore':
+ self.logfile_name = os.devnull
+ else:
+ self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
def __enter__(self):
self.logfile = open(self.logfile_name, 'ab', buffering=0)
diff --git a/zuul/ansible/base/action/command.py b/zuul/ansible/base/action/command.py
index f36da86f6..3bb88d8e5 100644
--- a/zuul/ansible/base/action/command.py
+++ b/zuul/ansible/base/action/command.py
@@ -25,15 +25,21 @@ class ActionModule(command.ActionModule):
if self._task.action in (
'command', 'shell',
'ansible.builtin.command', 'ansible.builtin.shell'):
- # Get a unique key for ZUUL_LOG_ID_MAP. ZUUL_LOG_ID_MAP
- # is read-only since we are forked. Use it to add a
- # counter to the log id so that if we run the same task
- # more than once, we get a unique log file. See comments
- # in paths.py for details.
- log_host = paths._sanitize_filename(
- task_vars.get('inventory_hostname'))
- key = "%s-%s" % (self._task._uuid, log_host)
- count = paths.ZUUL_LOG_ID_MAP.get(key, 0)
- self._task.args['zuul_log_id'] = "%s-%s-%s" % (
- self._task._uuid, count, log_host)
+ # This is a bit lame, but we do not log loops in the
+ # zuul_stream.py callback. This allows us to not write
+ # out command.py output to files that will never be read.
+ if 'ansible_loop_var' in task_vars:
+ self._task.args['zuul_log_id'] = 'in-loop-ignore'
+ else:
+ # Get a unique key for ZUUL_LOG_ID_MAP. ZUUL_LOG_ID_MAP
+ # is read-only since we are forked. Use it to add a
+ # counter to the log id so that if we run the same task
+ # more than once, we get a unique log file. See comments
+ # in paths.py for details.
+ log_host = paths._sanitize_filename(
+ task_vars.get('inventory_hostname'))
+ key = "%s-%s" % (self._task._uuid, log_host)
+ count = paths.ZUUL_LOG_ID_MAP.get(key, 0)
+ self._task.args['zuul_log_id'] = "%s-%s-%s" % (
+ self._task._uuid, count, log_host)
return super(ActionModule, self).run(tmp, task_vars)
diff --git a/zuul/ansible/base/library/command.py b/zuul/ansible/base/library/command.py
index d496b037c..3c22849ae 100755
--- a/zuul/ansible/base/library/command.py
+++ b/zuul/ansible/base/library/command.py
@@ -263,7 +263,15 @@ _log_lines = []
class Console(object):
def __init__(self, log_uuid):
- self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
+ # The streamer currently will not ask us for output from
+ # loops. This flag uuid was set in the action plugin if this
+ # call was part of a loop. This avoids us leaving behind
+ # files that will never be read, but also means no other
+ # special-casing for any of this path.
+ if log_uuid == 'in-loop-ignore':
+ self.logfile_name = os.devnull
+ else:
+ self.logfile_name = LOG_STREAM_FILE.format(log_uuid=log_uuid)
def __enter__(self):
self.logfile = open(self.logfile_name, 'ab', buffering=0)