From 6437a9a2ba1b73df486b38be13c9e2401d719ee8 Mon Sep 17 00:00:00 2001 From: Jorge Niedbalski R Date: Thu, 14 Aug 2014 14:42:16 -0400 Subject: [juju] Adds 'juju get' output, exposes export-mongodb This commit extends the plugin to include the resulting 'juju get ${service}' for each deployed service, also it exposes the export-mongodb option, which includes on the report a json file containing each data collection used by juju-core. Signed-off-by: Jorge Niedbalski R Signed-off-by: Adam Stokes --- sos/plugins/juju.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sos/sosreport.py | 2 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/sos/plugins/juju.py b/sos/plugins/juju.py index cbaa6614..c30efe91 100644 --- a/sos/plugins/juju.py +++ b/sos/plugins/juju.py @@ -15,6 +15,25 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. from sos.plugins import Plugin, UbuntuPlugin +from json import loads as json_load + + +def ensure_service_is_running(service): + def wrapper(callback): + def wrapped_f(self, *args, **kwargs): + try: + result = self.call_ext_prog("service {0} stop".format(service)) + if result["status"] != 0: + raise Exception("Cannot stop {0} service".format(service)) + callback(self, *args, **kwargs) + except Exception as ex: + self._log_error("Cannot stop {0}, exception: {1}".format( + service, + ex.message)) + finally: + self.call_ext_prog("service {0} start".format(service)) + return wrapped_f + return wrapper class Juju(Plugin, UbuntuPlugin): @@ -23,6 +42,33 @@ class Juju(Plugin, UbuntuPlugin): plugin_name = 'juju' + option_list = [ + ('export-mongodb', + 'Export mongodb collections as json files', '', False), + ] + + def get_deployed_services(self): + cmd = "juju status --format json" + return json_load( + self.call_ext_prog(cmd)['output'])['services'].keys() + + @ensure_service_is_running("juju-db") + def export_mongodb(self): + collections = ( + "relations", + "environments", + "linkednetworks", + "system", + "settings", + ) + + for collection in collections: + self.add_cmd_output( + "/usr/lib/juju/bin/mongoexport --ssl \ + --dbpath=/var/lib/juju/db --db juju --collection {0} \ + --jsonArray".format(collection), + suggest_filename="{}.json".format(collection)) + def setup(self): self.add_copy_specs([ "/var/log/juju", @@ -34,4 +80,11 @@ class Juju(Plugin, UbuntuPlugin): "juju -v get-constraints" ]) + for service in self.get_deployed_services(): + self.add_cmd_output("juju get {}".format(service)) + + if self.get_option("export-mongodb"): + self.export_mongodb() + + # vim: et ts=4 sw=4 diff --git a/sos/sosreport.py b/sos/sosreport.py index a093712c..d5f355d4 100644 --- a/sos/sosreport.py +++ b/sos/sosreport.py @@ -901,7 +901,7 @@ class SoSReport(object): self.opts.enableplugins): plugin_name = plugin.split(".")[0] if plugin_name not in self.plugin_names: - self.soslog.fatal('a non-existing plugin (%s) was specified' + self.soslog.fatal('a non-existing plugin (%s) was specified ' 'in the command line' % (plugin_name)) self._exit(1) -- cgit