diff options
| author | Gorka Eguileor <geguileo@redhat.com> | 2016-10-17 16:27:14 +0200 |
|---|---|---|
| committer | Gorka Eguileor <geguileo@redhat.com> | 2017-10-03 11:03:28 +0200 |
| commit | 1a4176ad87da88a39e4bd04e2c55e8109215d591 (patch) | |
| tree | 69d5910b5b7d3b142bbc033960d7dfe0841ff418 /cinderclient | |
| parent | 8fce74056fa4afd03149ede9d4b8786cc78ada3e (diff) | |
| download | python-cinderclient-1a4176ad87da88a39e4bd04e2c55e8109215d591.tar.gz | |
Add cluster support in manage listings
This patch adds support for API microversion 3.17, which allows us to
pass --cluster optional argument to volume and snapshot manage listings.
Implements: blueprint cinder-volume-active-active-support
Change-Id: I97b5f2e9960d5a1f140fc638804dbc631d63ff9d
Diffstat (limited to 'cinderclient')
| -rw-r--r-- | cinderclient/tests/unit/v3/test_shell.py | 35 | ||||
| -rw-r--r-- | cinderclient/v3/shell.py | 43 | ||||
| -rw-r--r-- | cinderclient/v3/volume_snapshots.py | 12 | ||||
| -rw-r--r-- | cinderclient/v3/volumes.py | 7 |
4 files changed, 79 insertions, 18 deletions
diff --git a/cinderclient/tests/unit/v3/test_shell.py b/cinderclient/tests/unit/v3/test_shell.py index f756ec1..8d362e8 100644 --- a/cinderclient/tests/unit/v3/test_shell.py +++ b/cinderclient/tests/unit/v3/test_shell.py @@ -643,6 +643,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') @@ -658,6 +663,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 db23d83..c453826 100644 --- a/cinderclient/v3/shell.py +++ b/cinderclient/v3/shell.py @@ -1090,10 +1090,20 @@ def do_manage(cs, args): @api_versions.wraps('3.8') -@utils.arg('host', - metavar='<host>', - 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='<host>', + 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='<detailed>', default=True, @@ -1125,9 +1135,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']) @@ -1552,10 +1564,19 @@ def do_service_list(cs, args): @api_versions.wraps('3.8') -@utils.arg('host', - metavar='<host>', - 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='<host>', + 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='<detailed>', default=True, @@ -1587,12 +1608,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 2fafe4b..3691d2f 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 bba714b..d26558e 100644 --- a/cinderclient/v3/volumes.py +++ b/cinderclient/v3/volumes.py @@ -250,11 +250,12 @@ class VolumeManager(volumes.VolumeManager): body['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") |
