Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Merge "Write ansible log content to a different log file"
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed Dec 23, 2019
2 parents 296be34 + 7adf317 commit 227cd60
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 34 additions & 12 deletions tripleo_common/image/image_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,29 +341,51 @@ def run_modify_playbook(cls, modify_role, modify_vars,
LOG.info('Playbook: \n%s' % yaml.safe_dump(
playbook, default_flow_style=False))
work_dir = tempfile.mkdtemp(prefix='tripleo-modify-image-playbook-')
log_name = 'tripleo-container-image-prepare-ansible.log'
try:
action = ansible.AnsiblePlaybookAction(
for handler in LOG.logger.root.handlers:
if hasattr(handler, 'baseFilename'):
if os.path.isfile(handler.baseFilename):
log_f = os.path.join(
os.path.dirname(handler.baseFilename),
log_name
)
break
else:
raise OSError('Log output is not a file.')
except (AttributeError, OSError):
tmp_dir = tempfile.gettempdir()
log_f = os.path.join(tmp_dir, log_name)
try:
LOG.info('Ansible action starting')
ansible.AnsiblePlaybookAction(
playbook=playbook,
work_dir=work_dir,
verbosity=1,
extra_env_variables=dict(os.environ),
override_ansible_cfg=(
"[defaults]\n"
"stdout_callback=yaml\n"
"log_path=%s\n" % log_f
)
)
result = action.run(None)
log_path = result.get('log_path')
if log_path and os.path.isfile(log_path):
with open(log_path) as f:
for line in f:
LOG.info(line.rstrip())
shutil.rmtree(work_dir)
).run(None)
except processutils.ProcessExecutionError as e:
LOG.error('%s\nError running playbook in directory: %s'
% (e.stdout, work_dir))
LOG.error(
'%s\n'
'Error running playbook in directory: %s\n'
'Playbook log information can be reviewed here: %s' % (
e.stdout,
work_dir,
log_f
)
)
raise ImageUploaderException(
'Modifying image %s failed' % target_image)
'Modifying image %s failed' % target_image
)
else:
LOG.info('Ansible action completed')
finally:
shutil.rmtree(work_dir)

@classmethod
def _images_match(cls, image1, image2, session1=None):
Expand Down
2 changes: 2 additions & 0 deletions tripleo_common/tests/image/test_image_uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ def test_modify_upload_image(self, mock_ansible, mock_exists, mock_copy,
override_ansible_cfg=(
"[defaults]\n"
"stdout_callback=yaml\n"
"log_path=%s/tripleo-container-image-prepare-ansible.log\n"
% os.path.dirname(logfile.name)
)
)

Expand Down

0 comments on commit 227cd60

Please sign in to comment.