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
This commit is contained in:
Gorka Eguileor 2016-10-17 16:27:14 +02:00
parent 8fce74056f
commit 1a4176ad87
5 changed files with 86 additions and 18 deletions

View File

@ -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')

View File

@ -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'])

View File

@ -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")

View File

@ -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")

View File

@ -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.