[OSC] Implement Share Migration Cancel and Complete Command

This commit adds 'openstack share migration cancel' and
'openstack share migration complete' command, that implement the
same functionality as 'manila migration-cancel'and 'manila
migration-complete' command.

Partially-implements: bp openstack-client-support
Change-Id: I153d3131b591aef599cff87a5dbd85f5db3115dd
This commit is contained in:
namrata 2022-04-17 17:20:51 +00:00 committed by Maari Tamm
parent fa84d6118c
commit 4951255876
4 changed files with 111 additions and 0 deletions

View File

@ -68,6 +68,13 @@ share migration
.. autoprogram-cliff:: openstack.share.v2
:command: share migration start
.. autoprogram-cliff:: openstack.share.v2
:command: share migration cancel
.. autoprogram-cliff:: openstack.share.v2
:command: share migration complete
==============
share networks
==============

View File

@ -1296,3 +1296,47 @@ class ShareMigrationStart(command.Command):
parsed_args.nondisruptive,
parsed_args.preserve_snapshots,
new_share_net_id, new_share_type_id)
class ShareMigrationCancel(command.Command):
"""Cancels migration of a given share when copying
(Admin only, Experimental).
"""
_description = _("Cancels migration of a given share when copying")
def get_parser(self, prog_name):
parser = super(ShareMigrationCancel, self).get_parser(prog_name)
parser.add_argument(
'share',
metavar="<share>",
help=_('Name or ID of share to migrate.')
)
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)
share.migration_cancel()
class ShareMigrationComplete(command.Command):
"""Completes migration for a given share (Admin only, Experimental)."""
_description = _("Completes migration for a given share")
def get_parser(self, prog_name):
parser = super(ShareMigrationComplete, self).get_parser(prog_name)
parser.add_argument(
'share',
metavar="<share>",
help=_('Name or ID of share to migrate.')
)
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)
share.migration_complete()

View File

@ -1932,3 +1932,61 @@ class TestShareMigrationStart(TestShare):
None
)
self.assertIsNone(result)
class TestShareMigrationCancel(TestShare):
def setUp(self):
super(TestShareMigrationCancel, self).setUp()
self._share = manila_fakes.FakeShare.create_one_share(
attrs={
'status': 'migrating'},
methods={'migration_cancel': None})
self.shares_mock.get.return_value = self._share
self.shares_mock.manage.return_value = self._share
# Get the command objects to test
self.cmd = osc_shares.ShareMigrationCancel(self.app, None)
def test_migration_cancel(self):
arglist = [
self._share.id
]
verifylist = [
('share', self._share.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self._share.migration_cancel.assert_called
self.assertIsNone(result)
class TestShareMigrationComplete(TestShare):
def setUp(self):
super(TestShareMigrationComplete, self).setUp()
self._share = manila_fakes.FakeShare.create_one_share(
attrs={
'status': 'migrating'},
methods={'migration_complete': None})
self.shares_mock.get.return_value = self._share
self.shares_mock.manage.return_value = self._share
# Get the command objects to test
self.cmd = osc_shares.ShareMigrationComplete(self.app, None)
def test_migration_complete(self):
arglist = [
self._share.id
]
verifylist = [
('share', self._share.id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self._share.migration_complete.assert_called
self.assertIsNone(result)

View File

@ -45,6 +45,8 @@ openstack.share.v2 =
share_adopt = manilaclient.osc.v2.share:AdoptShare
share_abandon = manilaclient.osc.v2.share:AbandonShare
share_migration_start = manilaclient.osc.v2.share:ShareMigrationStart
share_migration_cancel = manilaclient.osc.v2.share:ShareMigrationCancel
share_migration_complete = manilaclient.osc.v2.share:ShareMigrationComplete
share_export_location_show = manilaclient.osc.v2.share:ShareExportLocationShow
share_export_location_list = manilaclient.osc.v2.share:ShareExportLocationList
share_properties_show = manilaclient.osc.v2.share:ShowShareProperties