Fix 'List' command filters do not accept unicode symbols
When using the name or description to filter the share group list, if the name or description is unicode symbols, the query will fail due to the invalid str value. This change is to fix this. PS: this bug is left from [1] [1] I73ed2b675542d3aeedc9efdba08067819bf7d3e4 Change-Id: I14db19fb87da5cac86ec3634ddde6d647999db96 Closes-bug: #1712988
This commit is contained in:
@@ -176,9 +176,15 @@ class Manager(utils.HookableMixin):
|
||||
return self.resource_class(self, body)
|
||||
|
||||
def _build_query_string(self, search_opts):
|
||||
q_string = parse.urlencode(
|
||||
sorted([(k, v) for (k, v) in search_opts.items() if v]))
|
||||
return "?%s" % q_string if q_string else q_string
|
||||
query_string = ""
|
||||
if search_opts:
|
||||
search_opts = utils.unicode_key_value_to_string(search_opts)
|
||||
params = sorted(
|
||||
[(k, v) for (k, v) in search_opts.items() if v])
|
||||
if params:
|
||||
query_string = "?%s" % parse.urlencode(params)
|
||||
|
||||
return query_string
|
||||
|
||||
|
||||
class ManagerWithFind(Manager):
|
||||
|
@@ -2048,6 +2048,22 @@ class ShellTest(test_utils.TestCase):
|
||||
'GET',
|
||||
'/share-groups/detail?description%7E=fake_description')
|
||||
|
||||
def test_share_group_list_filter_by_inexact_unicode_name(self):
|
||||
for separator in self.separators:
|
||||
self.run_command('share-group-list --name~' + separator +
|
||||
u'ффф')
|
||||
self.assert_called(
|
||||
'GET',
|
||||
'/share-groups/detail?name%7E=%D1%84%D1%84%D1%84')
|
||||
|
||||
def test_share_group_list_filter_by_inexact_unicode_description(self):
|
||||
for separator in self.separators:
|
||||
self.run_command('share-group-list --description~' + separator +
|
||||
u'ффф')
|
||||
self.assert_called(
|
||||
'GET',
|
||||
'/share-groups/detail?description%7E=%D1%84%D1%84%D1%84')
|
||||
|
||||
def test_share_group_show(self):
|
||||
self.run_command('share-group-show 1234')
|
||||
|
||||
|
@@ -4212,13 +4212,13 @@ def do_share_group_create(cs, args):
|
||||
@cliutils.arg(
|
||||
'--name',
|
||||
metavar='<name>',
|
||||
type=str,
|
||||
type=six.text_type,
|
||||
default=None,
|
||||
help='Filter results by name.')
|
||||
@cliutils.arg(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
type=str,
|
||||
type=six.text_type,
|
||||
default=None,
|
||||
help='Filter results by description. '
|
||||
'Available only for microversion >= 2.36.')
|
||||
@@ -4308,14 +4308,14 @@ def do_share_group_create(cs, args):
|
||||
@cliutils.arg(
|
||||
'--name~',
|
||||
metavar='<name~>',
|
||||
type=str,
|
||||
type=six.text_type,
|
||||
default=None,
|
||||
help='Filter results matching a share group name pattern. '
|
||||
'Available only for microversion >= 2.36.')
|
||||
@cliutils.arg(
|
||||
'--description~',
|
||||
metavar='<description~>',
|
||||
type=str,
|
||||
type=six.text_type,
|
||||
default=None,
|
||||
help='Filter results matching a share group description pattern. '
|
||||
'Available only for microversion >= 2.36.')
|
||||
|
Reference in New Issue
Block a user