From d969430747da364f96bc1014c914d4ce0cd353b3 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Wed, 22 Feb 2017 23:33:09 -0500 Subject: [PATCH] Minor cleanups in on-node logging We don't need zuul_log anymore. People can write ansible themselves, which means they can write debug statements, which will go into the collected log. Also, put the port and the filename into constants so that they don't seem like magic numbers as much. Change-Id: I8020cc3e841617366831e80fe92fc477452d6da2 --- zuul/ansible/callback/zuul_stream.py | 4 +- zuul/ansible/library/command.py | 3 +- zuul/ansible/library/zuul_console.py | 9 +++-- zuul/ansible/library/zuul_log.py | 58 ---------------------------- 4 files changed, 11 insertions(+), 63 deletions(-) delete mode 100644 zuul/ansible/library/zuul_log.py diff --git a/zuul/ansible/callback/zuul_stream.py b/zuul/ansible/callback/zuul_stream.py index 8f9bcd27d7..9b8bccd022 100644 --- a/zuul/ansible/callback/zuul_stream.py +++ b/zuul/ansible/callback/zuul_stream.py @@ -20,6 +20,8 @@ import time from ansible.plugins.callback import default +LOG_STREAM_PORT = 19885 + def linesplit(socket): buff = socket.recv(4096) @@ -62,7 +64,7 @@ class CallbackModule(default.CallbackModule): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) while True: try: - s.connect((ip, 19885)) + s.connect((ip, LOG_STREAM_PORT)) except Exception: self._display.display("[%s] Waiting on logger" % host) time.sleep(0.1) diff --git a/zuul/ansible/library/command.py b/zuul/ansible/library/command.py index 639032257c..328ae7b323 100644 --- a/zuul/ansible/library/command.py +++ b/zuul/ansible/library/command.py @@ -121,12 +121,13 @@ from ansible.module_utils.basic import get_exception from ast import literal_eval +LOG_STREAM_FILE = '/tmp/console.log' PASSWD_ARG_RE = re.compile(r'^[-]{0,2}pass[-]?(word|wd)?') class Console(object): def __enter__(self): - self.logfile = open('/tmp/console.html', 'a', 0) + self.logfile = open(LOG_STREAM_FILE, 'a', 0) return self def __exit__(self, etype, value, tb): diff --git a/zuul/ansible/library/zuul_console.py b/zuul/ansible/library/zuul_console.py index e70dac8e4d..5d1333f705 100644 --- a/zuul/ansible/library/zuul_console.py +++ b/zuul/ansible/library/zuul_console.py @@ -20,6 +20,9 @@ import sys import socket import threading +LOG_STREAM_FILE = '/tmp/console.log' +LOG_STREAM_PORT = 19885 + def daemonize(): # A really basic daemonize method that should work well enough for @@ -155,15 +158,15 @@ class Server(object): def test(): - s = Server('/tmp/console.html', 19885) + s = Server(LOG_STREAM_PATH, LOG_STREAM_PORT) s.run() def main(): module = AnsibleModule( argument_spec=dict( - path=dict(default='/tmp/console.html'), - port=dict(default=19885, type='int'), + path=dict(default=LOG_STREAM_PATH), + port=dict(default=LOG_STREAM_PORT, type='int'), ) ) diff --git a/zuul/ansible/library/zuul_log.py b/zuul/ansible/library/zuul_log.py deleted file mode 100644 index 4b377d9079..0000000000 --- a/zuul/ansible/library/zuul_log.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/python - -# Copyright (c) 2016 IBM Corp. -# Copyright (c) 2016 Red Hat -# -# This module is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This software is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this software. If not, see . - -import datetime - - -class Console(object): - def __enter__(self): - self.logfile = open('/tmp/console.html', 'a', 0) - return self - - def __exit__(self, etype, value, tb): - self.logfile.close() - - def addLine(self, ln): - ts = datetime.datetime.now() - outln = '%s | %s' % (str(ts), ln) - self.logfile.write(outln) - - -def log(msg): - if not isinstance(msg, list): - msg = [msg] - with Console() as console: - for line in msg: - console.addLine("[Zuul] %s\n" % line) - - -def main(): - module = AnsibleModule( - argument_spec=dict( - msg=dict(required=True, type='raw'), - ) - ) - - p = module.params - log(p['msg']) - module.exit_json(changed=True) - -from ansible.module_utils.basic import * # noqa - -if __name__ == '__main__': - main()