summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2023-01-12 22:39:41 +0000
committerGerrit Code Review <review@openstack.org>2023-01-12 22:39:41 +0000
commit9b9c67771505ead95feb2525773f988a59436cf6 (patch)
tree2b7b91b9ad4018e412ecd84aa96d914c5ce3b978
parent6c95122777c8449056115292b492ec3e1e0d6e50 (diff)
parent88e3b0ad984797ec1f856429698949e4781dff3a (diff)
downloadpython-glanceclient-9b9c67771505ead95feb2525773f988a59436cf6.tar.gz
Merge "Boolean options: use strict checking"
-rw-r--r--doc/source/cli/property-keys.rst5
-rw-r--r--glanceclient/common/utils.py2
-rw-r--r--glanceclient/tests/unit/test_utils.py8
-rw-r--r--releasenotes/notes/boolean-properties-strict-checking-bdd624b5da81e723.yaml12
4 files changed, 26 insertions, 1 deletions
diff --git a/doc/source/cli/property-keys.rst b/doc/source/cli/property-keys.rst
index f2367fe..7176779 100644
--- a/doc/source/cli/property-keys.rst
+++ b/doc/source/cli/property-keys.rst
@@ -27,3 +27,8 @@ in the Glance Administration Guide.
For more information, refer to `Manage images
<https://docs.openstack.org/glance/latest/admin/manage-images.html>`_
in the Glance Administration Guide.
+
+.. note::
+
+ Boolean properties expect one of the following values: '0', '1', 'f',
+ 'false', 'n', 'no', 'off', 'on', 't', 'true', 'y', 'yes' (case-insensitive).
diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py
index e131bd9..c7afc79 100644
--- a/glanceclient/common/utils.py
+++ b/glanceclient/common/utils.py
@@ -103,7 +103,7 @@ def schema_args(schema_getter, omit=None):
typemap = {
'string': encodeutils.safe_decode,
'integer': int,
- 'boolean': strutils.bool_from_string,
+ 'boolean': lambda x: strutils.bool_from_string(x, strict=True),
'array': list
}
diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py
index db08a1c..e4b7200 100644
--- a/glanceclient/tests/unit/test_utils.py
+++ b/glanceclient/tests/unit/test_utils.py
@@ -236,6 +236,14 @@ class TestUtils(testtools.TestCase):
self.assertEqual(encodeutils.safe_decode, opts['type'])
self.assertIn('None, opt-1, opt-2', opts['help'])
+ # Make sure we use strict checking for boolean values.
+ decorated = utils.schema_args(schema_getter('boolean'))(dummy_func)
+ arg, opts = decorated.__dict__['arguments'][0]
+ type_function = opts['type']
+ self.assertEqual(type_function('False'), False)
+ self.assertEqual(type_function('True'), True)
+ self.assertRaises(ValueError, type_function, 'foo')
+
def test_iterable_closes(self):
# Regression test for bug 1461678.
def _iterate(i):
diff --git a/releasenotes/notes/boolean-properties-strict-checking-bdd624b5da81e723.yaml b/releasenotes/notes/boolean-properties-strict-checking-bdd624b5da81e723.yaml
new file mode 100644
index 0000000..bd0836d
--- /dev/null
+++ b/releasenotes/notes/boolean-properties-strict-checking-bdd624b5da81e723.yaml
@@ -0,0 +1,12 @@
+---
+prelude: >
+fixes:
+ - |
+ * Bug 1607317_: metadata def namespace update CLI is not working as expected for parameter "protected"
+
+ .. _1607317: https://code.launchpad.net/bugs/1607317
+other:
+ - |
+ Boolean arguments now expect one of the following values: '0', '1', 'f',
+ 'false', 'n', 'no', 'off', 'on', 't', 'true', 'y', 'yes'
+ (case-insensitive). This will not change anything for most users.