From 69031b558d600e507b86dc1ee0a7087ac9436219 Mon Sep 17 00:00:00 2001 From: czl389 Date: Wed, 24 Mar 2021 14:10:15 +0800 Subject: [PATCH] Fix error in CLI 'manila list' with sorting key 'availability_zone'. CLI 'manila list --sort-key availability_zone' return http 400 code, and error message 'Wrong sorting key provided'. The cause is that sortble key name in sqlAlchemy model field is 'availability_zone_id' , not 'availability_zone'. So we need a translation in CLI implement. Closes-Bug: #1920888 Change-Id: Ied983d85ca08a123b78bf8b05085fad8fe5bc2c5 --- manilaclient/common/constants.py | 2 +- manilaclient/tests/unit/v2/test_shell.py | 2 ++ manilaclient/v2/shares.py | 2 ++ ...t-with-sorting-key-availabilityzone-cea5a1f5d8a38fc3.yaml | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/bug-1920888-fix-error-in-cli-manila-list-with-sorting-key-availabilityzone-cea5a1f5d8a38fc3.yaml diff --git a/manilaclient/common/constants.py b/manilaclient/common/constants.py index 291aa3110..2754c22f8 100644 --- a/manilaclient/common/constants.py +++ b/manilaclient/common/constants.py @@ -20,7 +20,7 @@ SORT_DIR_VALUES = ('asc', 'desc') SHARE_SORT_KEY_VALUES = ( 'id', 'status', 'size', 'host', 'share_proto', - 'availability_zone', + 'availability_zone_id', 'availability_zone', 'user_id', 'project_id', 'created_at', 'updated_at', 'display_name', 'name', diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index ef1f0a74d..1aabfaf4a 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -332,6 +332,8 @@ class ShellTest(test_utils.TestCase): key = 'share_network_id' if key == 'share_network' else key key = 'snapshot_id' if key == 'snapshot' else key key = 'share_type_id' if key == 'share_type' else key + key = ('availability_zone_id' if key == 'availability_zone' + else key) self.assert_called('GET', '/shares/detail?sort_key=' + key) def test_list_with_fake_sort_key(self): diff --git a/manilaclient/v2/shares.py b/manilaclient/v2/shares.py index dfb15422b..a1d118577 100644 --- a/manilaclient/v2/shares.py +++ b/manilaclient/v2/shares.py @@ -388,6 +388,8 @@ class ShareManager(base.ManagerWithFind): search_opts['sort_key'] = 'snapshot_id' elif sort_key == 'share_network': search_opts['sort_key'] = 'share_network_id' + elif sort_key == 'availability_zone': + search_opts['sort_key'] = 'availability_zone_id' else: raise ValueError('sort_key must be one of the following: %s.' % ', '.join(constants.SHARE_SORT_KEY_VALUES)) diff --git a/releasenotes/notes/bug-1920888-fix-error-in-cli-manila-list-with-sorting-key-availabilityzone-cea5a1f5d8a38fc3.yaml b/releasenotes/notes/bug-1920888-fix-error-in-cli-manila-list-with-sorting-key-availabilityzone-cea5a1f5d8a38fc3.yaml new file mode 100644 index 000000000..263a7e1d0 --- /dev/null +++ b/releasenotes/notes/bug-1920888-fix-error-in-cli-manila-list-with-sorting-key-availabilityzone-cea5a1f5d8a38fc3.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + `Launchpad bug 1920888 `_: + Fix the bug in CLI 'manila list' with sorting key 'availability_zone'. \ No newline at end of file