diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index 8395efb70..39e3e188a 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -693,6 +693,11 @@ class ShellTest(utils.TestCase): 'manageable-list fakehost --detailed False') self.assert_called('GET', '/manageable_volumes?host=fakehost') + def test_volume_manageable_list_cluster(self): + self.run_command('--os-volume-api-version 3.17 ' + 'manageable-list --cluster dest') + self.assert_called('GET', '/manageable_volumes/detail?cluster=dest') + def test_snapshot_manageable_list(self): self.run_command('--os-volume-api-version 3.8 ' 'snapshot-manageable-list fakehost') @@ -708,6 +713,36 @@ class ShellTest(utils.TestCase): 'snapshot-manageable-list fakehost --detailed False') self.assert_called('GET', '/manageable_snapshots?host=fakehost') + def test_snapshot_manageable_list_cluster(self): + self.run_command('--os-volume-api-version 3.17 ' + 'snapshot-manageable-list --cluster dest') + self.assert_called('GET', '/manageable_snapshots/detail?cluster=dest') + + @ddt.data('', 'snapshot-') + def test_manageable_list_cluster_before_3_17(self, prefix): + self.assertRaises(exceptions.UnsupportedAttribute, + self.run_command, + '--os-volume-api-version 3.16 ' + '%smanageable-list --cluster dest' % prefix) + + @mock.patch('cinderclient.shell.CinderClientArgumentParser.error') + @ddt.data('', 'snapshot-') + def test_manageable_list_mutual_exclusion(self, prefix, error_mock): + error_mock.side_effect = SystemExit + self.assertRaises(SystemExit, + self.run_command, + '--os-volume-api-version 3.17 ' + '%smanageable-list fakehost --cluster dest' % prefix) + + @mock.patch('cinderclient.shell.CinderClientArgumentParser.error') + @ddt.data('', 'snapshot-') + def test_manageable_list_missing_required(self, prefix, error_mock): + error_mock.side_effect = SystemExit + self.assertRaises(SystemExit, + self.run_command, + '--os-volume-api-version 3.17 ' + '%smanageable-list' % prefix) + def test_list_messages(self): self.run_command('--os-volume-api-version 3.3 message-list') self.assert_called('GET', '/messages') diff --git a/cinderclient/v3/shell.py b/cinderclient/v3/shell.py index 644cc054b..d27ce2037 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -1139,10 +1139,20 @@ def do_manage(cs, args): @api_versions.wraps('3.8') -@utils.arg('host', - metavar='', - help='Cinder host on which to list manageable volumes; ' - 'takes the form: host@backend-name#pool') +# NOTE(geguileo): host is positional but optional in order to maintain backward +# compatibility even with mutually exclusive arguments. If version is < 3.16 +# then only host positional argument will be possible, and since the +# exclusive_arg group has required=True it will be required even if it's +# optional. +@utils.exclusive_arg('source', 'host', required=True, nargs='?', + metavar='', + help='Cinder host on which to list manageable volumes; ' + 'takes the form: host@backend-name#pool') +@utils.exclusive_arg('source', '--cluster', required=True, + metavar='CLUSTER', + help='Cinder cluster on which to list manageable ' + 'volumes; takes the form: cluster@backend-name#pool', + start_version='3.17') @utils.arg('--detailed', metavar='', default=True, @@ -1174,9 +1184,11 @@ def do_manageable_list(cs, args): """Lists all manageable volumes.""" # pylint: disable=function-redefined detailed = strutils.bool_from_string(args.detailed) + cluster = getattr(args, 'cluster', None) volumes = cs.volumes.list_manageable(host=args.host, detailed=detailed, marker=args.marker, limit=args.limit, - offset=args.offset, sort=args.sort) + offset=args.offset, sort=args.sort, + cluster=cluster) columns = ['reference', 'size', 'safe_to_manage'] if detailed: columns.extend(['reason_not_safe', 'cinder_id', 'extra_info']) @@ -1601,10 +1613,19 @@ def do_service_list(cs, args): @api_versions.wraps('3.8') -@utils.arg('host', - metavar='', - help='Cinder host on which to list manageable snapshots; ' - 'takes the form: host@backend-name#pool') +# NOTE(geguileo): host is positional but optional in order to maintain backward +# compatibility even with mutually exclusive arguments. If version is < 3.16 +# then only host positional argument will be possible, and since the +# exclusive_arg group has required=True it will be required even if it's +# optional. +@utils.exclusive_arg('source', 'host', required=True, nargs='?', + metavar='', + help='Cinder host on which to list manageable snapshots; ' + 'takes the form: host@backend-name#pool') +@utils.exclusive_arg('source', '--cluster', required=True, + help='Cinder cluster on which to list manageable ' + 'snapshots; takes the form: cluster@backend-name#pool', + start_version='3.17') @utils.arg('--detailed', metavar='', default=True, @@ -1636,12 +1657,14 @@ def do_snapshot_manageable_list(cs, args): """Lists all manageable snapshots.""" # pylint: disable=function-redefined detailed = strutils.bool_from_string(args.detailed) + cluster = getattr(args, 'cluster', None) snapshots = cs.volume_snapshots.list_manageable(host=args.host, detailed=detailed, marker=args.marker, limit=args.limit, offset=args.offset, - sort=args.sort) + sort=args.sort, + cluster=cluster) columns = ['reference', 'size', 'safe_to_manage', 'source_reference'] if detailed: columns.extend(['reason_not_safe', 'cinder_id', 'extra_info']) diff --git a/cinderclient/v3/volume_snapshots.py b/cinderclient/v3/volume_snapshots.py index 2fafe4bdd..3691d2fb8 100644 --- a/cinderclient/v3/volume_snapshots.py +++ b/cinderclient/v3/volume_snapshots.py @@ -65,10 +65,11 @@ class Snapshot(base.Resource): description=description, metadata=metadata) def list_manageable(self, host, detailed=True, marker=None, limit=None, - offset=None, sort=None): + offset=None, sort=None, cluster=None): return self.manager.list_manageable(host, detailed=detailed, marker=marker, limit=limit, - offset=offset, sort=sort) + offset=offset, sort=sort, + cluster=cluster) def unmanage(self, snapshot): """Unmanage a snapshot.""" @@ -212,11 +213,12 @@ class SnapshotManager(base.ManagerWithFind): } return self._create('/os-snapshot-manage', body, 'snapshot') - @api_versions.wraps("3.8") + @api_versions.wraps('3.8') def list_manageable(self, host, detailed=True, marker=None, limit=None, - offset=None, sort=None): + offset=None, sort=None, cluster=None): + search_opts = {'cluster': cluster} if cluster else {'host': host} url = self._build_list_url("manageable_snapshots", detailed=detailed, - search_opts={'host': host}, marker=marker, + search_opts=search_opts, marker=marker, limit=limit, offset=offset, sort=sort) return self._list(url, "manageable-snapshots") diff --git a/cinderclient/v3/volumes.py b/cinderclient/v3/volumes.py index 6669a834d..0cee48bf4 100644 --- a/cinderclient/v3/volumes.py +++ b/cinderclient/v3/volumes.py @@ -261,11 +261,12 @@ class VolumeManager(volumes.VolumeManager): body['volume']['cluster'] = cluster return self._create('/os-volume-manage', body, 'volume') - @api_versions.wraps("3.8") + @api_versions.wraps('3.8') def list_manageable(self, host, detailed=True, marker=None, limit=None, - offset=None, sort=None): + offset=None, sort=None, cluster=None): + search_opts = {'cluster': cluster} if cluster else {'host': host} url = self._build_list_url("manageable_volumes", detailed=detailed, - search_opts={'host': host}, marker=marker, + search_opts=search_opts, marker=marker, limit=limit, offset=offset, sort=sort) return self._list(url, "manageable-volumes") diff --git a/releasenotes/notes/cluster_list_manageable-40c02489b2c95d55.yaml b/releasenotes/notes/cluster_list_manageable-40c02489b2c95d55.yaml new file mode 100644 index 000000000..306c0dc46 --- /dev/null +++ b/releasenotes/notes/cluster_list_manageable-40c02489b2c95d55.yaml @@ -0,0 +1,7 @@ +--- +features: + - | + Cinder ``manageable-list`` and ``snapshot-manageable-list`` commands now + accept ``--cluster`` argument to specify the backend we want to list for + microversion 3.17 and higher. This argument and the ``host`` positional + argument are mutually exclusive.