From 4a534344ee0307ce6e3ee425bcf0a95c2f4a9df4 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 21 May 2018 13:07:12 -0700 Subject: [PATCH] scripts/rpc.py: pass named args to app.py Also add docstrings to all app.py methods. Change-Id: Ib234014630e8b47c55f8d96bede509952fe653c5 Signed-off-by: Daniel Verkamp Reviewed-on: https://review.gerrithub.io/411940 Tested-by: SPDK Automated Test System Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- scripts/rpc.py | 11 +++++++++-- scripts/rpc/app.py | 25 ++++++++++++++++++------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/scripts/rpc.py b/scripts/rpc.py index 2749e2968..fe59e588c 100755 --- a/scripts/rpc.py +++ b/scripts/rpc.py @@ -78,7 +78,8 @@ if __name__ == "__main__": # app @call_cmd def kill_instance(args): - rpc.app.kill_instance(args.client, args) + rpc.app.kill_instance(args.client, + sig_name=args.sig_name) p = subparsers.add_parser('kill_instance', help='Send signal to instance') p.add_argument('sig_name', help='signal will be sent to server.') @@ -86,7 +87,13 @@ if __name__ == "__main__": @call_cmd def context_switch_monitor(args): - print_dict(rpc.app.context_switch_monitor(args.client, args)) + enabled = None + if args.enable: + enabled = True + if args.disable: + enabled = False + print_dict(rpc.app.context_switch_monitor(args.client, + enabled=enabled)) p = subparsers.add_parser('context_switch_monitor', help='Control whether the context switch monitor is enabled') p.add_argument('-e', '--enable', action='store_true', help='Enable context switch monitoring') diff --git a/scripts/rpc/app.py b/scripts/rpc/app.py index bc510db10..c9b088f83 100755 --- a/scripts/rpc/app.py +++ b/scripts/rpc/app.py @@ -1,12 +1,23 @@ -def kill_instance(client, args): - params = {'sig_name': args.sig_name} +def kill_instance(client, sig_name): + """Send a signal to the SPDK process. + + Args: + sig_name: signal to send ("SIGINT", "SIGTERM", "SIGQUIT", "SIGHUP", or "SIGKILL") + """ + params = {'sig_name': sig_name} return client.call('kill_instance', params) -def context_switch_monitor(client, args): +def context_switch_monitor(client, enabled=None): + """Query or set state of context switch monitoring. + + Args: + enabled: True to enable monitoring; False to disable monitoring; None to query (optional) + + Returns: + Current context switch monitoring state (after applying enabled flag). + """ params = {} - if args.enable: - params['enabled'] = True - if args.disable: - params['enabled'] = False + if enabled is not None: + params['enabled'] = enabled return client.call('context_switch_monitor', params)