rpc.py: add framework for detecting deprecated aliases
This will get used in upcoming patches that actually create RPC aliases. Thanks to Ben Walker for help on the deprecated_alias helper. Signed-off-by: Jim Harris <james.r.harris@intel.com> Change-Id: Ica4432888b1ecb9bd234690758f67ef82794c50a Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/453035 Reviewed-by: Ben Walker <benjamin.walker@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
parent
dcb8ba7b8e
commit
c2b5a3f6b4
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
from rpc.client import print_dict, JSONRPCException
|
||||
from rpc.helpers import deprecated_aliases
|
||||
|
||||
import logging
|
||||
import argparse
|
||||
@ -33,7 +34,7 @@ if __name__ == "__main__":
|
||||
help='Set verbose mode to INFO', default="ERROR")
|
||||
parser.add_argument('--verbose', dest='verbose', choices=['DEBUG', 'INFO', 'ERROR'],
|
||||
help="""Set verbose level. """)
|
||||
subparsers = parser.add_subparsers(help='RPC methods')
|
||||
subparsers = parser.add_subparsers(help='RPC methods', dest='called_rpc_name')
|
||||
|
||||
def start_subsystem_init(args):
|
||||
rpc.start_subsystem_init(args.client)
|
||||
@ -1793,9 +1794,14 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
|
||||
p.add_argument('-n', '--max', help="""Maximum number of notifications to return in response""", type=int)
|
||||
p.set_defaults(func=get_notifications)
|
||||
|
||||
def check_called_name(name):
|
||||
if name in deprecated_aliases:
|
||||
print("{} is deprecated, use {} instead.".format(name, deprecated_aliases[name]), file=sys.stderr)
|
||||
|
||||
def call_rpc_func(args):
|
||||
try:
|
||||
args.func(args)
|
||||
check_called_name(args.called_rpc_name)
|
||||
except JSONRPCException as ex:
|
||||
print("Exception:")
|
||||
print(ex.message)
|
||||
|
16
scripts/rpc/helpers.py
Normal file
16
scripts/rpc/helpers.py
Normal file
@ -0,0 +1,16 @@
|
||||
import sys
|
||||
|
||||
deprecated_aliases = {}
|
||||
|
||||
|
||||
def deprecated_alias(old_name):
|
||||
def wrap(f):
|
||||
def old_f(*args, **kwargs):
|
||||
ret = f(*args, **kwargs)
|
||||
print("{} is deprecated, use {} instead.".format(old_name, f.__name__), file=sys.stderr)
|
||||
return ret
|
||||
old_f.__name__ = old_name
|
||||
deprecated_aliases[old_name] = f.__name__
|
||||
setattr(sys.modules[f.__module__], old_name, old_f)
|
||||
return f
|
||||
return wrap
|
Loading…
x
Reference in New Issue
Block a user