Fix cli arguments backward compatibility
Change-Id: I36760e9b466c519690c6773545e1c9764afc2a7d
This commit is contained in:
parent
cae77b17da
commit
c8d5425434
@ -103,6 +103,18 @@ def args(*args, **kwargs):
|
||||
return _decorator
|
||||
|
||||
|
||||
def deprecated_args(*args, **kwargs):
|
||||
def _decorator(func):
|
||||
func.__dict__.setdefault("args", []).insert(0, (args, kwargs))
|
||||
func.__dict__.setdefault("deprecated_args", [])
|
||||
func.deprecated_args.append(args[0])
|
||||
if "help" in kwargs.keys():
|
||||
warn_message = "DEPRECATED!"
|
||||
kwargs["help"] = " ".join([warn_message, kwargs["help"]])
|
||||
return func
|
||||
return _decorator
|
||||
|
||||
|
||||
def _methods_of(cls):
|
||||
"""Get all callable methods of a class that don't start with underscore.
|
||||
|
||||
@ -193,12 +205,22 @@ def _add_command_parsers(categories, subparsers):
|
||||
parser.add_argument('action_args', nargs='*')
|
||||
|
||||
|
||||
def validate_deprecated_args(argv, fn):
|
||||
if len(argv) > 3 and argv[2] == fn.func_name and not getattr(
|
||||
fn, "deprecated_args", []) == list():
|
||||
for item in fn.deprecated_args:
|
||||
if item in argv[3:]:
|
||||
LOG.warning("Deprecated argument %s for %s." % (item,
|
||||
fn.func_name))
|
||||
|
||||
|
||||
def run(argv, categories):
|
||||
parser = lambda subparsers: _add_command_parsers(categories, subparsers)
|
||||
category_opt = cfg.SubCommandOpt('category',
|
||||
title='Command categories',
|
||||
help='Available categories',
|
||||
handler=parser)
|
||||
|
||||
CONF.register_cli_opt(category_opt)
|
||||
|
||||
try:
|
||||
@ -266,9 +288,12 @@ def run(argv, categories):
|
||||
print(" " + arg[0][0])
|
||||
break
|
||||
return(1)
|
||||
|
||||
try:
|
||||
utils.load_plugins("/opt/rally/plugins/")
|
||||
utils.load_plugins(os.path.expanduser("~/.rally/plugins/"))
|
||||
|
||||
validate_deprecated_args(argv, fn)
|
||||
ret = fn(*fn_args, **fn_kwargs)
|
||||
return(ret)
|
||||
except IOError as e:
|
||||
@ -327,7 +352,15 @@ complete -F _rally rally
|
||||
completion = ""
|
||||
for category, cmds in main.categories.items():
|
||||
for name, command in _methods_of(cmds):
|
||||
args = ' '.join(arg[0][0] for arg in getattr(command, 'args', []))
|
||||
args_list = list()
|
||||
for arg in getattr(command, "args", []):
|
||||
if getattr(command, "deprecated_args", []):
|
||||
if arg[0][0] not in command.deprecated_args:
|
||||
args_list.append(arg[0][0])
|
||||
else:
|
||||
args_list.append(arg[0][0])
|
||||
args = " ".join(args_list)
|
||||
|
||||
completion += """ OPTS["{cat}_{cmd}"]="{args}"\n""".format(
|
||||
cat=category, cmd=name, args=args)
|
||||
return bash_data % {"data": completion}
|
||||
|
@ -125,6 +125,9 @@ class DeploymentCommands(object):
|
||||
if do_use:
|
||||
use.UseCommands().deployment(deployment['uuid'])
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment.')
|
||||
@envutils.with_default_deployment
|
||||
@ -138,6 +141,9 @@ class DeploymentCommands(object):
|
||||
"""
|
||||
api.recreate_deploy(deployment)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment.')
|
||||
@envutils.with_default_deployment
|
||||
@ -173,6 +179,9 @@ class DeploymentCommands(object):
|
||||
"To create a new deployment, use:"
|
||||
"\nrally deployment create"))
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment.')
|
||||
@envutils.with_default_deployment
|
||||
@ -188,6 +197,9 @@ class DeploymentCommands(object):
|
||||
result = deploy["config"]
|
||||
print(json.dumps(result, sort_keys=True, indent=4))
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment.')
|
||||
@envutils.with_default_deployment
|
||||
@ -211,6 +223,9 @@ class DeploymentCommands(object):
|
||||
table_rows.append(utils.Struct(**dict(zip(headers, data))))
|
||||
common_cliutils.print_list(table_rows, headers)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment.')
|
||||
@envutils.with_default_deployment
|
||||
|
@ -42,6 +42,9 @@ class ShowCommands(object):
|
||||
|
||||
return admin + deployment.get("users", [])
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment')
|
||||
@envutils.with_default_deployment
|
||||
@ -76,6 +79,9 @@ class ShowCommands(object):
|
||||
print(_("Authentication Issues: %s") % e)
|
||||
return(1)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment')
|
||||
@envutils.with_default_deployment
|
||||
@ -110,6 +116,9 @@ class ShowCommands(object):
|
||||
print(_("Authentication Issues: %s") % e)
|
||||
return(1)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment')
|
||||
@envutils.with_default_deployment
|
||||
@ -134,6 +143,9 @@ class ShowCommands(object):
|
||||
print(_("Authentication Issues: %s") % e)
|
||||
return(1)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment')
|
||||
@envutils.with_default_deployment
|
||||
@ -161,6 +173,9 @@ class ShowCommands(object):
|
||||
print(_("Authentication Issues: %s") % e)
|
||||
return(1)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', dest='deployment', type=str,
|
||||
required=False, help='UUID or name of a deployment')
|
||||
@envutils.with_default_deployment
|
||||
|
@ -44,6 +44,9 @@ class TaskCommands(object):
|
||||
Set of commands that allow you to manage benchmarking tasks and results.
|
||||
"""
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', type=str, dest='deployment',
|
||||
required=False, help='UUID or name of the deployment')
|
||||
@cliutils.args('--task', '--filename',
|
||||
@ -69,6 +72,9 @@ class TaskCommands(object):
|
||||
print("Task config is invalid: \n")
|
||||
print(e)
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args('--deployment', type=str, dest='deployment',
|
||||
required=False, help='UUID or name of the deployment')
|
||||
@cliutils.args('--task', '--filename',
|
||||
|
@ -55,6 +55,12 @@ class UseCommands(object):
|
||||
if not os.path.exists(os.path.expanduser('~/.rally/')):
|
||||
os.makedirs(os.path.expanduser('~/.rally/'))
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--uuid", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.deprecated_args(
|
||||
"--name", dest="deployment", type=str,
|
||||
required=False, help="Name of the deployment.")
|
||||
@cliutils.args('--deployment', type=str, dest='deployment',
|
||||
help='UUID or name of the deployment')
|
||||
def deployment(self, deployment=None):
|
||||
|
@ -42,6 +42,9 @@ class VerifyCommands(object):
|
||||
OpenStack live cloud.
|
||||
"""
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args("--deployment", dest="deployment", type=str,
|
||||
required=False, help="UUID or name of a deployment.")
|
||||
@cliutils.args("--set", dest="set_name", type=str, required=False,
|
||||
|
@ -37,6 +37,9 @@ class DBCommands(object):
|
||||
class TempestCommands(object):
|
||||
"""Commands for Tempest management."""
|
||||
|
||||
@cliutils.deprecated_args(
|
||||
"--deploy-id", dest="deployment", type=str,
|
||||
required=False, help="UUID of the deployment.")
|
||||
@cliutils.args("--deployment", type=str, dest="deployment",
|
||||
required=False, help="UUID or name of the deployment")
|
||||
@envutils.with_default_deployment
|
||||
|
Loading…
Reference in New Issue
Block a user