[OSC] Add Share Snapshot Instances commands
In this patch we add the following openstack share commands: share snapshot instance list share snapshot instance show share snapshot instance set --status share snapshot instance export location list share snapshot instance export location show Partially-implements: bp openstack-client-support Co-Authored-By: Caique Mello <caiquemellosbo@gmail.com> Change-Id: I7feb6219b0c684d2e88d0d077f776bfb331e3955
This commit is contained in:
@@ -73,7 +73,14 @@ share snapshots
|
|||||||
===============
|
===============
|
||||||
|
|
||||||
.. autoprogram-cliff:: openstack.share.v2
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
:command: share snapshot *
|
:command: share snapshot [!i]*
|
||||||
|
|
||||||
|
========================
|
||||||
|
share snapshot instances
|
||||||
|
========================
|
||||||
|
|
||||||
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
|
:command: share snapshot instance *
|
||||||
|
|
||||||
===============
|
===============
|
||||||
user messages
|
user messages
|
||||||
|
@@ -0,0 +1,93 @@
|
|||||||
|
# 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.command import command
|
||||||
|
from osc_lib import utils
|
||||||
|
|
||||||
|
from manilaclient.common._i18n import _
|
||||||
|
from manilaclient.common.apiclient import utils as apiutils
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ShareSnapshotInstanceExportLocationList(command.Lister):
|
||||||
|
"""List export locations from a share snapshot instance."""
|
||||||
|
_description = _("List export locations from a share snapshot instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = (
|
||||||
|
super(ShareSnapshotInstanceExportLocationList, self).get_parser(
|
||||||
|
prog_name))
|
||||||
|
parser.add_argument(
|
||||||
|
"instance",
|
||||||
|
metavar="<instance>",
|
||||||
|
help=_("Name or ID of the share instance.")
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
|
||||||
|
snapshot_instance = apiutils.find_resource(
|
||||||
|
share_client.share_snapshot_instances, parsed_args.instance)
|
||||||
|
|
||||||
|
share_snapshot_instance_export_locations = (
|
||||||
|
share_client.share_snapshot_instance_export_locations.list(
|
||||||
|
snapshot_instance=snapshot_instance))
|
||||||
|
|
||||||
|
columns = ["ID", "Path", "Is Admin only"]
|
||||||
|
|
||||||
|
return (
|
||||||
|
columns,
|
||||||
|
(utils.get_item_properties(s, columns) for s in
|
||||||
|
share_snapshot_instance_export_locations))
|
||||||
|
|
||||||
|
|
||||||
|
class ShareSnapshotInstanceExportLocationShow(command.ShowOne):
|
||||||
|
"""Show export location of the share snapshot instance."""
|
||||||
|
_description = _("Show export location of the share snapshot instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = (
|
||||||
|
super(ShareSnapshotInstanceExportLocationShow, self).get_parser(
|
||||||
|
prog_name))
|
||||||
|
parser.add_argument(
|
||||||
|
'snapshot_instance',
|
||||||
|
metavar='<snapshot_instance>',
|
||||||
|
help=_('ID of the share snapshot instance.')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'export_location',
|
||||||
|
metavar='<export_location>',
|
||||||
|
help=_('ID of the share snapshot instance export location.')
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
|
||||||
|
snapshot_instance = apiutils.find_resource(
|
||||||
|
share_client.share_snapshot_instances,
|
||||||
|
parsed_args.snapshot_instance)
|
||||||
|
|
||||||
|
share_snapshot_instance_export_location = (
|
||||||
|
share_client.share_snapshot_instance_export_locations.get(
|
||||||
|
parsed_args.export_location,
|
||||||
|
snapshot_instance=snapshot_instance))
|
||||||
|
|
||||||
|
share_snapshot_instance_export_location._info.pop('links', None)
|
||||||
|
|
||||||
|
return self.dict2columns(share_snapshot_instance_export_location._info)
|
141
manilaclient/osc/v2/share_snapshot_instances.py
Normal file
141
manilaclient/osc/v2/share_snapshot_instances.py
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
# 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.command import command
|
||||||
|
from osc_lib import exceptions
|
||||||
|
from osc_lib import utils
|
||||||
|
|
||||||
|
from manilaclient.common._i18n import _
|
||||||
|
from manilaclient.common import cliutils
|
||||||
|
|
||||||
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class ListShareSnapshotInstance(command.Lister):
|
||||||
|
"""List all share snapshot instances."""
|
||||||
|
_description = _("List all share snapshot instances")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ListShareSnapshotInstance, self).get_parser(
|
||||||
|
prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
"--snapshot",
|
||||||
|
metavar="<snapshot>",
|
||||||
|
default=None,
|
||||||
|
help=_("Filter results by share snapshot ID.")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--detailed",
|
||||||
|
action="store_true",
|
||||||
|
help=_("Show detailed information about snapshot instances. ")
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
snapshot = (share_client.share_snapshots.get(parsed_args.snapshot)
|
||||||
|
if parsed_args.snapshot else None)
|
||||||
|
|
||||||
|
share_snapshot_instances = share_client.share_snapshot_instances.list(
|
||||||
|
detailed=parsed_args.detailed,
|
||||||
|
snapshot=snapshot,
|
||||||
|
)
|
||||||
|
|
||||||
|
list_of_keys = ['ID', 'Snapshot ID', 'Status']
|
||||||
|
|
||||||
|
if (parsed_args.detailed):
|
||||||
|
list_of_keys += ['Created At', 'Updated At', 'Share ID',
|
||||||
|
'Share Instance ID', 'Progress',
|
||||||
|
'Provider Location']
|
||||||
|
|
||||||
|
return (list_of_keys, (utils.get_item_properties
|
||||||
|
(s, list_of_keys) for s in share_snapshot_instances))
|
||||||
|
|
||||||
|
|
||||||
|
class ShowShareSnapshotInstance(command.ShowOne):
|
||||||
|
"""Show details about a share snapshot instance."""
|
||||||
|
_description = _("Show details about a share snapshot instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShowShareSnapshotInstance, self).get_parser(
|
||||||
|
prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
"snapshot_instance",
|
||||||
|
metavar="<snapshot_instance>",
|
||||||
|
help=_("ID of the share snapshot instance.")
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
snapshot_instance = share_client.share_snapshot_instances.get(
|
||||||
|
parsed_args.snapshot_instance)
|
||||||
|
|
||||||
|
snapshot_instance_export_locations = (
|
||||||
|
share_client.share_snapshot_instance_export_locations.list(
|
||||||
|
snapshot_instance=snapshot_instance))
|
||||||
|
|
||||||
|
snapshot_instance._info['export_locations'] = []
|
||||||
|
for element_location in snapshot_instance_export_locations:
|
||||||
|
element_location._info.pop('links', None)
|
||||||
|
snapshot_instance._info['export_locations'].append(
|
||||||
|
element_location._info)
|
||||||
|
|
||||||
|
if parsed_args.formatter == 'table':
|
||||||
|
snapshot_instance._info['export_locations'] = (
|
||||||
|
cliutils.transform_export_locations_to_string_view(
|
||||||
|
snapshot_instance._info['export_locations']))
|
||||||
|
|
||||||
|
snapshot_instance._info.pop('links', None)
|
||||||
|
|
||||||
|
return self.dict2columns(snapshot_instance._info)
|
||||||
|
|
||||||
|
|
||||||
|
class SetShareSnapshotInstance(command.Command):
|
||||||
|
"""Explicitly update the state of a share snapshot instance."""
|
||||||
|
_description = _("Explicitly update the state of a share snapshot "
|
||||||
|
"instance.")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(SetShareSnapshotInstance, self).get_parser(
|
||||||
|
prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
"snapshot_instance",
|
||||||
|
metavar="<snapshot_instance>",
|
||||||
|
help=_("ID of the share snapshot instance to update.")
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--status',
|
||||||
|
metavar='<status>',
|
||||||
|
default='available',
|
||||||
|
choices=['available', 'error', 'creating', 'deleting',
|
||||||
|
'error_deleting'],
|
||||||
|
help=_('Indicate state to update the snapshot instance to. '
|
||||||
|
'Default is available.')
|
||||||
|
)
|
||||||
|
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
|
||||||
|
try:
|
||||||
|
share_client.share_snapshot_instances.reset_state(
|
||||||
|
parsed_args.snapshot_instance, parsed_args.status)
|
||||||
|
except Exception as e:
|
||||||
|
msg = _(
|
||||||
|
"Failed to update share snapshot instance status: %s" % e)
|
||||||
|
raise exceptions.CommandError(msg)
|
@@ -36,9 +36,11 @@ class FakeShareClient(object):
|
|||||||
self.quotas = mock.Mock()
|
self.quotas = mock.Mock()
|
||||||
self.share_snapshots = mock.Mock()
|
self.share_snapshots = mock.Mock()
|
||||||
self.share_snapshot_export_locations = mock.Mock()
|
self.share_snapshot_export_locations = mock.Mock()
|
||||||
|
self.share_snapshot_instances = mock.Mock()
|
||||||
self.share_replicas = mock.Mock()
|
self.share_replicas = mock.Mock()
|
||||||
self.shares.resource_class = osc_fakes.FakeResource(None, {})
|
self.shares.resource_class = osc_fakes.FakeResource(None, {})
|
||||||
self.share_export_locations = mock.Mock()
|
self.share_export_locations = mock.Mock()
|
||||||
|
self.share_snapshot_instance_export_locations = mock.Mock()
|
||||||
self.share_export_locations.resource_class = (
|
self.share_export_locations.resource_class = (
|
||||||
osc_fakes.FakeResource(None, {}))
|
osc_fakes.FakeResource(None, {}))
|
||||||
self.messages = mock.Mock()
|
self.messages = mock.Mock()
|
||||||
@@ -384,6 +386,109 @@ class FakeQuotaSet(object):
|
|||||||
return quotas
|
return quotas
|
||||||
|
|
||||||
|
|
||||||
|
class FakeShareSnapshotIntances(object):
|
||||||
|
"""Fake a share snapshot instance"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_one_snapshot_instance(attrs=None, methods=None):
|
||||||
|
"""Create a fake share snapshot instance
|
||||||
|
|
||||||
|
: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_snapshot_instance = {
|
||||||
|
'id': 'snapshot-instance-id-' + uuid.uuid4().hex,
|
||||||
|
'snapshot_id': 'snapshot-id-' + uuid.uuid4().hex,
|
||||||
|
'status': None,
|
||||||
|
'created_at': datetime.datetime.now().isoformat(),
|
||||||
|
'updated_at': datetime.datetime.now().isoformat(),
|
||||||
|
'share_id': 'share-id-' + uuid.uuid4().hex,
|
||||||
|
'share_instance_id': 'share-instance-id-' + uuid.uuid4().hex,
|
||||||
|
'progress': None,
|
||||||
|
'provider_location': None
|
||||||
|
}
|
||||||
|
|
||||||
|
share_snapshot_instance.update(attrs)
|
||||||
|
share_snapshot_instance = osc_fakes.FakeResource(info=copy.deepcopy(
|
||||||
|
share_snapshot_instance),
|
||||||
|
methods=methods,
|
||||||
|
loaded=True)
|
||||||
|
return share_snapshot_instance
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_share_snapshot_instances(attrs=None, count=2):
|
||||||
|
"""Create multiple fake snapshot instances.
|
||||||
|
|
||||||
|
:param Dictionary attrs:
|
||||||
|
A dictionary with all attributes
|
||||||
|
:param Integer count:
|
||||||
|
The number of share snapshot instances to be faked
|
||||||
|
:return:
|
||||||
|
A list of FakeResource objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
share_snapshot_instances = []
|
||||||
|
for n in range(0, count):
|
||||||
|
share_snapshot_instances.append(
|
||||||
|
FakeShareSnapshot.create_one_snapshot(attrs))
|
||||||
|
|
||||||
|
return share_snapshot_instances
|
||||||
|
|
||||||
|
|
||||||
|
class FakeShareSnapshotInstancesExportLocations(object):
|
||||||
|
"""Fake a share snapshot instance Export Locations"""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_one_snapshot_instance(attrs=None, methods=None):
|
||||||
|
"""Create a fake share snapshot instance export locations
|
||||||
|
|
||||||
|
: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_snapshot_instance_export_location = {
|
||||||
|
'id': 'snapshot-instance-export-location-id-' + uuid.uuid4().hex,
|
||||||
|
'is_admin_only': False,
|
||||||
|
'path': '0.0.0.0/:fake-share-instance-export-location-id',
|
||||||
|
}
|
||||||
|
|
||||||
|
share_snapshot_instance_export_location.update(attrs)
|
||||||
|
share_snapshot_instance_export_location = osc_fakes.FakeResource(
|
||||||
|
info=copy.deepcopy(
|
||||||
|
share_snapshot_instance_export_location),
|
||||||
|
methods=methods,
|
||||||
|
loaded=True)
|
||||||
|
return share_snapshot_instance_export_location
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def create_share_snapshot_instances(attrs=None, count=2):
|
||||||
|
"""Create multiple fake snapshot instances.
|
||||||
|
|
||||||
|
:param Dictionary attrs:
|
||||||
|
A dictionary with all attributes
|
||||||
|
:param Integer count:
|
||||||
|
The number of share snapshot instance locations to be faked
|
||||||
|
:return:
|
||||||
|
A list of FakeResource objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
share_snapshot_instances = []
|
||||||
|
for n in range(0, count):
|
||||||
|
share_snapshot_instances.append(
|
||||||
|
FakeShareSnapshot.create_one_snapshot(attrs))
|
||||||
|
|
||||||
|
return share_snapshot_instances
|
||||||
|
|
||||||
|
|
||||||
class FakeShareSnapshot(object):
|
class FakeShareSnapshot(object):
|
||||||
"""Fake a share snapshot"""
|
"""Fake a share snapshot"""
|
||||||
|
|
||||||
|
@@ -0,0 +1,149 @@
|
|||||||
|
# Copyright 2021 Red Hat Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
from osc_lib import utils as osc_lib_utils
|
||||||
|
|
||||||
|
from manilaclient.osc.v2 import (share_snapshot_instance_export_locations as
|
||||||
|
osc_snapshot_instance_locations)
|
||||||
|
from manilaclient.tests.unit.osc import osc_utils
|
||||||
|
from manilaclient.tests.unit.osc.v2 import fakes as manila_fakes
|
||||||
|
|
||||||
|
COLUMNS = ['ID', 'Path', 'Is Admin only']
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceExportLocation(manila_fakes.TestShare):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceExportLocation, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock = (
|
||||||
|
self.app.client_manager.share.share_snapshot_instances)
|
||||||
|
self.share_snapshot_instances_mock.reset_mock()
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_mock = (
|
||||||
|
self.app.client_manager
|
||||||
|
.share.share_snapshot_instance_export_locations)
|
||||||
|
self.share_snapshot_instances_el_mock.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceExportLocationList(
|
||||||
|
TestShareSnapshotInstanceExportLocation):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceExportLocationList, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instance = (
|
||||||
|
manila_fakes.FakeShareSnapshotIntances
|
||||||
|
.create_one_snapshot_instance())
|
||||||
|
|
||||||
|
self.share_snapshot_instances_export_locations = (
|
||||||
|
manila_fakes.FakeShareSnapshotInstancesExportLocations
|
||||||
|
.create_share_snapshot_instances(count=2)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.get.return_value = (
|
||||||
|
self.share_snapshot_instance)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_mock.list.return_value = (
|
||||||
|
self.share_snapshot_instances_export_locations)
|
||||||
|
|
||||||
|
self.cmd = (osc_snapshot_instance_locations
|
||||||
|
.ShareSnapshotInstanceExportLocationList(self.app,
|
||||||
|
None))
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_export_location_list_missing_args(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
self.assertRaises(osc_utils.ParserException,
|
||||||
|
self.check_parser, self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_export_location_list(self):
|
||||||
|
values = (osc_lib_utils.get_dict_properties(
|
||||||
|
s._info, COLUMNS) for s in
|
||||||
|
self.share_snapshot_instances_export_locations)
|
||||||
|
arglist = [
|
||||||
|
self.share_snapshot_instance.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('instance', self.share_snapshot_instance.id)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(COLUMNS, columns)
|
||||||
|
self.assertEqual(list(values), list(data))
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceExportLocationShow(
|
||||||
|
TestShareSnapshotInstanceExportLocation):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceExportLocationShow, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instance = (
|
||||||
|
manila_fakes.FakeShareSnapshotIntances
|
||||||
|
.create_one_snapshot_instance())
|
||||||
|
|
||||||
|
self.share_snapshot_instances_export_location = (
|
||||||
|
manila_fakes.FakeShareSnapshotInstancesExportLocations
|
||||||
|
.create_one_snapshot_instance()
|
||||||
|
)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.get.return_value = (
|
||||||
|
self.share_snapshot_instance)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_mock.get.return_value = (
|
||||||
|
self.share_snapshot_instances_export_location)
|
||||||
|
|
||||||
|
self.cmd = (osc_snapshot_instance_locations
|
||||||
|
.ShareSnapshotInstanceExportLocationShow(self.app,
|
||||||
|
None))
|
||||||
|
|
||||||
|
self.data = (self.share_snapshot_instances_export_location.
|
||||||
|
_info.values())
|
||||||
|
self.columns = (self.share_snapshot_instances_export_location.
|
||||||
|
_info.keys())
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_export_location_show_missing_args(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
self.assertRaises(osc_utils.ParserException,
|
||||||
|
self.check_parser, self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_export_location_show(self):
|
||||||
|
arglist = [
|
||||||
|
self.share_snapshot_instance.id,
|
||||||
|
self.share_snapshot_instances_export_location.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('snapshot_instance', self.share_snapshot_instance.id),
|
||||||
|
('export_location',
|
||||||
|
self.share_snapshot_instances_export_location.id)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.get.assert_called_with(
|
||||||
|
self.share_snapshot_instance.id)
|
||||||
|
self.share_snapshot_instances_el_mock.get.assert_called_with(
|
||||||
|
self.share_snapshot_instances_export_location.id,
|
||||||
|
snapshot_instance=self.share_snapshot_instance)
|
||||||
|
self.assertCountEqual(self.columns, columns)
|
||||||
|
self.assertCountEqual(self.data, data)
|
240
manilaclient/tests/unit/osc/v2/test_share_snapshot_instances.py
Normal file
240
manilaclient/tests/unit/osc/v2/test_share_snapshot_instances.py
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
# Copyright 2021 Red Hat Inc. All rights reserved.
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
from osc_lib import exceptions as osc_exceptions
|
||||||
|
from osc_lib import utils as osc_lib_utils
|
||||||
|
|
||||||
|
from manilaclient.common.apiclient import exceptions as api_exceptions
|
||||||
|
from manilaclient.common import cliutils
|
||||||
|
from manilaclient.osc.v2 import (
|
||||||
|
share_snapshot_instances as osc_share_snapshot_instances)
|
||||||
|
from manilaclient.tests.unit.osc import osc_utils
|
||||||
|
from manilaclient.tests.unit.osc.v2 import fakes as manila_fakes
|
||||||
|
|
||||||
|
COLUMNS = ['ID', 'Snapshot ID', 'Status']
|
||||||
|
|
||||||
|
COLUMNS_DETAIL = [
|
||||||
|
'ID',
|
||||||
|
'Snapshot ID',
|
||||||
|
'Status',
|
||||||
|
'Created At',
|
||||||
|
'Updated At',
|
||||||
|
'Share ID',
|
||||||
|
'Share Instance ID',
|
||||||
|
'Progress',
|
||||||
|
'Provider Location'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstance(manila_fakes.TestShare):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstance, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshots_mock = (
|
||||||
|
self.app.client_manager.share.share_snapshots)
|
||||||
|
self.share_snapshots_mock.reset_mock()
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock = (
|
||||||
|
self.app.client_manager.share.share_snapshot_instances)
|
||||||
|
self.share_snapshot_instances_mock.reset_mock()
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_mock = (
|
||||||
|
self.app.client_manager
|
||||||
|
.share.share_snapshot_instance_export_locations)
|
||||||
|
self.share_snapshot_instances_el_mock.reset_mock()
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceList(TestShareSnapshotInstance):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceList, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instances = (
|
||||||
|
manila_fakes.FakeShareSnapshotIntances
|
||||||
|
.create_share_snapshot_instances(count=2))
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.list.return_value = (
|
||||||
|
self.share_snapshot_instances)
|
||||||
|
|
||||||
|
self.cmd = (
|
||||||
|
osc_share_snapshot_instances.ListShareSnapshotInstance(self.app,
|
||||||
|
None))
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_list(self):
|
||||||
|
values = (osc_lib_utils.get_dict_properties(
|
||||||
|
s._info, COLUMNS) for s in self.share_snapshot_instances)
|
||||||
|
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(COLUMNS, columns)
|
||||||
|
self.assertEqual(list(values), list(data))
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_list_detail(self):
|
||||||
|
values = (osc_lib_utils.get_dict_properties(
|
||||||
|
s._info, COLUMNS_DETAIL) for s in self.share_snapshot_instances)
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--detailed'
|
||||||
|
]
|
||||||
|
|
||||||
|
verifylist = [
|
||||||
|
('detailed', True)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(COLUMNS_DETAIL, columns)
|
||||||
|
self.assertEqual(list(values), list(data))
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_list_snapshot_id(self):
|
||||||
|
self.share_snapshot = (
|
||||||
|
manila_fakes.FakeShareSnapshot.create_one_snapshot())
|
||||||
|
|
||||||
|
self.share_snapshots_mock.get.return_value = self.share_snapshot
|
||||||
|
self.share_snapshot_instances_mock.list.return_value = (
|
||||||
|
[self.share_snapshot_instances[0]])
|
||||||
|
|
||||||
|
values = (osc_lib_utils.get_dict_properties(
|
||||||
|
s._info, COLUMNS) for s in [self.share_snapshot_instances[0]])
|
||||||
|
|
||||||
|
arglist = [
|
||||||
|
'--snapshot', self.share_snapshot.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('snapshot', self.share_snapshot.id)
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.assertEqual(COLUMNS, columns)
|
||||||
|
self.assertEqual(list(values), list(data))
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceShow(TestShareSnapshotInstance):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceShow, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instance = (
|
||||||
|
manila_fakes.FakeShareSnapshotIntances
|
||||||
|
.create_one_snapshot_instance())
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.get.return_value = (
|
||||||
|
self.share_snapshot_instance)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_list = (
|
||||||
|
manila_fakes.FakeShareSnapshotInstancesExportLocations
|
||||||
|
.create_share_snapshot_instances(count=2)
|
||||||
|
)
|
||||||
|
|
||||||
|
self.share_snapshot_instances_el_mock.list.return_value = (
|
||||||
|
self.share_snapshot_instances_el_list)
|
||||||
|
|
||||||
|
self.cmd = (osc_share_snapshot_instances
|
||||||
|
.ShowShareSnapshotInstance(self.app, None))
|
||||||
|
|
||||||
|
self.share_snapshot_instance._info['export_locations'] = (
|
||||||
|
cliutils.transform_export_locations_to_string_view(
|
||||||
|
self.share_snapshot_instances_el_list))
|
||||||
|
|
||||||
|
self.data = self.share_snapshot_instance._info.values()
|
||||||
|
self.columns = self.share_snapshot_instance._info.keys()
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_show_missing_args(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
self.assertRaises(osc_utils.ParserException,
|
||||||
|
self.check_parser, self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_show(self):
|
||||||
|
arglist = [
|
||||||
|
self.share_snapshot_instance.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('snapshot_instance', self.share_snapshot_instance.id)
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.share_snapshot_instances_mock.get.assert_called_with(
|
||||||
|
self.share_snapshot_instance.id)
|
||||||
|
self.assertCountEqual(self.columns, columns)
|
||||||
|
self.assertCountEqual(self.data, data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareSnapshotInstanceSet(TestShareSnapshotInstance):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareSnapshotInstanceSet, self).setUp()
|
||||||
|
|
||||||
|
self.share_snapshot_instance = (
|
||||||
|
manila_fakes.FakeShareSnapshotIntances
|
||||||
|
.create_one_snapshot_instance())
|
||||||
|
|
||||||
|
self.snapshot_instance_status = 'available'
|
||||||
|
|
||||||
|
self.cmd = (osc_share_snapshot_instances
|
||||||
|
.SetShareSnapshotInstance(self.app, None))
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_set_missing_args(self):
|
||||||
|
arglist = []
|
||||||
|
verifylist = []
|
||||||
|
|
||||||
|
self.assertRaises(osc_utils.ParserException,
|
||||||
|
self.check_parser, self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_set_instance_not_found(self):
|
||||||
|
arglist = [
|
||||||
|
self.share_snapshot_instance.id,
|
||||||
|
'--status', self.snapshot_instance_status
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('snapshot_instance', self.share_snapshot_instance.id),
|
||||||
|
('status', self.snapshot_instance_status)
|
||||||
|
]
|
||||||
|
|
||||||
|
self.share_snapshot_instances_mock.reset_state.side_effect = (
|
||||||
|
api_exceptions.NotFound())
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.assertRaises(osc_exceptions.CommandError,
|
||||||
|
self.cmd.take_action, parsed_args)
|
||||||
|
|
||||||
|
def test_share_snapshot_instance_set(self):
|
||||||
|
arglist = [
|
||||||
|
self.share_snapshot_instance.id,
|
||||||
|
'--status', self.snapshot_instance_status
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('snapshot_instance', self.share_snapshot_instance.id),
|
||||||
|
('status', self.snapshot_instance_status)
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.cmd.take_action(parsed_args)
|
||||||
|
self.share_snapshot_instances_mock.reset_state.assert_called_with(
|
||||||
|
self.share_snapshot_instance.id, self.snapshot_instance_status)
|
@@ -79,6 +79,11 @@ openstack.share.v2 =
|
|||||||
share_snapshot_access_list = manilaclient.osc.v2.share_snapshots:ShareSnapshotAccessList
|
share_snapshot_access_list = manilaclient.osc.v2.share_snapshots:ShareSnapshotAccessList
|
||||||
share_snapshot_export_location_list = manilaclient.osc.v2.share_snapshots:ShareSnapshotListExportLocation
|
share_snapshot_export_location_list = manilaclient.osc.v2.share_snapshots:ShareSnapshotListExportLocation
|
||||||
share_snapshot_export_location_show = manilaclient.osc.v2.share_snapshots:ShareSnapshotShowExportLocation
|
share_snapshot_export_location_show = manilaclient.osc.v2.share_snapshots:ShareSnapshotShowExportLocation
|
||||||
|
share_snapshot_instance_list = manilaclient.osc.v2.share_snapshot_instances:ListShareSnapshotInstance
|
||||||
|
share_snapshot_instance_show = manilaclient.osc.v2.share_snapshot_instances:ShowShareSnapshotInstance
|
||||||
|
share_snapshot_instance_set = manilaclient.osc.v2.share_snapshot_instances:SetShareSnapshotInstance
|
||||||
|
share_snapshot_instance_export_location_list = manilaclient.osc.v2.share_snapshot_instance_export_locations:ShareSnapshotInstanceExportLocationList
|
||||||
|
share_snapshot_instance_export_location_show = manilaclient.osc.v2.share_snapshot_instance_export_locations:ShareSnapshotInstanceExportLocationShow
|
||||||
share_message_delete = manilaclient.osc.v2.messages:DeleteMessage
|
share_message_delete = manilaclient.osc.v2.messages:DeleteMessage
|
||||||
share_message_list = manilaclient.osc.v2.messages:ListMessage
|
share_message_list = manilaclient.osc.v2.messages:ListMessage
|
||||||
share_message_show = manilaclient.osc.v2.messages:ShowMessage
|
share_message_show = manilaclient.osc.v2.messages:ShowMessage
|
||||||
|
Reference in New Issue
Block a user