From 27216129b4d5b8497cb0c3141bd52142845deca3 Mon Sep 17 00:00:00 2001 From: Feng Shengqin Date: Tue, 31 Jul 2018 15:16:54 +0800 Subject: [PATCH] Optimizing code for checking the value of force/stop Change-Id: I8f8e3cb65e20f528ae6811b69a0e746181601130 --- zun/api/controllers/v1/containers.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/zun/api/controllers/v1/containers.py b/zun/api/controllers/v1/containers.py index f34a02a54..ddf0e882c 100644 --- a/zun/api/controllers/v1/containers.py +++ b/zun/api/controllers/v1/containers.py @@ -671,19 +671,14 @@ class ContainersController(base.Controller): context.all_projects = True container = utils.get_container(container_ident) check_policy_on_container(container.as_dict(), "container:delete") - try: - force = strutils.bool_from_string(force, strict=True) - except ValueError: - bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS) - raise exception.InvalidValue(_('Valid force values are: %s') - % bools) stop = kwargs.pop('stop', False) try: + force = strutils.bool_from_string(force, strict=True) stop = strutils.bool_from_string(stop, strict=True) except ValueError: bools = ', '.join(strutils.TRUE_STRINGS + strutils.FALSE_STRINGS) - raise exception.InvalidValue(_('Valid stop values are: %s') - % bools) + raise exception.InvalidValue(_('Valid force or stop values ' + 'are: %s') % bools) compute_api = pecan.request.compute_api if not force and not stop: utils.validate_container_state(container, 'delete')