From 8532e9c47939b872df8cb78f09b49ac5a57b62fd Mon Sep 17 00:00:00 2001 From: Martin Schuppert Date: Thu, 16 Mar 2017 08:58:07 +0100 Subject: [gnocchi] add_cmd_output block to be run only when ENVs set add_cmd_output now gets only called if the needed ENV variables are set to be able to connect to an OpenStack env. Resolves: #956. Signed-off-by: Martin Schuppert Signed-off-by: Bryn M. Reeves --- sos/plugins/gnocchi.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/sos/plugins/gnocchi.py b/sos/plugins/gnocchi.py index a29164b8..a386e789 100644 --- a/sos/plugins/gnocchi.py +++ b/sos/plugins/gnocchi.py @@ -1,4 +1,5 @@ # Copyright (C) 2016 Red Hat, Inc., Sachin Patil +# Copyright (C) 2017 Red Hat, Inc., Martin Schuppert # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,20 +44,21 @@ class GnocchiPlugin(Plugin, RedHatPlugin): self.add_copy_spec_limit("/var/log/gnocchi/*.log", sizelimit=self.limit) - for os_var in ['OS_USERNAME', 'OS_PASSWORD', 'OS_TENANT_NAME']: - if os_var not in os.environ: - self.soslog.warning("%s not found in environment variables" - " which is required to run gnocchi" - " commands" % (os_var)) - - self.add_cmd_output([ - "gnocchi --version", - "gnocchi status", - "gnocchi capabilities list", - "gnocchi archive-policy list", - "gnocchi resource list", - "gnocchi resource-type list" - ]) + vars = [p in os.environ for p in [ + 'OS_USERNAME', 'OS_PASSWORD', 'OS_TENANT_NAME']] + if not all(vars): + self.soslog.warning("Not all environment variables set. Source " + "the environment file for the user intended " + "to connect to the OpenStack environment.") + else: + self.add_cmd_output([ + "gnocchi --version", + "gnocchi status", + "gnocchi capabilities list", + "gnocchi archive-policy list", + "gnocchi resource list", + "gnocchi resource-type list" + ]) def postproc(self): self.do_file_sub( -- cgit