diff options
author | francotseng <francotseng18@gmail.com> | 2019-06-28 14:18:28 +0800 |
---|---|---|
committer | francotseng <francotseng18@gmail.com> | 2019-07-01 03:43:02 +0000 |
commit | 6c035399ad12ab9a9c5b1c8d455aea294107e3b4 (patch) | |
tree | f5acf767da6bfa13cb9a81177f4a39600c32ea66 | |
parent | 61396bba54c673257ddc3437de2cd880f5c390e6 (diff) | |
download | osprofiler-6c035399ad12ab9a9c5b1c8d455aea294107e3b4.tar.gz |
The --connection-string is marked required, and parse_args()
assumes the flag invalid if it's not supplied as command line
argument, even if env OSPROFILER_CONNECTION_STRING is setted.
We should not rely on the required=True of argparse module,
but check the required args on our own to take env arguments
into consideration.
Change-Id: I50f5f369ec41ddc82f9b66f5910b7805940fb387
(cherry picked from commit ede0ec402eee45e107c1fde429c3332b3e49f60e)
-rw-r--r-- | osprofiler/cmd/commands.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/osprofiler/cmd/commands.py b/osprofiler/cmd/commands.py index bc3de7e..df92a56 100644 --- a/osprofiler/cmd/commands.py +++ b/osprofiler/cmd/commands.py @@ -36,7 +36,6 @@ class TraceCommands(BaseCommand): @cliutils.arg("trace", help="File with trace or trace id") @cliutils.arg("--connection-string", dest="conn_str", default=(cliutils.env("OSPROFILER_CONNECTION_STRING")), - required=True, help="Storage driver's connection string. Defaults to " "env[OSPROFILER_CONNECTION_STRING] if set") @cliutils.arg("--transport-url", dest="transport_url", @@ -59,6 +58,12 @@ class TraceCommands(BaseCommand): def show(self, args): """Display trace results in HTML, JSON or DOT format.""" + if not args.conn_str: + raise exc.CommandError( + "You must provide connection string via" + " either --connection-string or " + "via env[OSPROFILER_CONNECTION_STRING]") + trace = None if not uuidutils.is_uuid_like(args.trace): @@ -156,7 +161,6 @@ class TraceCommands(BaseCommand): @cliutils.arg("--connection-string", dest="conn_str", default=cliutils.env("OSPROFILER_CONNECTION_STRING"), - required=True, help="Storage driver's connection string. Defaults to " "env[OSPROFILER_CONNECTION_STRING] if set") @cliutils.arg("--error-trace", dest="error_trace", @@ -164,6 +168,11 @@ class TraceCommands(BaseCommand): help="List all traces that contain error.") def list(self, args): """List all traces""" + if not args.conn_str: + raise exc.CommandError( + "You must provide connection string via" + " either --connection-string or " + "via env[OSPROFILER_CONNECTION_STRING]") try: engine = base.get_driver(args.conn_str, **args.__dict__) except Exception as e: |