Browse Source

Merge "Drop support for --sort_key and --sort_dir"

tags/5.0.0^0
Zuul 5 days ago
parent
commit
a63d4d651a

+ 4
- 27
cinderclient/base.py View File

@@ -131,8 +131,7 @@ class Manager(common_base.HookableMixin):
131 131
             return common_base.ListWithMeta(items, resp)
132 132
 
133 133
     def _build_list_url(self, resource_type, detailed=True, search_opts=None,
134
-                        marker=None, limit=None, sort_key=None, sort_dir=None,
135
-                        sort=None, offset=None):
134
+                        marker=None, limit=None, sort=None, offset=None):
136 135
 
137 136
         if search_opts is None:
138 137
             search_opts = {}
@@ -151,16 +150,6 @@ class Manager(common_base.HookableMixin):
151 150
         if sort:
152 151
             query_params['sort'] = self._format_sort_param(sort,
153 152
                                                            resource_type)
154
-        else:
155
-            # sort_key and sort_dir deprecated in kilo, prefer sort
156
-            if sort_key:
157
-                query_params['sort_key'] = self._format_sort_key_param(
158
-                    sort_key,
159
-                    resource_type)
160
-
161
-            if sort_dir:
162
-                query_params['sort_dir'] = self._format_sort_dir_param(
163
-                    sort_dir)
164 153
 
165 154
         if offset:
166 155
             query_params['offset'] = offset
@@ -179,7 +168,7 @@ class Manager(common_base.HookableMixin):
179 168
                  "query_string": query_string})
180 169
 
181 170
     def _format_sort_param(self, sort, resource_type=None):
182
-        '''Formats the sort information into the sort query string parameter.
171
+        """Formats the sort information into the sort query string parameter.
183 172
 
184 173
         The input sort information can be any of the following:
185 174
         - Comma-separated string in the form of <key[:dir]>
@@ -195,7 +184,7 @@ class Manager(common_base.HookableMixin):
195 184
         :returns: Formatted query string parameter or None
196 185
         :raise ValueError: If an invalid sort direction or invalid sort key is
197 186
                            given
198
-        '''
187
+        """
199 188
         if not sort:
200 189
             return None
201 190
 
@@ -205,11 +194,7 @@ class Manager(common_base.HookableMixin):
205 194
 
206 195
         sort_array = []
207 196
         for sort_item in sort:
208
-            if isinstance(sort_item, tuple):
209
-                sort_key = sort_item[0]
210
-                sort_dir = sort_item[1]
211
-            else:
212
-                sort_key, _sep, sort_dir = sort_item.partition(':')
197
+            sort_key, _sep, sort_dir = sort_item.partition(':')
213 198
             sort_key = sort_key.strip()
214 199
             sort_key = self._format_sort_key_param(sort_key, resource_type)
215 200
             if sort_dir:
@@ -237,14 +222,6 @@ class Manager(common_base.HookableMixin):
237 222
                ', '.join(valid_sort_keys))
238 223
         raise ValueError(msg)
239 224
 
240
-    def _format_sort_dir_param(self, sort_dir):
241
-        if sort_dir in SORT_DIR_VALUES:
242
-            return sort_dir
243
-
244
-        msg = ('sort_dir must be one of the following: %s.'
245
-               % ', '.join(SORT_DIR_VALUES))
246
-        raise ValueError(msg)
247
-
248 225
     @contextlib.contextmanager
249 226
     def completion_cache(self, cache_type, obj_class, mode):
250 227
         """

+ 1
- 30
cinderclient/tests/unit/v2/test_shell.py View File

@@ -219,37 +219,11 @@ class ShellTest(utils.TestCase):
219 219
         mock_print.assert_called_once_with(mock.ANY, key_list,
220 220
             exclude_unavailable=True, sortby_index=0)
221 221
 
222
-    def test_list_sort_valid(self):
223
-        self.run_command('list --sort_key=id --sort_dir=asc')
224
-        self.assert_called('GET', '/volumes/detail?sort_dir=asc&sort_key=id')
225
-
226
-    def test_list_sort_key_name(self):
227
-        # Client 'name' key is mapped to 'display_name'
228
-        self.run_command('list --sort_key=name')
229
-        self.assert_called('GET', '/volumes/detail?sort_key=display_name')
230
-
231 222
     def test_list_sort_name(self):
