Sandro Bonazzola has uploaded a new change for review. Change subject: sos - refactored engine sos plugin ......................................................................
sos - refactored engine sos plugin engine sos plugin used two flags: vdsmlogs and prefix. Both flags were implemented with behaviors not acceptable by sos developers: - vdsmlogs is not a boolean flag: it was used for specifying a path containing logs collected by sosreport runs on other hosts; if required the path should have been determined without allowing the user to specify a generic path like '/' - prefix is not a boolean flag and was used for changing the name of the report tarball. The name was changed altering the sosreport policy instead of creating a new policy. Both these 2 flag are meaningless if you run sosreport -a -o engine because -a set both the flags to True and because running sosreport you can't collect hypervisors sosreport in vdsmlogs and you want a standard sosreport. I've refactored the engine sos plugin removing both the flags. It's engine-log-collector that will take care to rename the tarball with the desired prefix and it's engine-log-collector that will take care of adding the vdsmlogs to the archive. PREVIOUS: - collect and archive postgres data in a scratch dir - collect and archive hypervisors data in a scratch dir - collect and archive engine data (including the above in /tmp) NOW: - collect engine data - collect and archive postgres data in log-collector-data - collect and archive hypervisors data in log-collector-data - archive all the above in a single tarball. Change-Id: Ib226ec23b98450a03ebd2a64043a911645a62235 Signed-off-by: Sandro Bonazzola <sbona...@redhat.com> --- M src/__main__.py M src/sos/plugins/engine.py 2 files changed, 71 insertions(+), 50 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-log-collector refs/changes/70/13970/1 diff --git a/src/__main__.py b/src/__main__.py index 95177ef..5b1cd8d 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -21,10 +21,10 @@ from optparse import OptionParser, OptionGroup, SUPPRESS_HELP import subprocess import shlex +import shutil import pprint import fnmatch import traceback -import shutil import logging import gettext import getpass @@ -33,6 +33,7 @@ import dateutil.tz as tz import tempfile import atexit +import time from helper import hypervisors from ovirt_log_collector import config @@ -639,12 +640,12 @@ class ENGINEData(CollectorBase): def build_options(self): + """ + returns the parameters for sosreport execution on the local host + running ovirt-engine service. + """ opts = [ "-k rpm.rpmva=off", - "-k engine.vdsmlogs=%s" % self.configuration.get( - "local_scratch_dir" - ), - "-k engine.prefix=on", "-k general.all_logs=True", "-k apache.log=True" ] @@ -677,23 +678,9 @@ "memory", )) self.configuration["sos_options"] = self.build_options() - stdout = self.caller.call( - '/usr/sbin/sosreport --batch --report --tmp-dir=%(local_tmp_dir)s\ - -o %(reports)s %(sos_options)s' - ) - self.parse_sosreport_stdout(stdout) - if os.path.exists(self.configuration["path"]): - archiveSize = '%.1fM' % ( - float(os.path.getsize(self.configuration["path"])) / (1 << 20) - ) - else: - archiveSize = None - - return """Log files have been collected and placed in %s. - The MD5 for this file is %s and its size is %s""" % ( - self.configuration["path"], - self.configuration["checksum"], - archiveSize + self.caller.call( + "sosreport --batch --report --build \ + --tmp-dir='%(local_tmp_dir)s' -o %(reports)s %(sos_options)s" ) @@ -791,6 +778,60 @@ self.conf = configuration if self.conf.command is None: raise Exception("No command specified.") + + def archive(self): + """ + Create a single tarball with collected data from engine, postgresql + and all hypervisors. + """ + print _('Creating compressed archive...') + report_file_ext = 'bz2' + compressor = 'bzip2' + caller = Caller({}) + try: + caller.call('xz --version') + report_file_ext = 'xz' + compressor = 'xz' + except Exception: + logging.debug('xz compression not available') + self.conf["path"] = os.path.join( + tempfile.gettempdir(), + "sosreport-%s-%s.tar.%s" % ( + 'LogCollector', + time.strftime("%Y%m%d%H%M%S"), + report_file_ext + ) + ) + config = { + 'report': os.path.splitext(self.conf['path'])[0], + 'compressed_report': self.conf['path'], + 'compressor': compressor, + 'directory': self.conf["local_tmp_dir"], + } + caller.configuration = config + caller.call("tar -cf '%(report)s' -C '%(directory)s' .") + shutil.rmtree(self.conf["local_tmp_dir"]) + caller.call("%(compressor)s -1 '%(report)s'") + md5_out = caller.call("md5sum '%(compressed_report)s'") + checksum = md5_out.split()[0] + with open("%s.md5" % self.conf["path"], 'w') as checksum_file: + checksum_file.write(md5_out) + + msg = '' + if os.path.exists(self.conf["path"]): + archiveSize = '%.1fM' % ( + float(os.path.getsize(self.conf["path"])) / (1 << 20) + ) + + msg = _( + 'Log files have been collected and placed in {path}.\n' + 'The MD5 for this file is {checksum} and its size is {size}' + ).format( + path=self.conf["path"], + size=archiveSize, + checksum=checksum, + ) + return msg def write_time_diff(self, queue): local_scratch_dir = self.conf.get("local_scratch_dir") @@ -1044,8 +1085,7 @@ "localhost", configuration=self.conf ) - stdout = collector.sosreport() - logging.info(stdout) + collector.sosreport() def parse_password(option, opt_str, value, parser): @@ -1359,12 +1399,11 @@ # We need to make a temporary scratch directory wherein # all of the output from VDSM and PostgreSQL SOS plug-ins - # will be dumped. The contents of this directory will be scooped - # up by the oVirt Engine SOS plug-in via the engine.vdsmlogs option - # and included in a single .xz file. + # will be dumped. The contents of this directory will be included in + # a single .xz or .bz2 file report. conf["local_scratch_dir"] = os.path.join( conf["local_tmp_dir"], - 'RHEVH-and-PostgreSQL-reports' + 'log-collector-data' ) if not os.path.exists(conf["local_scratch_dir"]): os.makedirs(conf["local_scratch_dir"]) @@ -1377,6 +1416,8 @@ The directory is: %s'""" % (conf["local_scratch_dir"])) if conf.command == "collect": + collector.get_engine_data() + collector.get_postgres_data() if not conf.get("no_hypervisor"): if collector.set_hosts(): collector.get_hypervisor_data() @@ -1386,10 +1427,8 @@ hypervisor data will be collected.") else: logging.info("Skipping hypervisor collection...") - - collector.get_postgres_data() - collector.get_engine_data() - + stdout = collector.archive() + logging.info(stdout) elif conf.command == "list": if collector.set_hosts(): collector.list_hosts() @@ -1398,8 +1437,6 @@ "No hypervisors were found, therefore no hypervisor \ data will be listed.") - # Clean up the temp directory - shutil.rmtree(conf["local_scratch_dir"]) except KeyboardInterrupt, k: print "Exiting on user cancel." except Exception, e: diff --git a/src/sos/plugins/engine.py b/src/sos/plugins/engine.py index 9f75ff2..bb92f40 100644 --- a/src/sos/plugins/engine.py +++ b/src/sos/plugins/engine.py @@ -5,16 +5,6 @@ class engine(sos.plugintools.PluginBase): """oVirt related information""" - optionList = [ - ( - "vdsmlogs", - "Directory containing all of the SOS logs from the hypervisor(s)", - "", - False - ), - ("prefix", "Prefix the sosreport archive", "", False) - ] - def setup(self): # Copy engine config files. self.addCopySpec("/etc/ovirt-engine") @@ -24,8 +14,6 @@ self.addCopySpec("/etc/sysconfig/ovirt-engine") self.addCopySpec("/usr/share/ovirt-engine/conf") self.addCopySpec("/var/log/ovirt-guest-agent") - if self.getOption("vdsmlogs"): - self.addCopySpec(self.getOption("vdsmlogs")) def postproc(self): """ @@ -43,7 +31,3 @@ r"Password.type=(.*)", r'Password.type=********' ) - - if self.getOption("prefix"): - current_name = self.policy().reportName - self.policy().reportName = "LogCollector-" + current_name -- To view, visit http://gerrit.ovirt.org/13970 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ib226ec23b98450a03ebd2a64043a911645a62235 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-log-collector Gerrit-Branch: ovirt-log-collector-3.2 Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches