[OSC] Implement Share Group Commands
Added the implementation of the share group commands to OSC. Commands are: - openstack share group create - openstack share group delete - openstack share group list - openstack share group show - openstack share group set - openstack share group unset Change-Id: I9eb31449fef4eae73f1db91f2bad133d0fe8df2e
This commit is contained in:
parent
92ca00cd64
commit
7c8aa8efd1
@ -144,3 +144,10 @@ share instance export location
|
||||
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share instance export location *
|
||||
|
||||
============
|
||||
share groups
|
||||
============
|
||||
|
||||
.. autoprogram-cliff:: openstack.share.v2
|
||||
:command: share group *
|
||||
|
545
manilaclient/osc/v2/share_groups.py
Normal file
545
manilaclient/osc/v2/share_groups.py
Normal file
@ -0,0 +1,545 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
|
||||
from osc_lib.cli import parseractions
|
||||
from osc_lib.command import command
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import utils as osc_utils
|
||||
|
||||
from manilaclient import api_versions
|
||||
from manilaclient.common._i18n import _
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateShareGroup(command.ShowOne):
|
||||
"""Create new share group."""
|
||||
_description = _(
|
||||
"Create new share group")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar="<name>",
|
||||
default=None,
|
||||
help=_('Share group name')
|
||||
)
|
||||
parser.add_argument(
|
||||
"--description",
|
||||
metavar="<description>",
|
||||
default=None,
|
||||
help=_("Share group description."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-types",
|
||||
metavar="<share-types>",
|
||||
nargs="+",
|
||||
default=[],
|
||||
help=_("Name or ID of share type(s)."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-group-type",
|
||||
metavar="<share-group-type>",
|
||||
default=None,
|
||||
help=_("Share group type name or ID of the share "
|
||||
"group to be created."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-network",
|
||||
metavar="<share-network>",
|
||||
default=False,
|
||||
help=_("Specify share network name or id"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--source-share-group-snapshot",
|
||||
metavar="<source-share-group-snapshot>",
|
||||
default=False,
|
||||
help=_("Share group snapshot name or ID to create "
|
||||
"the share group from."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--availability-zone",
|
||||
metavar='<availability-zone>',
|
||||
default=None,
|
||||
help=_("Optional availability zone in which group "
|
||||
"should be created"),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wait",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_('Wait for share group creation')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
|
||||
share_types = []
|
||||
for share_type in parsed_args.share_types:
|
||||
share_types.append(
|
||||
osc_utils.find_resource(
|
||||
share_client.share_types,
|
||||
share_type,
|
||||
)
|
||||
)
|
||||
share_group_type = None
|
||||
if parsed_args.share_group_type:
|
||||
share_group_type = osc_utils.find_resource(
|
||||
share_client.share_group_types,
|
||||
parsed_args.share_group_type).id
|
||||
|
||||
share_network = None
|
||||
if parsed_args.share_network:
|
||||
share_network = osc_utils.find_resource(
|
||||
share_client.share_networks,
|
||||
parsed_args.share_network).id
|
||||
|
||||
source_share_group_snapshot = None
|
||||
if parsed_args.source_share_group_snapshot:
|
||||
source_share_group_snapshot = osc_utils.find_resource(
|
||||
share_client.source_share_group_snapshots,
|
||||
parsed_args.source_share_group_snapshot).id
|
||||
|
||||
body = {
|
||||
'name': parsed_args.name,
|
||||
'description': parsed_args.description,
|
||||
'share_types': share_types,
|
||||
'share_group_type': share_group_type,
|
||||
'share_network': share_network,
|
||||
'source_share_group_snapshot': source_share_group_snapshot,
|
||||
'availability_zone': parsed_args.availability_zone
|
||||
}
|
||||
|
||||
share_group = share_client.share_groups.create(**body)
|
||||
|
||||
if parsed_args.wait:
|
||||
if not osc_utils.wait_for_status(
|
||||
status_f=share_client.share_groups.get,
|
||||
res_id=share_group.id,
|
||||
success_status=['available']
|
||||
):
|
||||
LOG.error(_("ERROR: Share group is in error state."))
|
||||
|
||||
share_group = osc_utils.find_resource(
|
||||
share_client.share_groups,
|
||||
share_group.id)
|
||||
|
||||
printable_share_group = share_group._info
|
||||
printable_share_group.pop('links', None)
|
||||
|
||||
if printable_share_group.get('share_types'):
|
||||
if parsed_args.formatter == 'table':
|
||||
printable_share_group['share_types'] = (
|
||||
"\n".join(printable_share_group['share_types'])
|
||||
)
|
||||
|
||||
return self.dict2columns(printable_share_group)
|
||||
|
||||
|
||||
class DeleteShareGroup(command.Command):
|
||||
"""Delete one or more share groups."""
|
||||
_description = _("Delete one or more share groups")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(DeleteShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"share_group",
|
||||
metavar="<share_group>",
|
||||
nargs="+",
|
||||
help=_("Name or ID of the share group(s) to delete")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--force",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Attempt to force delete the share group (Default=False) "
|
||||
"(Admin only).")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--wait",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Wait for share group to delete")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
result = 0
|
||||
|
||||
for share_group in parsed_args.share_group:
|
||||
try:
|
||||
share_group_obj = osc_utils.find_resource(
|
||||
share_client.share_groups,
|
||||
share_group)
|
||||
|
||||
share_client.share_groups.delete(
|
||||
share_group_obj,
|
||||
force=parsed_args.force)
|
||||
|
||||
if parsed_args.wait:
|
||||
if not osc_utils.wait_for_delete(
|
||||
manager=share_client.share_groups,
|
||||
res_id=share_group_obj.id):
|
||||
result += 1
|
||||
|
||||
except Exception as e:
|
||||
result += 1
|
||||
LOG.error(_(
|
||||
"Failed to delete share group with "
|
||||
"name or ID '%(share_group)s': %(e)s"),
|
||||
{'share_group': share_group, 'e': e})
|
||||
|
||||
if result > 0:
|
||||
total = len(parsed_args.share_group)
|
||||
msg = (_("%(result)s of %(total)s share groups failed "
|
||||
"to delete.") % {'result': result, 'total': total})
|
||||
raise exceptions.CommandError(msg)
|
||||
|
||||
|
||||
class ListShareGroup(command.Lister):
|
||||
"""List share groups."""
|
||||
_description = _("List share groups")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ListShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"--all-projects",
|
||||
action='store_true',
|
||||
default=False,
|
||||
help=_("Display snapshots from all projects (Admin only).")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--name",
|
||||
metavar="<name>",
|
||||
default=None,
|
||||
help=_("Filter results by name.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--description",
|
||||
metavar="<description>",
|
||||
default=None,
|
||||
help=_("Filter results by description. Available "
|
||||
"only for microversion >= 2.36.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--status",
|
||||
metavar="<status>",
|
||||
default=None,
|
||||
help=_("Filter results by status.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-server-id",
|
||||
metavar="<share-server-id>",
|
||||
default=None,
|
||||
help=_("Filter results by share server ID.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-group-type",
|
||||
metavar="<share-group-type>",
|
||||
default=None,
|
||||
help=_("Filter results by a share group type ID "
|
||||
"or name that was used for share group "
|
||||
"creation. ")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--snapshot",
|
||||
metavar="<snapshot>",
|
||||
default=None,
|
||||
help=_("Filter results by share group snapshot "
|
||||
"name or ID that was used to create the "
|
||||
"share group. ")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--host",
|
||||
metavar="<host>",
|
||||
default=None,
|
||||
help=_("Filter results by host.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--share-network",
|
||||
metavar="<share-network>",
|
||||
default=None,
|
||||
help=_("Filter results by share-network name or "
|
||||
"ID. ")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--project-id",
|
||||
metavar="<project-id>",
|
||||
default=None,
|
||||
help=_("Filter results by project ID. Useful with "
|
||||
"set key '--all-projects'. ")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--limit",
|
||||
metavar="<limit>",
|
||||
type=int,
|
||||
default=None,
|
||||
action=parseractions.NonNegativeAction,
|
||||
help=_("Limit the number of share groups returned")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--marker",
|
||||
metavar="<marker>",
|
||||
help=_("The last share group ID of the previous page")
|
||||
)
|
||||
parser.add_argument(
|
||||
'--sort',
|
||||
metavar="<key>[:<direction>]",
|
||||
default='name:asc',
|
||||
help=_("Sort output by selected keys and directions(asc or desc) "
|
||||
"(default: name:asc), multiple keys and directions can be "
|
||||
"specified separated by comma")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--name~",
|
||||
metavar="<name~>",
|
||||
default=None,
|
||||
help=_("Filter results matching a share group "
|
||||
"name pattern. Available only for "
|
||||
"microversion >= 2.36. ")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--description~",
|
||||
metavar="<description~>",
|
||||
default=None,
|
||||
help=_("Filter results matching a share group "
|
||||
"name pattern. Available only for "
|
||||
"microversion >= 2.36. ")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
identity_client = self.app.client_manager.identity
|
||||
|
||||
share_server_id = None
|
||||
if parsed_args.share_server_id:
|
||||
share_server_id = osc_utils.find_resource(
|
||||
share_client.share_servers,
|
||||
parsed_args.share_server).id
|
||||
|
||||
share_group_type = None
|
||||
if parsed_args.share_group_type:
|
||||
share_group_type = osc_utils.find_resource(
|
||||
share_client.share_group_types,
|
||||
parsed_args.share_group_type).id
|
||||
|
||||
snapshot = None
|
||||
if parsed_args.snapshot:
|
||||
snapshot = apiutils.find_resource(
|
||||
share_client.share_snapshots,
|
||||
parsed_args.snapshot).id
|
||||
|
||||
share_network = None
|
||||
if parsed_args.share_network:
|
||||
share_network = osc_utils.find_resource(
|
||||
share_client.share_networks,
|
||||
parsed_args.share_network).id
|
||||
|
||||
project_id = None
|
||||
if parsed_args.project_id:
|
||||
project_id = identity_common.find_project(
|
||||
identity_client,
|
||||
parsed_args.project,
|
||||
parsed_args.project_domain).id
|
||||
|
||||
columns = [
|
||||
'ID',
|
||||
'Name',
|
||||
'Status',
|
||||
'Description',
|
||||
]
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': parsed_args.all_projects,
|
||||
'name': parsed_args.name,
|
||||
'status': parsed_args.status,
|
||||
'share_server_id': share_server_id,
|
||||
'share_group_type': share_group_type,
|
||||
'snapshot': snapshot,
|
||||
'host': parsed_args.host,
|
||||
'share_network': share_network,
|
||||
'project_id': project_id,
|
||||
'limit': parsed_args.limit,
|
||||
'offset': parsed_args.marker,
|
||||
}
|
||||
|
||||
if share_client.api_version >= api_versions.APIVersion("2.36"):
|
||||
search_opts['name~'] = getattr(parsed_args, 'name~')
|
||||
search_opts['description~'] = getattr(parsed_args, 'description~')
|
||||
search_opts['description'] = parsed_args.description
|
||||
elif (parsed_args.description or getattr(parsed_args, 'name~') or
|
||||
getattr(parsed_args, 'description~')):
|
||||
raise exceptions.CommandError(
|
||||
"Pattern based filtering (name~, description~ and description)"
|
||||
" is only available with manila API version >= 2.36")
|
||||
|
||||
if parsed_args.all_projects:
|
||||
columns.append('Project ID')
|
||||
share_groups = share_client.share_groups.list(search_opts=search_opts)
|
||||
|
||||
data = (osc_utils.get_dict_properties(
|
||||
share_group._info, columns) for share_group in share_groups)
|
||||
|
||||
return (columns, data)
|
||||
|
||||
|
||||
class ShowShareGroup(command.ShowOne):
|
||||
"""Show share groups."""
|
||||
_description = _("Show details about a share groups")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(ShowShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
"share_group",
|
||||
metavar="<share-group>",
|
||||
help=_("Name or ID of the share group.")
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
|
||||
share_group = osc_utils.find_resource(
|
||||
share_client.share_groups,
|
||||
parsed_args.share_group)
|
||||
|
||||
printable_share_group = share_group._info
|
||||
printable_share_group.pop('links', None)
|
||||
|
||||
if printable_share_group.get('share_types'):
|
||||
if parsed_args.formatter == 'table':
|
||||
printable_share_group['share_types'] = "\n".join(
|
||||
printable_share_group['share_types'])
|
||||
|
||||
return self.dict2columns(printable_share_group)
|
||||
|
||||
|
||||
class SetShareGroup(command.Command):
|
||||
"""Set share group."""
|
||||
_description = _("Explicitly set share group status")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(SetShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'share_group',
|
||||
metavar="<share-group>",
|
||||
help=_('Name or ID of the share group to update.')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--name',
|
||||
metavar="<name>",
|
||||
default=None,
|
||||
help=_('New name for the share group. (Default=None)')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--description',
|
||||
metavar='<description>',
|
||||
default=None,
|
||||
help=_('Share group description. (Default=None)')
|
||||
)
|
||||
parser.add_argument(
|
||||
'--status',
|
||||
metavar='<status>',
|
||||
default=None,
|
||||
help=_('Explicitly update the status of a share group (Admin '
|
||||
'only). Examples include: available, error, creating, '
|
||||
'deleting, error_deleting.')
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
result = 0
|
||||
|
||||
share_group = osc_utils.find_resource(
|
||||
share_client.share_groups,
|
||||
parsed_args.share_group)
|
||||
|
||||
kwargs = {}
|
||||
if parsed_args.name is not None:
|
||||
kwargs['name'] = parsed_args.name
|
||||
if parsed_args.description is not None:
|
||||
kwargs['description'] = parsed_args.description
|
||||
if kwargs:
|
||||
try:
|
||||
share_client.share_groups.update(
|
||||
share_group.id,
|
||||
**kwargs
|
||||
)
|
||||
except Exception as e:
|
||||
LOG.error(_("Failed to update share group name "
|
||||
"or description: %s"), e)
|
||||
result += 1
|
||||
if parsed_args.status:
|
||||
try:
|
||||
share_group.reset_state(parsed_args.status)
|
||||
except Exception as e:
|
||||
LOG.error(_(
|
||||
"Failed to set status for the share group: %s"), e)
|
||||
result += 1
|
||||
|
||||
if result > 0:
|
||||
raise exceptions.CommandError(_("One or more of the "
|
||||
"set operations failed"))
|
||||
|
||||
|
||||
class UnsetShareGroup(command.Command):
|
||||
"""Unset a share group property."""
|
||||
_description = _("Unset a share group property")
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(UnsetShareGroup, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'share_group',
|
||||
metavar="<share-group>",
|
||||
help=_("Name or ID of the share group "
|
||||
"to set a property for.")
|
||||
)
|
||||
parser.add_argument(
|
||||
"--name",
|
||||
action='store_true',
|
||||
help=_("Unset share group name."),
|
||||
)
|
||||
parser.add_argument(
|
||||
"--description",
|
||||
action='store_true',
|
||||
help=_("Unset share group description."),
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
share_client = self.app.client_manager.share
|
||||
|
||||
share_group = osc_utils.find_resource(
|
||||
share_client.share_groups,
|
||||
parsed_args.share_group)
|
||||
|
||||
kwargs = {}
|
||||
if parsed_args.name:
|
||||
kwargs['name'] = None
|
||||
if parsed_args.description:
|
||||
kwargs['description'] = None
|
||||
if kwargs:
|
||||
try:
|
||||
share_client.share_groups.update(
|
||||
share_group,
|
||||
**kwargs
|
||||
)
|
||||
except Exception as e:
|
||||
raise exceptions.CommandError(_(
|
||||
"Failed to unset share_group name "
|
||||
"or description : %s" % e))
|
@ -31,6 +31,7 @@ class FakeShareClient(object):
|
||||
self.management_url = kwargs['endpoint']
|
||||
self.shares = mock.Mock()
|
||||
self.share_access_rules = mock.Mock()
|
||||
self.share_groups = mock.Mock()
|
||||
self.share_types = mock.Mock()
|
||||
self.share_type_access = mock.Mock()
|
||||
self.quotas = mock.Mock()
|
||||
@ -1091,3 +1092,62 @@ class FakeShareNetwork(object):
|
||||
FakeShareNetwork.create_one_share_network(attrs))
|
||||
|
||||
return share_networks
|
||||
|
||||
|
||||
class FakeShareGroup(object):
|
||||
"""Fake a share group"""
|
||||
|
||||
@staticmethod
|
||||
def create_one_share_group(attrs=None, methods=None):
|
||||
"""Create a fake share group
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:return:
|
||||
A FakeResource object, with project_id, resource and so on
|
||||
"""
|
||||
|
||||
attrs = attrs or {}
|
||||
methods = methods or {}
|
||||
|
||||
share_group = {
|
||||
"id": 'share-group-id-' + uuid.uuid4().hex,
|
||||
'name': None,
|
||||
'created_at': datetime.datetime.now().isoformat(),
|
||||
'status': 'available',
|
||||
'description': None,
|
||||
'availability_zone': None,
|
||||
"project_id": 'project-id-' + uuid.uuid4().hex,
|
||||
'host': None,
|
||||
'share_group_type_id': 'share-group-type-id-' + uuid.uuid4().hex,
|
||||
'source_share_group_snapshot_id': None,
|
||||
'share_network_id': None,
|
||||
'share_server_id': None,
|
||||
'share_types': ['share-types-id-' + uuid.uuid4().hex],
|
||||
'consistent_snapshot_support': None
|
||||
}
|
||||
|
||||
share_group.update(attrs)
|
||||
share_group = osc_fakes.FakeResource(info=copy.deepcopy(
|
||||
share_group),
|
||||
methods=methods,
|
||||
loaded=True)
|
||||
return share_group
|
||||
|
||||
@staticmethod
|
||||
def create_share_groups(attrs=None, count=2):
|
||||
"""Create multiple fake groups.
|
||||
|
||||
:param Dictionary attrs:
|
||||
A dictionary with all attributes
|
||||
:param Integer count:
|
||||
The number of share groups to be faked
|
||||
:return:
|
||||
A list of FakeResource objects
|
||||
"""
|
||||
|
||||
share_groups = []
|
||||
for n in range(0, count):
|
||||
share_groups.append(
|
||||
FakeShareGroup.create_one_share_group(attrs))
|
||||
return share_groups
|
||||
|
803
manilaclient/tests/unit/osc/v2/test_share_groups.py
Normal file
803
manilaclient/tests/unit/osc/v2/test_share_groups.py
Normal file
@ -0,0 +1,803 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import argparse
|
||||
from unittest import mock
|
||||
import uuid
|
||||
|
||||
from osc_lib import exceptions
|
||||
from osc_lib import exceptions as osc_exceptions
|
||||
|
||||
from osc_lib import utils as oscutils
|
||||
|
||||
from manilaclient.osc import utils
|
||||
|
||||
from manilaclient import api_versions
|
||||
|
||||
from manilaclient.osc.v2 import share_groups as osc_share_groups
|
||||
|
||||
from manilaclient.tests.unit.osc.v2 import fakes as manila_fakes
|
||||
|
||||
|
||||
class TestShareGroup(manila_fakes.TestShare):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroup, self).setUp()
|
||||
|
||||
self.groups_mock = self.app.client_manager.share.share_groups
|
||||
self.groups_mock.reset_mock()
|
||||
|
||||
self.share_types_mock = self.app.client_manager.share.share_types
|
||||
self.share_types_mock.reset_mock()
|
||||
|
||||
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||
api_versions.MAX_VERSION)
|
||||
|
||||
|
||||
class TestShareGroupCreate(TestShareGroup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupCreate, self).setUp()
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group()
|
||||
)
|
||||
self.formatted_result = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group(
|
||||
attrs={
|
||||
"id": self.share_group.id,
|
||||
'created_at': self.share_group.created_at,
|
||||
"project_id": self.share_group.project_id,
|
||||
'share_group_type_id': (
|
||||
self.share_group.share_group_type_id),
|
||||
'share_types': '\n'.join(self.share_group.share_types)
|
||||
}))
|
||||
|
||||
self.groups_mock.create.return_value = self.share_group
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.cmd = osc_share_groups.CreateShareGroup(self.app, None)
|
||||
|
||||
self.data = tuple(self.formatted_result._info.values())
|
||||
self.columns = tuple(self.share_group._info.keys())
|
||||
|
||||
def test_share_group_create_no_args(self):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.create.assert_called_with(
|
||||
name=None,
|
||||
description=None,
|
||||
share_types=[],
|
||||
share_group_type=None,
|
||||
share_network=None,
|
||||
source_share_group_snapshot=None,
|
||||
availability_zone=None
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_share_group_create_with_options(self):
|
||||
arglist = [
|
||||
'--name', self.share_group.name,
|
||||
'--description', self.share_group.description
|
||||
]
|
||||
verifylist = [
|
||||
('name', self.share_group.name),
|
||||
('description', self.share_group.description)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.create.assert_called_with(
|
||||
name=self.share_group.name,
|
||||
description=self.share_group.description,
|
||||
share_types=[],
|
||||
share_group_type=None,
|
||||
share_network=None,
|
||||
source_share_group_snapshot=None,
|
||||
availability_zone=None
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_share_group_create_az(self):
|
||||
arglist = [
|
||||
'--availability-zone', self.share_group.availability_zone
|
||||
]
|
||||
verifylist = [
|
||||
('availability_zone', self.share_group.availability_zone)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.create.assert_called_with(
|
||||
name=None,
|
||||
description=None,
|
||||
share_types=[],
|
||||
share_group_type=None,
|
||||
share_network=None,
|
||||
source_share_group_snapshot=None,
|
||||
availability_zone=self.share_group.availability_zone
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_share_group_create_share_types(self):
|
||||
|
||||
share_types = manila_fakes.FakeShareType.create_share_types(count=2)
|
||||
self.share_types_mock.get = manila_fakes.FakeShareType.get_share_types(
|
||||
share_types)
|
||||
arglist = [
|
||||
'--share-types', share_types[0].id, share_types[1].id
|
||||
]
|
||||
verifylist = [
|
||||
('share_types', [share_types[0].id, share_types[1].id])
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.create.assert_called_with(
|
||||
name=None,
|
||||
description=None,
|
||||
share_types=share_types,
|
||||
share_group_type=None,
|
||||
share_network=None,
|
||||
source_share_group_snapshot=None,
|
||||
availability_zone=None
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
def test_share_group_create_wait(self):
|
||||
arglist = [
|
||||
'--wait'
|
||||
]
|
||||
verifylist = [
|
||||
('wait', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.create.assert_called_with(
|
||||
name=None,
|
||||
description=None,
|
||||
share_types=[],
|
||||
share_group_type=None,
|
||||
share_network=None,
|
||||
source_share_group_snapshot=None,
|
||||
availability_zone=None
|
||||
)
|
||||
|
||||
self.groups_mock.get.assert_called_with(self.share_group.id)
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
# TODO(archanaserver): Add test cases for share-group-type,
|
||||
# share-network and source-share-group-snapshot when the
|
||||
# options have OSC support.
|
||||
|
||||
|
||||
class TestShareGroupDelete(TestShareGroup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupDelete, self).setUp()
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group())
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.cmd = osc_share_groups.DeleteShareGroup(self.app, None)
|
||||
|
||||
def test_share_group_delete(self):
|
||||
arglist = [
|
||||
self.share_group.id
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [self.share_group.id])
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.delete.assert_called_with(
|
||||
self.share_group,
|
||||
force=False)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_group_delete_force(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--force'
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [self.share_group.id]),
|
||||
('force', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.delete.assert_called_with(
|
||||
self.share_group,
|
||||
force=True)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_group_delete_multiple(self):
|
||||
share_groups = (
|
||||
manila_fakes.FakeShareGroup.create_share_groups(
|
||||
count=2))
|
||||
arglist = [
|
||||
share_groups[0].id,
|
||||
share_groups[1].id
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [share_groups[0].id, share_groups[1].id])
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.assertEqual(self.groups_mock.delete.call_count,
|
||||
len(share_groups))
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_group_delete_exception(self):
|
||||
arglist = [
|
||||
self.share_group.id
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [self.share_group.id])
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.groups_mock.delete.side_effect = exceptions.CommandError()
|
||||
self.assertRaises(exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_share_group_delete_wait(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--wait'
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [self.share_group.id]),
|
||||
('wait', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
with mock.patch('osc_lib.utils.wait_for_delete', return_value=True):
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.delete.assert_called_with(
|
||||
self.share_group,
|
||||
force=False)
|
||||
self.groups_mock.get.assert_called_with(self.share_group.id)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_group_delete_wait_exception(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--wait'
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', [self.share_group.id]),
|
||||
('wait', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
with mock.patch('osc_lib.utils.wait_for_delete', return_value=False):
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args
|
||||
)
|
||||
|
||||
|
||||
class TestShareGroupShow(TestShareGroup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupShow, self).setUp()
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group()
|
||||
)
|
||||
self.formatted_result = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group(
|
||||
attrs={
|
||||
"id": self.share_group.id,
|
||||
'created_at': self.share_group.created_at,
|
||||
"project_id": self.share_group.project_id,
|
||||
'share_group_type_id': (
|
||||
self.share_group.share_group_type_id),
|
||||
'share_types': '\n'.join(self.share_group.share_types)
|
||||
}))
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.data = tuple(self.formatted_result._info.values())
|
||||
self.columns = tuple(self.share_group._info.keys())
|
||||
|
||||
self.cmd = osc_share_groups.ShowShareGroup(self.app, None)
|
||||
|
||||
def test_share_group_show(self):
|
||||
arglist = [
|
||||
self.share_group.id
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.get.assert_called_with(
|
||||
self.share_group.id
|
||||
)
|
||||
|
||||
self.assertCountEqual(self.columns, columns)
|
||||
self.assertCountEqual(self.data, data)
|
||||
|
||||
|
||||
class TestShareGroupSet(TestShareGroup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupSet, self).setUp()
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group()
|
||||
)
|
||||
self.share_group = manila_fakes.FakeShare.create_one_share(
|
||||
methods={"reset_state": None}
|
||||
)
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.cmd = osc_share_groups.SetShareGroup(self.app, None)
|
||||
|
||||
def test_set_share_group_name(self):
|
||||
new_name = uuid.uuid4().hex
|
||||
arglist = [
|
||||
'--name', new_name,
|
||||
self.share_group.id,
|
||||
]
|
||||
verifylist = [
|
||||
('name', new_name),
|
||||
('share_group', self.share_group.id)
|
||||
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.groups_mock.update.assert_called_with(
|
||||
self.share_group.id,
|
||||
name=parsed_args.name)
|
||||
|
||||
def test_set_share_group_description(self):
|
||||
new_description = uuid.uuid4().hex
|
||||
arglist = [
|
||||
'--description', new_description,
|
||||
self.share_group.id,
|
||||
]
|
||||
verifylist = [
|
||||
('description', new_description),
|
||||
('share_group', self.share_group.id),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.cmd.take_action(parsed_args)
|
||||
self.groups_mock.update.assert_called_with(
|
||||
self.share_group.id,
|
||||
description=parsed_args.description)
|
||||
|
||||
def test_share_group_set_status(self):
|
||||
new_status = 'available'
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--status', new_status
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id),
|
||||
('status', new_status)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.share_group.reset_state.assert_called_with(new_status)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_share_group_set_status_exception(self):
|
||||
new_status = 'available'
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--status', new_status
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id),
|
||||
('status', new_status)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.share_group.reset_state.side_effect = Exception()
|
||||
self.assertRaises(
|
||||
osc_exceptions.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
|
||||
class TestShareGroupUnset(TestShareGroup):
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupUnset, self).setUp()
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group()
|
||||
)
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.cmd = osc_share_groups.UnsetShareGroup(self.app, None)
|
||||
|
||||
def test_unset_share_group_name(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--name'
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id),
|
||||
('name', True)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.update.assert_called_with(
|
||||
self.share_group,
|
||||
name=None)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_unset_share_group_description(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--description'
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id),
|
||||
('description', True)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.update.assert_called_with(
|
||||
self.share_group,
|
||||
description=None)
|
||||
self.assertIsNone(result)
|
||||
|
||||
def test_unset_share_group_name_exception(self):
|
||||
arglist = [
|
||||
self.share_group.id,
|
||||
'--name',
|
||||
]
|
||||
verifylist = [
|
||||
('share_group', self.share_group.id),
|
||||
('name', True),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.groups_mock.update.side_effect = Exception()
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
|
||||
class TestShareGroupList(TestShareGroup):
|
||||
|
||||
columns = [
|
||||
'id',
|
||||
'name',
|
||||
'status',
|
||||
'description'
|
||||
]
|
||||
|
||||
column_headers = utils.format_column_headers(columns)
|
||||
|
||||
def setUp(self):
|
||||
super(TestShareGroupList, self).setUp()
|
||||
|
||||
self.new_share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group()
|
||||
)
|
||||
self.groups_mock.list.return_value = [self.new_share_group]
|
||||
|
||||
self.share_group = (
|
||||
manila_fakes.FakeShareGroup.create_one_share_group())
|
||||
self.groups_mock.get.return_value = self.share_group
|
||||
|
||||
self.share_groups_list = (
|
||||
manila_fakes.FakeShareGroup.create_share_groups(
|
||||
count=2))
|
||||
self.groups_mock.list.return_value = self.share_groups_list
|
||||
|
||||
self.values = (oscutils.get_dict_properties(
|
||||
s._info, self.columns) for s in self.share_groups_list)
|
||||
|
||||
self.cmd = osc_share_groups.ListShareGroup(self.app, None)
|
||||
|
||||
def test_share_group_list(self):
|
||||
arglist = []
|
||||
verifylist = []
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.list.assert_called_with(search_opts={
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': None,
|
||||
'offset': None,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
})
|
||||
|
||||
self.assertEqual(self.column_headers, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_list_share_group_api_version_exception(self):
|
||||
self.app.client_manager.share.api_version = api_versions.APIVersion(
|
||||
"2.35")
|
||||
|
||||
arglist = [
|
||||
'--description', 'Description'
|
||||
]
|
||||
verifylist = [
|
||||
('description', 'Description')
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.CommandError,
|
||||
self.cmd.take_action,
|
||||
parsed_args)
|
||||
|
||||
def test_list_share_groups_all_projects(self):
|
||||
all_tenants_list = self.column_headers.copy()
|
||||
all_tenants_list.append('Project ID')
|
||||
list_values = (oscutils.get_dict_properties(
|
||||
s._info, all_tenants_list) for s in self.share_groups_list)
|
||||
|
||||
arglist = [
|
||||
'--all-projects'
|
||||
]
|
||||
|
||||
verifylist = [
|
||||
('all_projects', True)
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
self.groups_mock.list.assert_called_with(search_opts={
|
||||
'all_tenants': True,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': None,
|
||||
'offset': None,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
})
|
||||
|
||||
self.assertEqual(all_tenants_list, columns)
|
||||
self.assertEqual(list(list_values), list(data))
|
||||
|
||||
def test_share_group_list_name(self):
|
||||
arglist = [
|
||||
'--name', self.new_share_group.name
|
||||
]
|
||||
verifylist = [
|
||||
('name', self.new_share_group.name)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': None,
|
||||
'offset': None,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
}
|
||||
|
||||
search_opts['name'] = self.new_share_group.name
|
||||
|
||||
self.groups_mock.list.assert_called_once_with(
|
||||
search_opts=search_opts,
|
||||
)
|
||||
|
||||
self.assertEqual(self.column_headers, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_share_group_list_description(self):
|
||||
arglist = [
|
||||
'--description', self.new_share_group.description
|
||||
]
|
||||
verifylist = [
|
||||
('description', self.new_share_group.description)
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': None,
|
||||
'offset': None,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
}
|
||||
|
||||
search_opts['description'] = self.new_share_group.description
|
||||
|
||||
self.groups_mock.list.assert_called_once_with(
|
||||
search_opts=search_opts,
|
||||
)
|
||||
|
||||
self.assertEqual(self.column_headers, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_share_group_list_status(self):
|
||||
arglist = [
|
||||
'--status', self.new_share_group.status,
|
||||
]
|
||||
verifylist = [
|
||||
('status', self.new_share_group.status),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': None,
|
||||
'offset': None,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
}
|
||||
|
||||
search_opts['status'] = self.new_share_group.status
|
||||
|
||||
self.groups_mock.list.assert_called_once_with(
|
||||
search_opts=search_opts,
|
||||
)
|
||||
|
||||
self.assertEqual(self.column_headers, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_share_group_list_marker_and_limit(self):
|
||||
arglist = [
|
||||
"--marker", self.new_share_group.id,
|
||||
"--limit", "2",
|
||||
]
|
||||
verifylist = [
|
||||
('marker', self.new_share_group.id),
|
||||
('limit', 2),
|
||||
]
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': False,
|
||||
'name': None,
|
||||
'status': None,
|
||||
'share_server_id': None,
|
||||
'share_group_type': None,
|
||||
'snapshot': None,
|
||||
'host': None,
|
||||
'share_network': None,
|
||||
'project_id': None,
|
||||
'limit': 2,
|
||||
'offset': self.new_share_group.id,
|
||||
'name~': None,
|
||||
'description~': None,
|
||||
'description': None
|
||||
}
|
||||
|
||||
self.groups_mock.list.assert_called_once_with(
|
||||
search_opts=search_opts,
|
||||
)
|
||||
|
||||
self.assertEqual(self.column_headers, columns)
|
||||
self.assertEqual(list(self.values), list(data))
|
||||
|
||||
def test_share_group_list_negative_limit(self):
|
||||
arglist = [
|
||||
"--limit", "-2",
|
||||
]
|
||||
verifylist = [
|
||||
("limit", -2),
|
||||
]
|
||||
self.assertRaises(argparse.ArgumentTypeError, self.check_parser,
|
||||
self.cmd, arglist, verifylist)
|
||||
|
||||
# TODO(archanaserver): Add test cases for share-server-id,
|
||||
# share-group-type, snapshot, share-network and source-
|
||||
# share-group-share_group when the options have OSC support.
|
@ -113,6 +113,12 @@ openstack.share.v2 =
|
||||
share_network_delete = manilaclient.osc.v2.share_networks:DeleteShareNetwork
|
||||
share_network_set = manilaclient.osc.v2.share_networks:SetShareNetwork
|
||||
share_network_unset = manilaclient.osc.v2.share_networks:UnsetShareNetwork
|
||||
share_group_create = manilaclient.osc.v2.share_groups:CreateShareGroup
|
||||
share_group_delete = manilaclient.osc.v2.share_groups:DeleteShareGroup
|
||||
share_group_list = manilaclient.osc.v2.share_groups:ListShareGroup
|
||||
share_group_show = manilaclient.osc.v2.share_groups:ShowShareGroup
|
||||
share_group_set = manilaclient.osc.v2.share_groups:SetShareGroup
|
||||
share_group_unset = manilaclient.osc.v2.share_groups:UnsetShareGroup
|
||||
|
||||
[coverage:run]
|
||||
omit = manilaclient/tests/*
|
||||
|
Loading…
Reference in New Issue
Block a user