232 223
         # Client 'name' key is mapped to 'display_name'
233 224
         self.run_command('list --sort=name')
234 225
         self.assert_called('GET', '/volumes/detail?sort=display_name')
235 226
 
236
-    def test_list_sort_key_invalid(self):
237
-        self.assertRaises(ValueError,
238
-                          self.run_command,
239
-                          'list --sort_key=foo --sort_dir=asc')
240
-
241
-    def test_list_sort_dir_invalid(self):
242
-        self.assertRaises(ValueError,
243
-                          self.run_command,
244
-                          'list --sort_key=id --sort_dir=foo')
245
-
246
-    def test_list_mix_sort_args(self):
247
-        cmds = ['list --sort name:desc --sort_key=status',
248
-                'list --sort name:desc --sort_dir=asc',
249
-                'list --sort name:desc --sort_key=status --sort_dir=asc']
250
-        for cmd in cmds:
251
-            self.assertRaises(exceptions.CommandError, self.run_command, cmd)
252
-
253 227
     def test_list_sort_single_key_only(self):
254 228
         self.run_command('list --sort=id')
255 229
         self.assert_called('GET', '/volumes/detail?sort=id')
@@ -277,10 +251,7 @@ class ShellTest(utils.TestCase):
277 251
 
278 252
     def test_list_reorder_with_sort(self):
279 253
         # sortby_index is None if there is sort information
280
-        for cmd in ['list --sort_key=name',
281
-                    'list --sort_dir=asc',
282
-                    'list --sort_key=name --sort_dir=asc',
283
-                    'list --sort=name',
254
+        for cmd in ['list --sort=name',
284 255
                     'list --sort=name:asc']:
285 256
             with mock.patch('cinderclient.utils.print_list') as mock_print:
286 257
                 self.run_command(cmd)

+ 1
- 25
cinderclient/tests/unit/v2/test_volumes.py View File

@@ -29,19 +29,6 @@ class VolumesTest(utils.TestCase):
29 29
         cs.assert_called('GET', '/volumes/detail?limit=2&marker=1234')
30 30
         self._assert_request_id(lst)
31 31
 
32
-    def test_list_volumes_with_sort_key_dir(self):
33
-        lst = cs.volumes.list(sort_key='id', sort_dir='asc')
34
-        cs.assert_called('GET', '/volumes/detail?sort_dir=asc&sort_key=id')
35
-        self._assert_request_id(lst)
36
-
37
-    def test_list_volumes_with_invalid_sort_key(self):
38
-        self.assertRaises(ValueError,
39
-                          cs.volumes.list, sort_key='invalid', sort_dir='asc')
40
-
41
-    def test_list_volumes_with_invalid_sort_dir(self):
42
-        self.assertRaises(ValueError,
43
-                          cs.volumes.list, sort_key='id', sort_dir='invalid')
44
-
45 32
     def test__list(self):
46 33
         # There only 2 volumes available for our tests, so we set limit to 2.
47 34
         limit = 2
@@ -345,21 +332,10 @@ class FormatSortParamTestCase(utils.TestCase):
345 332
         self.assertEqual('id:asc,status,size:desc',
346 333
                          cs.volumes._format_sort_param(s))
347 334
 
348
-    def test_format_sort_list_of_tuples(self):
349
-        s = [('id', 'asc'), 'status', ('size', 'desc')]
350
-        self.assertEqual('id:asc,status,size:desc',
351
-                         cs.volumes._format_sort_param(s))
352
-
353
-    def test_format_sort_list_of_strings_and_tuples(self):
354
-        s = [('id', 'asc'), 'status', 'size:desc']
355
-        self.assertEqual('id:asc,status,size:desc',
356
-                         cs.volumes._format_sort_param(s))
357
-
358 335
     def test_format_sort_invalid_direction(self):
359 336
         for s in ['id:foo',
360 337
                   'id:asc,status,size:foo',
361
-                  ['id', 'status', 'size:foo'],
362
-                  ['id', 'status', ('size', 'foo')]]:
338
+                  ['id', 'status', 'size:foo']]:
363 339
             self.assertRaises(ValueError,
364 340
                               cs.volumes._format_sort_param,
365 341
                               s)

