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
This commit is contained in:
parent
512df9f390
commit
d969430747
|
@ -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)
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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'),
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
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()
|
Loading…
Reference in New Issue