diff options
-rw-r--r-- | doc/source/cli/property-keys.rst | 6 | ||||
-rw-r--r-- | glanceclient/common/utils.py | 2 | ||||
-rw-r--r-- | glanceclient/tests/functional/v1/test_readonly_glance.py | 9 | ||||
-rw-r--r-- | glanceclient/tests/functional/v2/test_readonly_glance.py | 9 | ||||
-rw-r--r-- | glanceclient/tests/unit/test_utils.py | 9 | ||||
-rw-r--r-- | glanceclient/v2/shell.py | 23 | ||||
-rw-r--r-- | tox.ini | 5 |
7 files changed, 38 insertions, 25 deletions
diff --git a/doc/source/cli/property-keys.rst b/doc/source/cli/property-keys.rst index 5c3cee4..7176779 100644 --- a/doc/source/cli/property-keys.rst +++ b/doc/source/cli/property-keys.rst @@ -7,14 +7,14 @@ that can be consumed by other services to affect the behavior of those other services. Properties can be set on an image at the time of image creation or they -can be set on an existing image. Use the :command:`openstack image create` -and :command:`openstack image set` commands respectively. +can be set on an existing image. Use the :command:`glance image-create` +and :command:`glance image-update` commands respectively. For example: .. code-block:: console - $ openstack image set IMG-UUID --property architecture=x86_64 + $ glance image-update IMG-UUID --property architecture=x86_64 For a list of image properties that can be used to affect the behavior of other services, refer to `Useful image properties diff --git a/glanceclient/common/utils.py b/glanceclient/common/utils.py index 0de575f..c7afc79 100644 --- a/glanceclient/common/utils.py +++ b/glanceclient/common/utils.py @@ -123,6 +123,8 @@ def schema_args(schema_getter, omit=None): for name, property in properties.items(): if name in omit: continue + if property.get('readOnly', False): + continue param = '--' + name.replace('_', '-') kwargs = {} diff --git a/glanceclient/tests/functional/v1/test_readonly_glance.py b/glanceclient/tests/functional/v1/test_readonly_glance.py index a7024aa..ffd8358 100644 --- a/glanceclient/tests/functional/v1/test_readonly_glance.py +++ b/glanceclient/tests/functional/v1/test_readonly_glance.py @@ -51,7 +51,14 @@ class SimpleReadOnlyGlanceClientTest(base.ClientTestBase): commands = [] cmds_start = lines.index('Positional arguments:') - cmds_end = lines.index('Optional arguments:') + try: + # Starting in Python 3.10, argparse displays options in the + # "Options:" section... + cmds_end = lines.index('Options:') + except ValueError: + # ... but before Python 3.10, options were displayed in the + # "Optional arguments:" section. + cmds_end = lines.index('Optional arguments:') command_pattern = re.compile(r'^ {4}([a-z0-9\-\_]+)') for line in lines[cmds_start:cmds_end]: match = command_pattern.match(line) diff --git a/glanceclient/tests/functional/v2/test_readonly_glance.py b/glanceclient/tests/functional/v2/test_readonly_glance.py index 4d7f92d..7bc86d1 100644 --- a/glanceclient/tests/functional/v2/test_readonly_glance.py +++ b/glanceclient/tests/functional/v2/test_readonly_glance.py @@ -71,7 +71,14 @@ class SimpleReadOnlyGlanceClientTest(base.ClientTestBase): commands = [] cmds_start = lines.index('Positional arguments:') - cmds_end = lines.index('Optional arguments:') + try: + # Starting in Python 3.10, argparse displays options in the + # "Options:" section... + cmds_end = lines.index('Options:') + except ValueError: + # ... but before Python 3.10, options were displayed in the + # "Optional arguments:" section. + cmds_end = lines.index('Optional arguments:') command_pattern = re.compile(r'^ {4}([a-z0-9\-\_]+)') for line in lines[cmds_start:cmds_end]: match = command_pattern.match(line) diff --git a/glanceclient/tests/unit/test_utils.py b/glanceclient/tests/unit/test_utils.py index d10c70d..e4b7200 100644 --- a/glanceclient/tests/unit/test_utils.py +++ b/glanceclient/tests/unit/test_utils.py @@ -191,12 +191,17 @@ class TestUtils(testtools.TestCase): def schema_getter(_type='string', enum=False): prop = { 'type': ['null', _type], - 'readOnly': True, 'description': 'Test schema', } + prop_readonly = { + 'type': ['null', _type], + 'readOnly': True, + 'description': 'Test schema read-only', + } if enum: prop['enum'] = [None, 'opt-1', 'opt-2'] + prop_readonly['enum'] = [None, 'opt-ro-1', 'opt-ro-2'] def actual_getter(): return { @@ -205,6 +210,7 @@ class TestUtils(testtools.TestCase): 'name': 'test_schema', 'properties': { 'test': prop, + 'readonly-test': prop_readonly, } } @@ -214,6 +220,7 @@ class TestUtils(testtools.TestCase): pass decorated = utils.schema_args(schema_getter())(dummy_func) + self.assertEqual(len(decorated.__dict__['arguments']), 1) arg, opts = decorated.__dict__['arguments'][0] self.assertIn('--test', arg) self.assertEqual(encodeutils.safe_decode, opts['type']) diff --git a/glanceclient/v2/shell.py b/glanceclient/v2/shell.py index 773c198..93a9377 100644 --- a/glanceclient/v2/shell.py +++ b/glanceclient/v2/shell.py @@ -49,11 +49,7 @@ def get_image_schema(): return IMAGE_SCHEMA -@utils.schema_args(get_image_schema, omit=['created_at', 'updated_at', 'file', - 'checksum', 'virtual_size', 'size', - 'status', 'schema', 'direct_url', - 'locations', 'self', 'os_hidden', - 'os_hash_value', 'os_hash_algo']) +@utils.schema_args(get_image_schema, omit=['locations', 'os_hidden']) # NOTE(rosmaita): to make this option more intuitive for end users, we # do not use the Glance image property name 'os_hidden' here. This means # we must include 'os_hidden' in the 'omit' list above and handle the @@ -118,11 +114,7 @@ def do_image_create(gc, args): utils.print_image(image) -@utils.schema_args(get_image_schema, omit=['created_at', 'updated_at', 'file', - 'checksum', 'virtual_size', 'size', - 'status', 'schema', 'direct_url', - 'locations', 'self', 'os_hidden', - 'os_hash_value', 'os_hash_algo']) +@utils.schema_args(get_image_schema, omit=['locations', 'os_hidden']) # NOTE: --hidden requires special handling; see note at do_image_create @utils.arg('--hidden', type=strutils.bool_from_string, metavar='[True|False]', default=None, @@ -354,12 +346,8 @@ def _validate_backend(backend, gc): @utils.arg('id', metavar='<IMAGE_ID>', help=_('ID of image to update.')) -@utils.schema_args(get_image_schema, omit=['id', 'locations', 'created_at', - 'updated_at', 'file', 'checksum', - 'virtual_size', 'size', 'status', - 'schema', 'direct_url', 'tags', - 'self', 'os_hidden', - 'os_hash_value', 'os_hash_algo']) +@utils.schema_args(get_image_schema, omit=['id', 'locations', 'tags', + 'os_hidden']) # NOTE: --hidden requires special handling; see note at do_image_create @utils.arg('--hidden', type=strutils.bool_from_string, metavar='[True|False]', default=None, @@ -1105,8 +1093,7 @@ def do_md_namespace_import(gc, args): @utils.schema_args(get_namespace_schema, omit=['property_count', 'properties', 'tag_count', 'tags', 'object_count', 'objects', - 'resource_type_associations', - 'schema']) + 'resource_type_associations']) def do_md_namespace_update(gc, args): """Update an existing metadata definitions namespace.""" schema = gc.schemas.get('metadefs/namespace') @@ -54,9 +54,12 @@ commands = [testenv:docs] basepython = python3 -deps = -r{toxinidir}/doc/requirements.txt +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/doc/requirements.txt commands = sphinx-build -W -b html doc/source doc/build/html + sphinx-build -W -b man doc/source doc/build/man [testenv:releasenotes] basepython = python3 |