+ 0
- 15
cinderclient/tests/unit/v3/test_shell.py View File

@@ -1438,21 +1438,6 @@ class ShellTest(utils.TestCase):
1438 1438
                                  }}
1439 1439
         self.assert_called('POST', '/volume-transfers', body=expected)
1440 1440
 
1441
-    def test_list_transfer_sort_key(self):
1442
-        self.run_command(
1443
-            '--os-volume-api-version 3.59 transfer-list --sort=id')
1444
-        url = ('/volume-transfers/detail?%s' %
1445
-               parse.urlencode([('sort_key', 'id')]))
1446
-        self.assert_called('GET', url)
1447
-
1448
-    def test_list_transfer_sort_key_dir(self):
1449
-        self.run_command(
1450
-            '--os-volume-api-version 3.59 transfer-list --sort=id:asc')
1451
-        url = ('/volume-transfers/detail?%s' %
1452
-               parse.urlencode([('sort_dir', 'asc'),
1453
-                                ('sort_key', 'id')]))
1454
-        self.assert_called('GET', url)
1455
-
1456 1441
     def test_list_transfer_sorty_not_sorty(self):
1457 1442
         self.run_command(
1458 1443
             '--os-volume-api-version 3.59 transfer-list')

+ 2
- 18
cinderclient/v2/shell.py View File

@@ -100,14 +100,6 @@ def _translate_attachments(info):
100 100
                 'Use the show command to see which fields are available. '
101 101
                 'Unavailable/non-existent fields will be ignored. '
102 102
                 'Default=None.')
103
-@utils.arg('--sort_key',
104
-           metavar='<sort_key>',
105
-           default=None,
106
-           help=argparse.SUPPRESS)
107
-@utils.arg('--sort_dir',
108
-           metavar='<sort_dir>',
109
-           default=None,
110
-           help=argparse.SUPPRESS)
111 103
 @utils.arg('--sort',
112 104
            metavar='<key>[:<direction>]',
113 105
            default=None,
@@ -147,16 +139,8 @@ def do_list(cs, args):
147 139
         for field_title in args.fields.split(','):
148 140
             field_titles.append(field_title)
149 141
 
150
-    # --sort_key and --sort_dir deprecated in kilo and is not supported
151
-    # with --sort
152
-    if args.sort and (args.sort_key or args.sort_dir):
153
-        raise exceptions.CommandError(
154
-            'The --sort_key and --sort_dir arguments are deprecated and are '
155
-            'not supported with --sort.')
156
-
157 142
     volumes = cs.volumes.list(search_opts=search_opts, marker=args.marker,
158
-                              limit=args.limit, sort_key=args.sort_key,
159
-                              sort_dir=args.sort_dir, sort=args.sort)
143
+                              limit=args.limit, sort=args.sort)
160 144
     shell_utils.translate_volume_keys(volumes)
161 145
 
162 146
     # Create a list of servers to which the volume is attached
@@ -178,7 +162,7 @@ def do_list(cs, args):
178 162
         if search_opts['all_tenants']:
179 163
             key_list.insert(1, 'Tenant ID')
180 164
 
181
-    if args.sort_key or args.sort_dir or args.sort:
165
+    if args.sort:
182 166
         sortby_index = None
183 167
     else:
184 168
         sortby_index = 0

+ 2
- 6
cinderclient/v2/volumes.py View File

@@ -281,7 +281,7 @@ class VolumeManager(base.ManagerWithFind):
281 281
         return self._get("/volumes/%s" % volume_id, "volume")
282 282
 
