From 6eaaad532ad42d46a4d5ccb6e96e6508bee5ebef Mon Sep 17 00:00:00 2001 From: Cindy Pallares Date: Fri, 19 Dec 2014 11:53:50 -0500 Subject: [PATCH] Make non-boolean check strict Currently when we enter any non-boolean strings in the client, it accepts it and defaults the value to false. It should check if the strings are boolean values and respond with an error if they're not. Closes-Bug: #1394236 Change-Id: Ie498ee1b93524d91a43343f73140446c2cc9ab92 --- glanceclient/v1/shell.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/glanceclient/v1/shell.py b/glanceclient/v1/shell.py index d4d117e3..5d5452ef 100644 --- a/glanceclient/v1/shell.py +++ b/glanceclient/v1/shell.py @@ -16,6 +16,7 @@ from __future__ import print_function import copy +import functools import six import sys @@ -29,6 +30,8 @@ CONTAINER_FORMATS = 'Acceptable formats: ami, ari, aki, bare, and ovf.' DISK_FORMATS = ('Acceptable formats: ami, ari, aki, vhd, vmdk, raw, ' 'qcow2, vdi, and iso.') +_bool_strict = functools.partial(strutils.bool_from_string, strict=True) + @utils.arg('--name', metavar='', help='Filter images to those that have this name.') @@ -58,7 +61,7 @@ DISK_FORMATS = ('Acceptable formats: ami, ari, aki, vhd, vmdk, raw, ' choices=glanceclient.v1.images.SORT_DIR_VALUES, help='Sort image list in specified direction.') @utils.arg('--is-public', - type=strutils.bool_from_string, metavar='{True,False}', + type=_bool_strict, metavar='{True,False}', help=('Allows the user to select a listing of public or non ' 'public images.')) @utils.arg('--owner', default=None, metavar='', @@ -188,10 +191,10 @@ def do_image_download(gc, args): ' the Glance server should immediately copy the data and' ' store it in its configured image store.')) @utils.arg('--is-public', - type=strutils.bool_from_string, metavar='{True,False}', + type=_bool_strict, metavar='{True,False}', help='Make image accessible to the public.') @utils.arg('--is-protected', - type=strutils.bool_from_string, metavar='{True,False}', + type=_bool_strict, metavar='{True,False}', help='Prevent image from being deleted.') @utils.arg('--property', metavar="", action='append', default=[], help=("Arbitrary property to associate with image. " @@ -265,10 +268,10 @@ def do_image_create(gc, args): ' the Glance server should immediately copy the data and' ' store it in its configured image store.')) @utils.arg('--is-public', - type=strutils.bool_from_string, metavar='{True,False}', + type=_bool_strict, metavar='{True,False}', help='Make image accessible to the public.') @utils.arg('--is-protected', - type=strutils.bool_from_string, metavar='{True,False}', + type=_bool_strict, metavar='{True,False}', help='Prevent image from being deleted.') @utils.arg('--property', metavar="", action='append', default=[], help=("Arbitrary property to associate with image. "