From ca50782ebc1de8ac1d15b2b90346827d9d7efe43 Mon Sep 17 00:00:00 2001 From: zhongjun Date: Mon, 12 Sep 2016 11:05:01 +0800 Subject: [PATCH] Add share_type filter to pool_list Administrators intend to get the pool's information filtered by share type more directly. The blueprint aims to cover this situation: 1. add '--detail' to support retrieving pool list in detail or not 2. add '--share_type' to filter pools by share_type name or id Implements: blueprint pool-list-by-share-type Change-Id: Ia100eb6b4b83c8e2cc91f6fc86f01caa9bce87d4 --- manilaclient/api_versions.py | 2 +- .../tests/functional/test_scheduler_stats.py | 13 ++++++++++ manilaclient/tests/unit/v2/fakes.py | 21 ++++++++++++++++ manilaclient/tests/unit/v2/test_shell.py | 23 ++++++++++++++---- manilaclient/v2/shell.py | 24 +++++++++++++++++-- ...arams-pools-list-api-12cf1s14ddf40kdd.yaml | 4 ++++ 6 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/add-query-params-pools-list-api-12cf1s14ddf40kdd.yaml diff --git a/manilaclient/api_versions.py b/manilaclient/api_versions.py index 4730c057c..e854943c0 100644 --- a/manilaclient/api_versions.py +++ b/manilaclient/api_versions.py @@ -27,7 +27,7 @@ from manilaclient import utils LOG = logging.getLogger(__name__) -MAX_VERSION = '2.22' +MAX_VERSION = '2.23' MIN_VERSION = '2.0' DEPRECATED_VERSION = '1.0' _VERSIONED_METHOD_MAP = {} diff --git a/manilaclient/tests/functional/test_scheduler_stats.py b/manilaclient/tests/functional/test_scheduler_stats.py index f2d743d21..6c78e7182 100644 --- a/manilaclient/tests/functional/test_scheduler_stats.py +++ b/manilaclient/tests/functional/test_scheduler_stats.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +from tempest.lib.common.utils import data_utils from tempest.lib import exceptions from manilaclient.tests.functional import base @@ -25,6 +26,18 @@ class ManilaClientTestSchedulerStatsReadOnly(base.BaseTestCase): def test_pools_list_with_debug_flag(self): self.clients['admin'].manila('pool-list', flags='--debug') + def test_pools_list_with_detail(self): + self.clients['admin'].manila('pool-list', params='--detail') + + def test_pools_list_with_share_type_filter(self): + share_type = self.create_share_type( + name=data_utils.rand_name('manilaclient_functional_test'), + snapshot_support=True, + ) + self.clients['admin'].manila('pool-list', + params='--share_type ' + + share_type['ID']) + def test_pools_list_with_filters(self): self.clients['admin'].manila( 'pool-list', diff --git a/manilaclient/tests/unit/v2/fakes.py b/manilaclient/tests/unit/v2/fakes.py index cf92467d1..2fe452c59 100644 --- a/manilaclient/tests/unit/v2/fakes.py +++ b/manilaclient/tests/unit/v2/fakes.py @@ -594,6 +594,27 @@ class FakeHTTPClient(fakes.FakeHTTPClient): } return (200, {}, pools) + def get_scheduler_stats_pools_detail(self, **kw): + pools = { + 'pools': [ + { + 'name': 'host1@backend1#pool1', + 'host': 'host1', + 'backend': 'backend1', + 'pool': 'pool1', + 'capabilities': {'qos': True}, + }, + { + 'name': 'host1@backend1#pool2', + 'host': 'host1', + 'backend': 'backend1', + 'pool': 'pool2', + 'capabilities': {'qos': False}, + } + ] + } + return (200, {}, pools) + def get_consistency_groups_detail(self, **kw): consistency_groups = { 'consistency_groups': [ diff --git a/manilaclient/tests/unit/v2/test_shell.py b/manilaclient/tests/unit/v2/test_shell.py index 510e5100b..51d57ab9c 100644 --- a/manilaclient/tests/unit/v2/test_shell.py +++ b/manilaclient/tests/unit/v2/test_shell.py @@ -1601,6 +1601,17 @@ class ShellTest(test_utils.TestCase): mock.ANY, fields=["Name", "Host", "Backend", "Pool"]) + @mock.patch.object(cliutils, 'print_list', mock.Mock()) + def test_pool_list_with_detail(self): + self.run_command('pool-list --detail') + self.assert_called( + 'GET', + '/scheduler-stats/pools/detail?backend=.%2A&host=.%2A&pool=.%2A', + ) + cliutils.print_list.assert_called_with( + mock.ANY, + fields=["Name", "Host", "Backend", "Pool", 'Capabilities']) + @mock.patch.object(cliutils, 'print_list', mock.Mock()) def test_pool_list_select_column(self): self.run_command('pool-list --columns name,host') @@ -1612,13 +1623,17 @@ class ShellTest(test_utils.TestCase): mock.ANY, fields=["Name", "Host"]) + @ddt.data('--share-type test_type', '--share_type test_type', + '--share-type-id 0123456789', '--share_type_id 0123456789') @mock.patch.object(cliutils, 'print_list', mock.Mock()) - def test_pool_list_with_filters(self): - self.run_command( - 'pool-list --host host1 --backend backend1 --pool pool1') + def test_pool_list_with_filters(self, param): + cmd = ('pool-list --host host1 --backend backend1 --pool pool1' + ' ' + + param) + self.run_command(cmd) self.assert_called( 'GET', - '/scheduler-stats/pools?backend=backend1&host=host1&pool=pool1', + '/scheduler-stats/pools?backend=backend1&host=host1&' + 'pool=pool1&share_type=%s' % param.split()[-1], ) cliutils.print_list.assert_called_with( mock.ANY, diff --git a/manilaclient/v2/shell.py b/manilaclient/v2/shell.py index 792603cf0..15b1f4a97 100644 --- a/manilaclient/v2/shell.py +++ b/manilaclient/v2/shell.py @@ -3016,6 +3016,19 @@ def do_type_key(cs, args): default=None, help='Comma separated list of columns to be displayed ' 'e.g. --columns "name,host"') +@cliutils.arg( + '--detail', '--detailed', + action='store_true', + help='Show detailed information about pools. (Default=False)') +@cliutils.arg( + '--share-type', '--share_type', + '--share-type-id', '--share_type_id', + metavar='', + type=str, + default=None, + action='single_alias', + help='Filter results by share type name or ID. (Default=None)' + 'Available only for microversion >= 2.23') def do_pool_list(cs, args): """List all backend storage pools known to the scheduler (Admin only).""" @@ -3023,12 +3036,19 @@ def do_pool_list(cs, args): 'host': args.host, 'backend': args.backend, 'pool': args.pool, + 'share_type': args.share_type, } - fields = ["Name", "Host", "Backend", "Pool"] + + if args.detail: + fields = ["Name", "Host", "Backend", "Pool", "Capabilities"] + else: + fields = ["Name", "Host", "Backend", "Pool"] + if args.columns is not None: fields = _split_columns(columns=args.columns) - pools = cs.pools.list(detailed=False, search_opts=search_opts) + pools = cs.pools.list(detailed=args.detail, search_opts=search_opts) + cliutils.print_list(pools, fields=fields) diff --git a/releasenotes/notes/add-query-params-pools-list-api-12cf1s14ddf40kdd.yaml b/releasenotes/notes/add-query-params-pools-list-api-12cf1s14ddf40kdd.yaml new file mode 100644 index 000000000..9c4278a31 --- /dev/null +++ b/releasenotes/notes/add-query-params-pools-list-api-12cf1s14ddf40kdd.yaml @@ -0,0 +1,4 @@ +--- +features: + - Added ``--detail`` argument to pool list command. + - Added ``--share_type`` argument to pool list command.