283 283
     def list(self, detailed=True, search_opts=None, marker=None, limit=None,
284
-             sort_key=None, sort_dir=None, sort=None):
284
+             sort=None):
285 285
         """Lists all volumes.
286 286
 
287 287
         :param detailed: Whether to return detailed volume info.
@@ -289,9 +289,6 @@ class VolumeManager(base.ManagerWithFind):
289 289
         :param marker: Begin returning volumes that appear later in the volume
290 290
                        list than that represented by this volume id.
291 291
         :param limit: Maximum number of volumes to return.
292
-        :param sort_key: Key to be sorted; deprecated in kilo
293
-        :param sort_dir: Sort direction, should be 'desc' or 'asc'; deprecated
294
-                         in kilo
295 292
         :param sort: Sort information
296 293
         :rtype: list of :class:`Volume`
297 294
         """
@@ -299,8 +296,7 @@ class VolumeManager(base.ManagerWithFind):
299 296
         resource_type = "volumes"
300 297
         url = self._build_list_url(resource_type, detailed=detailed,
301 298
                                    search_opts=search_opts, marker=marker,
302
-                                   limit=limit, sort_key=sort_key,
303
-                                   sort_dir=sort_dir, sort=sort)
299
+                                   limit=limit, sort=sort)
304 300
         return self._list(url, resource_type, limit=limit)
305 301
 
306 302
     def delete(self, volume, cascade=False):

+ 2
- 3
cinderclient/v3/attachments.py View File

@@ -45,7 +45,7 @@ class VolumeAttachmentManager(base.ManagerWithFind):
45 45
 
46 46
     @api_versions.wraps('3.27')
47 47
     def list(self, detailed=False, search_opts=None, marker=None, limit=None,
48
-             sort_key=None, sort_dir=None, sort=None):
48
+             sort=None):
49 49
         """List all attachments."""
50 50
         resource_type = "attachments"
51 51
         url = self._build_list_url(resource_type,
@@ -53,8 +53,7 @@ class VolumeAttachmentManager(base.ManagerWithFind):
53 53
                                    search_opts=search_opts,
54 54
                                    marker=marker,
55 55
                                    limit=limit,
56
-                                   sort_key=sort_key,
57
-                                   sort_dir=sort_dir, sort=sort)
56
+                                   sort=sort)
58 57
         return self._list(url, resource_type, limit=limit)
59 58
 
60 59
     @api_versions.wraps('3.27')

+ 4
- 33
cinderclient/v3/shell.py View File

@@ -337,14 +337,6 @@ RESET_STATE_RESOURCES = {'volume': utils.find_volume,
337 337
                 'Use the show command to see which fields are available. '
338 338
                 'Unavailable/non-existent fields will be ignored. '
339 339
                 'Default=None.')
340
-@utils.arg('--sort_key',
341
-           metavar='<sort_key>',
342
-           default=None,
343
-           help=argparse.SUPPRESS)
344
-@utils.arg('--sort_dir',
345
-           metavar='<sort_dir>',
346
-           default=None,
347
-           help=argparse.SUPPRESS)
348 340
 @utils.arg('--sort',
349 341
            metavar='<key>[:<direction>]',
350 342
            default=None,
@@ -412,24 +404,15 @@ def do_list(cs, args):
412 404
         for field_title in args.fields.split(','):
413 405
             field_titles.append(field_title)
414 406
 
415
-    # --sort_key and --sort_dir deprecated in kilo and is not supported
416
-    # with --sort
417
-    if args.sort and (args.sort_key or args.sort_dir):
418
-        raise exceptions.CommandError(
419
-            'The --sort_key and --sort_dir arguments are deprecated and are '
420
-            'not supported with --sort.')
421
-
422 407
     total_count = 0
423 408
     if show_count:
424 409
         search_opts['with_count'] = args.with_count
425 410
         volumes, total_count = cs.volumes.list(
426 411
             search_opts=search_opts, marker=args.marker,
427
-            limit=args.limit, sort_key=args.sort_key,
428
-            sort_dir=args.sort_dir, sort=args.sort)
412
+            limit=args.limit, sort=args.sort)
429 413
     else:
