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
This commit is contained in:
zhongjun 2016-09-12 11:05:01 +08:00 committed by zhongjun2
parent a88bfc654d
commit ca50782ebc
6 changed files with 80 additions and 7 deletions

View File

@ -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 = {}

View File

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

View File

@ -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': [

View File

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

View File

@ -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='<share_type>',
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)

View File

@ -0,0 +1,4 @@
---
features:
- Added ``--detail`` argument to pool list command.
- Added ``--share_type`` argument to pool list command.