diff --git a/doc/source/cli/osc/v2/index.rst b/doc/source/cli/osc/v2/index.rst index a964ab737..ecc2342f4 100644 --- a/doc/source/cli/osc/v2/index.rst +++ b/doc/source/cli/osc/v2/index.rst @@ -35,6 +35,12 @@ shares .. autoprogram-cliff:: openstack.share.v2 :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 ================== diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 4a060367b..eebf4a6fb 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -961,3 +961,70 @@ class AbandonShare(command.Command): msg = (_("Failed to abandon %(result)s out of %(total)s shares.") % {'result': result, 'total': total}) 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="", + help=_('Name or ID of share') + ) + parser.add_argument( + 'export_location', + metavar="", + 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="", + 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)) diff --git a/manilaclient/tests/unit/osc/v2/fakes.py b/manilaclient/tests/unit/osc/v2/fakes.py index c3e05157a..8f65df180 100644 --- a/manilaclient/tests/unit/osc/v2/fakes.py +++ b/manilaclient/tests/unit/osc/v2/fakes.py @@ -298,11 +298,12 @@ class FakeShareExportLocation(object): attrs = attrs or {} share_export_location_info = { - "fake_uuid": "foo_el_uuid", + "created_at": 'time-' + uuid.uuid4().hex, "fake_path": "/foo/el/path", "fake_share_instance_id": 'share-instance-id' + uuid.uuid4().hex, + "fake_uuid": "foo_el_uuid", "is_admin_only": False, - "created_at": 'time-' + uuid.uuid4().hex, + "preferred": False, "updated_at": 'time-' + uuid.uuid4().hex, } diff --git a/manilaclient/tests/unit/osc/v2/test_share.py b/manilaclient/tests/unit/osc/v2/test_share.py index 6dddc9dd8..32a08c270 100644 --- a/manilaclient/tests/unit/osc/v2/test_share.py +++ b/manilaclient/tests/unit/osc/v2/test_share.py @@ -19,6 +19,7 @@ import uuid from openstackclient.tests.unit.identity.v3 import fakes as identity_fakes from osc_lib import exceptions as osc_exceptions +from osc_lib import utils as oscutils from manilaclient import api_versions 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.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.reset_mock() @@ -1657,3 +1663,81 @@ class TestAbandonShare(TestShare): self.cmd.take_action, 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) diff --git a/setup.cfg b/setup.cfg index 21a136388..0009ff68c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -44,6 +44,8 @@ openstack.share.v2 = share_resize = manilaclient.osc.v2.share:ResizeShare share_adopt = manilaclient.osc.v2.share:AdoptShare 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_delete = manilaclient.osc.v2.share_access_rules:ShareAccessDeny share_access_list = manilaclient.osc.v2.share_access_rules:ListShareAccess