430 414
         volumes = cs.volumes.list(search_opts=search_opts, marker=args.marker,
431
-                                  limit=args.limit, sort_key=args.sort_key,
432
-                                  sort_dir=args.sort_dir, sort=args.sort)
415
+                                  limit=args.limit, sort=args.sort)
433 416
     shell_utils.translate_volume_keys(volumes)
434 417
 
435 418
     # Create a list of servers to which the volume is attached
@@ -465,7 +448,7 @@ def do_list(cs, args):
465 448
         if search_opts['all_tenants']:
466 449
             key_list.insert(1, 'Tenant ID')
467 450
 
468
-    if args.sort_key or args.sort_dir or args.sort:
451
+    if args.sort:
469 452
         sortby_index = None
470 453
     else:
471 454
         sortby_index = 0
@@ -2591,25 +2574,13 @@ def do_transfer_list(cs, args):
2591 2574
     }
2592 2575
 
2593 2576
     sort = getattr(args, 'sort', None)
2594
-    sort_key = None
2595
-    sort_dir = None
2596 2577
     if sort:
2597
-        # We added this feature with sort_key and sort_dir, but that was a
2598
-        # mistake as we've deprecated that construct a long time ago and should
2599
-        # be removing it in favor of --sort. Too late for the service side, but
2600
-        # to make the client experience consistent, we handle the compatibility
2601
-        # here.
2602 2578
         sort_args = sort.split(':')
2603 2579
         if len(sort_args) > 2:
2604 2580
             raise exceptions.CommandError(
2605 2581
                 'Invalid sort parameter provided. Argument must be in the '
2606 2582
                 'form "key[:<asc|desc>]".')
2607 2583
 
2608
-        sort_key = sort_args[0]
2609
-        if len(sort_args) == 2:
2610
-            sort_dir = sort_args[1]
2611
-
2612
-    transfers = cs.transfers.list(
2613
-        search_opts=search_opts, sort_key=sort_key, sort_dir=sort_dir)
2584
+    transfers = cs.transfers.list(search_opts=search_opts, sort=sort)
2614 2585
     columns = ['ID', 'Volume ID', 'Name']
2615 2586
     utils.print_list(transfers, columns)

+ 3
- 5
cinderclient/v3/volume_transfers.py View File

@@ -62,14 +62,12 @@ class VolumeTransferManager(volume_transfers.VolumeTransferManager):
62 62
 
63 63
         return self._get("/os-volume-transfer/%s" % transfer_id, "transfer")
64 64
 
65
-    def list(self, detailed=True, search_opts=None, sort_key=None,
66
-             sort_dir=None):
65
+    def list(self, detailed=True, search_opts=None, sort=None):
67 66
         """Get a list of all volume transfer.
68 67
 
69 68
         :param detailed: Get detailed object information.
70 69
         :param search_opts: Filtering options.
71
-        :param sort_key: Optional key to sort on.
72
-        :param sort_dir: Optional direction to sort.
70
+        :param sort: Sort information
73 71
         :rtype: list of :class:`VolumeTransfer`
74 72
         """
75 73
         resource_type = 'os-volume-transfer'
@@ -78,7 +76,7 @@ class VolumeTransferManager(volume_transfers.VolumeTransferManager):
78 76
 
79 77
         url = self._build_list_url(resource_type, detailed=detailed,
80 78
                                    search_opts=search_opts,
81
-                                   sort_key=sort_key, sort_dir=sort_dir)
79
+                                   sort=sort)
82 80
         return self._list(url, 'transfers')
83 81
 
84 82
     def delete(self, transfer_id):

+ 3
- 0
releasenotes/notes/cinderclient-5-de0508ce5a221d21.yaml View File

@@ -26,3 +26,6 @@ upgrade:
26 26
     The deprecated volume create option ``--allow-multiattach`` has now been
27 27
     removed. Multiattach capability is now controlled using `volume-type extra
28 28
     specs <https://docs.openstack.org/cinder/latest/admin/blockstorage-volume-multiattach.html>`_.
29
+  - |
30
+    Support for the deprecated ``--sort_key`` and ``--sort_dir`` arguments have
31
+    now been dropped. Use the supported ``--sort`` argument instead.

Loading…
Cancel
Save