From b858466964d129886befd85b776a5c20a217a10f Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Thu, 16 Feb 2017 15:48:55 -0600 Subject: [PATCH] Generalize the usage of _remove_null_params Make sure the parameter is None before removing it. This is for avoiding incorrect removal of xxx=False, xxx=[], etc. Related-Bug: #1658613 Change-Id: I08d868edbeb95fe545cdb5d1ceaea4f05f8a338b --- zunclient/osc/v1/containers.py | 1 + zunclient/v1/containers_shell.py | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/zunclient/osc/v1/containers.py b/zunclient/osc/v1/containers.py index 7ec8f931..d836adf8 100644 --- a/zunclient/osc/v1/containers.py +++ b/zunclient/osc/v1/containers.py @@ -403,6 +403,7 @@ class KillContainer(command.Command): opts = {} opts['id'] = parsed_args.container opts['signal'] = parsed_args.signal + opts = _remove_null_parms(**opts) try: client.containers.kill(**opts) print(_('Request to send kill signal to container %s has ' diff --git a/zunclient/v1/containers_shell.py b/zunclient/v1/containers_shell.py index 0913484c..5a0dbcec 100644 --- a/zunclient/v1/containers_shell.py +++ b/zunclient/v1/containers_shell.py @@ -64,7 +64,7 @@ def _check_restart_policy(policy): def _remove_null_parms(**kwargs): new = {} for (key, value) in kwargs.items(): - if value: + if value is not None: new[key] = value return new @@ -334,6 +334,7 @@ def do_kill(cs, args): opts = {} opts['id'] = container opts['signal'] = args.signal + opts = _remove_null_parms(**opts) try: cs.containers.kill(**opts) print( @@ -440,10 +441,9 @@ def do_rename(cs, args): def do_update(cs, args): """Updates one or more container attributes""" opts = {} - if args.memory is not None: - opts['memory'] = args.memory - if args.cpu is not None: - opts['cpu'] = args.cpu + opts['memory'] = args.memory + opts['cpu'] = args.cpu + opts = _remove_null_parms(**opts) if not opts: raise exc.CommandError("You must update at least one property") container = cs.containers.update(args.container, **opts)