From 10f101d7d0f3be5d54f66455a8d1637057ac5332 Mon Sep 17 00:00:00 2001 From: Matt Dietz Date: Wed, 19 Nov 2014 18:47:47 +0000 Subject: [PATCH] Bug fix for --config-file in redis_sg_tool The redis SG tool was incorrectly handling the --config-file option. This patch amends it correctly pass the argument to oslo.config --- bin/redis_sg_tool | 60 ++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/bin/redis_sg_tool b/bin/redis_sg_tool index 4dcf56a..96f79bb 100755 --- a/bin/redis_sg_tool +++ b/bin/redis_sg_tool @@ -16,20 +16,26 @@ """Quark Redis Security Groups CLI tool. -Usage: redis_sg_tool [-h] [--config-file PATH] +Usage: redis_sg_tool [-h] [--config-file=PATH] [--retries=] + [--retry-delay=] [--yarly] + +Options: + -h --help Show this screen. + --version Show version. + --config-file=PATH Use a different config file path + --retries= Number of times to re-attempt some operations + --retry-delay= Amount of time to wait between retries + +Available commands are: redis_sg_tool test-connection redis_sg_tool vifs-in-redis redis_sg_tool num-groups redis_sg_tool ports-with-groups - redis_sg_tool purge-orphans [--yarly] [--retries=] - [--retry-delay=] - redis_sg_tool write-groups [--yarly] [--retries=] - [--retry-delay=] + redis_sg_tool purge-orphans [--yarly] + redis_sg_tool write-groups [--yarly] + redis_sg_tool -h | --help + redis_sg_tool --version -Options: - -h --help Show this screen. - --version Show version. - --config-file PATH Use a different config file path """ VERSION = 0.1 @@ -53,17 +59,22 @@ from quark.security_groups import redis_client class QuarkRedisTool(object): def __init__(self, arguments): self._args = arguments + self._retries = RETRIES self._retry_delay = RETRY_DELAY - if self._args["--retries"]: + + if self._args.get("--retries"): self._retries = int(self._args["--retries"]) - if self._args["--retry-delay"]: + if self._args.get("--retry-delay"): self._retry_delay = int(self._args["--retry-delay"]) config_args = [] - if self._args["--config-file"]: - config_args.append(self._args["--config-file"]) + if self._args.get("--config-file"): + config_args.append("--config-file=%s" % + self._args.pop("--config-file")) + + self._dryrun = not self._args.get("--yarly") config.init(config_args) if not cfg.CONF.config_file: @@ -72,24 +83,19 @@ class QuarkRedisTool(object): "/etc/) and the '--config-file' option!")) def dispatch(self): - if self._args["test-connection"]: + command = self._args.get("") + if command == "test-connection": self.test_connection() - elif self._args["vifs-in-redis"]: + elif command == "vifs-in-redis": self.vif_count() - elif self._args["num-groups"]: + elif command == "num-groups": self.num_groups() - elif self._args["ports-with-groups"]: + elif command == "ports-with-groups": self.ports_with_groups() - elif self._args["purge-orphans"]: - dryrun = True - if "--yarly" in self._args and self._args["--yarly"]: - dryrun = False - self.purge_orphans(dryrun) - elif self._args["write-groups"]: - dryrun = True - if "--yarly" in self._args and self._args["--yarly"]: - dryrun = False - self.write_groups(dryrun) + elif command == "purge-orphans": + self.purge_orphans(self._dryrun) + elif command == "write-groups": + self.write_groups(self._dryrun) else: print ("Redis security groups tool. Re-run with -h/--help for " "options")