From aac4a4d145f5ca66cc911b66b4966156829223a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=A1gr?= Date: Mon, 25 Jul 2016 16:25:06 +0200 Subject: [PATCH] Fixed oschecks-check_keystone_api When oschecks-check_keystone_api is run without additional parameters (when credentials are passed via env variables) the check generates false alert. This patch makes this usecase possible. Change-Id: I173aaa789e3c43887286574b50b550dfed9a99cd --- monitoring-for-openstack/oschecks/keystone.py | 9 ++++---- monitoring-for-openstack/oschecks/utils.py | 21 ++++++++++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/monitoring-for-openstack/oschecks/keystone.py b/monitoring-for-openstack/oschecks/keystone.py index 370ca73..2a39d18 100644 --- a/monitoring-for-openstack/oschecks/keystone.py +++ b/monitoring-for-openstack/oschecks/keystone.py @@ -25,11 +25,12 @@ def _check_keystone_api(): keystone = utils.Keystone() def check_token(): - return keystone.run().strip() + return keystone.run() - elapsed, token = utils.timeit(check_token) - if not token: - utils.critical("Unable to get a token") + elapsed, result = utils.timeit(check_token) + rc, out = result + if rc: + utils.critical("Unable to get a token:\n{0}".format(out)) if elapsed > 10: utils.warning("Got a token after 10 seconds, it's too long." diff --git a/monitoring-for-openstack/oschecks/utils.py b/monitoring-for-openstack/oschecks/utils.py index 09273db..63b0062 100755 --- a/monitoring-for-openstack/oschecks/utils.py +++ b/monitoring-for-openstack/oschecks/utils.py @@ -260,12 +260,19 @@ class Keystone(object): def run(self): - vformat = ['-f', 'value', '-c', 'id'] command = ['token', 'issue'] - vempty = '' - if 'help' in sys.argv or '--help' in sys.argv or '-h' in sys.argv or len(sys.argv[1:]) == 0: - self.shell.run(command) - return vempty + vformat = ['-f', 'value', '-c', 'id'] + if 'help' in sys.argv or '--help' in sys.argv or '-h' in sys.argv: + rc = self.shell.run(command) else: - self.cmd = self.shell.run(sys.argv[1:] + command + vformat) - return self.shell.stdout.getvalue() or vempty + cmd_arg = sys.argv[1:] + # removes parameters used in vformat + for opt in ['-f', '-c']: + if opt in cmd_arg: + index = cmd_arg.index(opt) + if len(cmd_arg) > (index + 1): + for i in range(2): + cmd_arg.pop(index) + rc = self.shell.run(command + cmd_arg + vformat) + out = self.shell.stdout.getvalue() + return rc, out