Updates default --sort behaviour

When querying against a Juno glance-registry, we found that having the
--sort option defaulting to 'name:asc" results in querying the registry
with additional SQL parameters like the following:

WHERE image_properties_2.name = :name_1 AND image_properties_2.value =
:value_1

as a result of handling the newer 'sort' filter. This results in a
blank list being returned as the output of glance image-list.

This patch sets the --sort-key and --sort-dir instead of --sort when
neither --sort-key nor --sort-dir are specified, so as to maintain
backwards compatibility with Juno glance-registry.

Change-Id: I8bd64cca7f1b7abdbabf4c09e3dbbcb4044e51b4
Closes-bug: #1492887
This commit is contained in:
Jake Yip
2015-09-08 20:04:11 +10:00
parent aa4cd9dc4b
commit c8c8964ddd

View File

@@ -142,8 +142,8 @@ def do_image_update(gc, args):
help='Sort image list in specified directions.') help='Sort image list in specified directions.')
@utils.arg('--sort', metavar='<key>[:<direction>]', default=None, @utils.arg('--sort', metavar='<key>[:<direction>]', default=None,
help=(("Comma-separated list of sort keys and directions in the " help=(("Comma-separated list of sort keys and directions in the "
"form of <key>[:<asc|desc>]. Valid keys: %s. OPTIONAL: " "form of <key>[:<asc|desc>]. Valid keys: %s. OPTIONAL."
"Default='name:asc'.") % ', '.join(images.SORT_KEY_VALUES))) ) % ', '.join(images.SORT_KEY_VALUES)))
def do_image_list(gc, args): def do_image_list(gc, args):
"""List images you can access.""" """List images you can access."""
filter_keys = ['visibility', 'member_status', 'owner', 'checksum', 'tag'] filter_keys = ['visibility', 'member_status', 'owner', 'checksum', 'tag']
@@ -169,7 +169,8 @@ def do_image_list(gc, args):
if args.sort is not None: if args.sort is not None:
kwargs['sort'] = args.sort kwargs['sort'] = args.sort
elif not args.sort_dir and not args.sort_key: elif not args.sort_dir and not args.sort_key:
kwargs['sort'] = 'name:asc' kwargs['sort_key'] = 'name'
kwargs['sort_dir'] = 'asc'
columns = ['ID', 'Name'] columns = ['ID', 'Name']