Merge "[OSC] Implement Share Export Location Commands"
This commit is contained in:
@@ -35,6 +35,12 @@ shares
|
|||||||
.. autoprogram-cliff:: openstack.share.v2
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
:command: share abandon
|
:command: share abandon
|
||||||
|
|
||||||
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
|
:command: share export location show
|
||||||
|
|
||||||
|
.. autoprogram-cliff:: openstack.share.v2
|
||||||
|
:command: share export location list
|
||||||
|
|
||||||
==================
|
==================
|
||||||
share access rules
|
share access rules
|
||||||
==================
|
==================
|
||||||
|
@@ -961,3 +961,70 @@ class AbandonShare(command.Command):
|
|||||||
msg = (_("Failed to abandon %(result)s out of %(total)s shares.")
|
msg = (_("Failed to abandon %(result)s out of %(total)s shares.")
|
||||||
% {'result': result, 'total': total})
|
% {'result': result, 'total': total})
|
||||||
raise exceptions.CommandError(msg)
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
|
|
||||||
|
class ShareExportLocationShow(command.ShowOne):
|
||||||
|
"""Show export location of a share."""
|
||||||
|
|
||||||
|
_description = _("Show export location of a share")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShareExportLocationShow, self).get_parser(
|
||||||
|
prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'share',
|
||||||
|
metavar="<share>",
|
||||||
|
help=_('Name or ID of share')
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'export_location',
|
||||||
|
metavar="<export-location>",
|
||||||
|
help=_('ID of the share export location')
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
share = apiutils.find_resource(share_client.shares,
|
||||||
|
parsed_args.share)
|
||||||
|
|
||||||
|
export_location = share_client.share_export_locations.get(
|
||||||
|
share=share,
|
||||||
|
export_location=parsed_args.export_location
|
||||||
|
)
|
||||||
|
|
||||||
|
return self.dict2columns(export_location._info)
|
||||||
|
|
||||||
|
|
||||||
|
class ShareExportLocationList(command.Lister):
|
||||||
|
"""List export locations of a share."""
|
||||||
|
|
||||||
|
_description = _("List export location of a share")
|
||||||
|
|
||||||
|
def get_parser(self, prog_name):
|
||||||
|
parser = super(ShareExportLocationList, self).get_parser(
|
||||||
|
prog_name)
|
||||||
|
parser.add_argument(
|
||||||
|
'share',
|
||||||
|
metavar="<share>",
|
||||||
|
help=_('Name or ID of share')
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
def take_action(self, parsed_args):
|
||||||
|
share_client = self.app.client_manager.share
|
||||||
|
share = apiutils.find_resource(share_client.shares,
|
||||||
|
parsed_args.share)
|
||||||
|
|
||||||
|
export_locations = share_client.share_export_locations.list(
|
||||||
|
share=share
|
||||||
|
)
|
||||||
|
|
||||||
|
list_of_keys = [
|
||||||
|
'ID',
|
||||||
|
'Path',
|
||||||
|
'Preferred'
|
||||||
|
]
|
||||||
|
|
||||||
|
return (list_of_keys, (oscutils.get_item_properties
|
||||||
|
(s, list_of_keys) for s in export_locations))
|
||||||
|
@@ -298,11 +298,12 @@ class FakeShareExportLocation(object):
|
|||||||
attrs = attrs or {}
|
attrs = attrs or {}
|
||||||
|
|
||||||
share_export_location_info = {
|
share_export_location_info = {
|
||||||
"fake_uuid": "foo_el_uuid",
|
"created_at": 'time-' + uuid.uuid4().hex,
|
||||||
"fake_path": "/foo/el/path",
|
"fake_path": "/foo/el/path",
|
||||||
"fake_share_instance_id": 'share-instance-id' + uuid.uuid4().hex,
|
"fake_share_instance_id": 'share-instance-id' + uuid.uuid4().hex,
|
||||||
|
"fake_uuid": "foo_el_uuid",
|
||||||
"is_admin_only": False,
|
"is_admin_only": False,
|
||||||
"created_at": 'time-' + uuid.uuid4().hex,
|
"preferred": False,
|
||||||
"updated_at": 'time-' + uuid.uuid4().hex,
|
"updated_at": 'time-' + uuid.uuid4().hex,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -19,6 +19,7 @@ import uuid
|
|||||||
|
|
||||||
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes
|
||||||
from osc_lib import exceptions as osc_exceptions
|
from osc_lib import exceptions as osc_exceptions
|
||||||
|
from osc_lib import utils as oscutils
|
||||||
|
|
||||||
from manilaclient import api_versions
|
from manilaclient import api_versions
|
||||||
from manilaclient.api_versions import MAX_VERSION
|
from manilaclient.api_versions import MAX_VERSION
|
||||||
@@ -37,6 +38,11 @@ class TestShare(manila_fakes.TestShare):
|
|||||||
self.shares_mock = self.app.client_manager.share.shares
|
self.shares_mock = self.app.client_manager.share.shares
|
||||||
self.shares_mock.reset_mock()
|
self.shares_mock.reset_mock()
|
||||||
|
|
||||||
|
self.export_locations_mock = (
|
||||||
|
self.app.client_manager.share.share_export_locations
|
||||||
|
)
|
||||||
|
self.export_locations_mock.reset_mock()
|
||||||
|
|
||||||
self.projects_mock = self.app.client_manager.identity.projects
|
self.projects_mock = self.app.client_manager.identity.projects
|
||||||
self.projects_mock.reset_mock()
|
self.projects_mock.reset_mock()
|
||||||
|
|
||||||
@@ -1657,3 +1663,81 @@ class TestAbandonShare(TestShare):
|
|||||||
self.cmd.take_action,
|
self.cmd.take_action,
|
||||||
parsed_args
|
parsed_args
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareExportLocationShow(TestShare):
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareExportLocationShow, self).setUp()
|
||||||
|
|
||||||
|
self._share = manila_fakes.FakeShare.create_one_share()
|
||||||
|
self.shares_mock.get.return_value = self._share
|
||||||
|
|
||||||
|
self._export_location = (
|
||||||
|
manila_fakes.FakeShareExportLocation.create_one_export_location())
|
||||||
|
|
||||||
|
self.export_locations_mock.get.return_value = (
|
||||||
|
self._export_location
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = osc_shares.ShareExportLocationShow(self.app, None)
|
||||||
|
|
||||||
|
def test_share_show_export_location(self):
|
||||||
|
arglist = [
|
||||||
|
self._share.id,
|
||||||
|
self._export_location.fake_uuid
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('share', self._share.id),
|
||||||
|
('export_location', self._export_location.fake_uuid)
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.export_locations_mock.get.assert_called_with(
|
||||||
|
share=self._share,
|
||||||
|
export_location=self._export_location.fake_uuid
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(tuple(self._export_location._info.keys()), columns)
|
||||||
|
self.assertCountEqual(self._export_location._info.values(), data)
|
||||||
|
|
||||||
|
|
||||||
|
class TestShareExportLocationList(TestShare):
|
||||||
|
|
||||||
|
columns = ['ID', 'Path', 'Preferred']
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
super(TestShareExportLocationList, self).setUp()
|
||||||
|
|
||||||
|
self._share = manila_fakes.FakeShare.create_one_share()
|
||||||
|
self.shares_mock.get.return_value = self._share
|
||||||
|
|
||||||
|
self._export_locations = [
|
||||||
|
manila_fakes.FakeShareExportLocation.create_one_export_location()]
|
||||||
|
|
||||||
|
self.export_locations_mock.list.return_value = (
|
||||||
|
self._export_locations
|
||||||
|
)
|
||||||
|
|
||||||
|
self.values = (oscutils.get_dict_properties(
|
||||||
|
e._info, self.columns) for e in self._export_locations)
|
||||||
|
|
||||||
|
# Get the command object to test
|
||||||
|
self.cmd = osc_shares.ShareExportLocationList(self.app, None)
|
||||||
|
|
||||||
|
def test_share_list_export_location(self):
|
||||||
|
arglist = [
|
||||||
|
self._share.id
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('share', self._share.id)
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
self.export_locations_mock.list.assert_called_with(
|
||||||
|
share=self._share
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertCountEqual(self.values, data)
|
||||||
|
@@ -44,6 +44,8 @@ openstack.share.v2 =
|
|||||||
share_resize = manilaclient.osc.v2.share:ResizeShare
|
share_resize = manilaclient.osc.v2.share:ResizeShare
|
||||||
share_adopt = manilaclient.osc.v2.share:AdoptShare
|
share_adopt = manilaclient.osc.v2.share:AdoptShare
|
||||||
share_abandon = manilaclient.osc.v2.share:AbandonShare
|
share_abandon = manilaclient.osc.v2.share:AbandonShare
|
||||||
|
share_export_location_show = manilaclient.osc.v2.share:ShareExportLocationShow
|
||||||
|
share_export_location_list = manilaclient.osc.v2.share:ShareExportLocationList
|
||||||
share_access_create = manilaclient.osc.v2.share_access_rules:ShareAccessAllow
|
share_access_create = manilaclient.osc.v2.share_access_rules:ShareAccessAllow
|
||||||
share_access_delete = manilaclient.osc.v2.share_access_rules:ShareAccessDeny
|
share_access_delete = manilaclient.osc.v2.share_access_rules:ShareAccessDeny
|
||||||
share_access_list = manilaclient.osc.v2.share_access_rules:ListShareAccess
|
share_access_list = manilaclient.osc.v2.share_access_rules:ListShareAccess
|
||||||
|
Reference in New Issue
Block a user