From 495125587609a086cdb337ff62b682bd1b60d20f Mon Sep 17 00:00:00 2001 From: namrata Date: Sun, 17 Apr 2022 17:20:51 +0000 Subject: [PATCH] [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 --- doc/source/cli/osc/v2/index.rst | 7 +++ manilaclient/osc/v2/share.py | 44 +++++++++++++++ manilaclient/tests/unit/osc/v2/test_share.py | 58 ++++++++++++++++++++ setup.cfg | 2 + 4 files changed, 111 insertions(+) diff --git a/doc/source/cli/osc/v2/index.rst b/doc/source/cli/osc/v2/index.rst index 9b18a8921..7ac5ce529 100644 --- a/doc/source/cli/osc/v2/index.rst +++ b/doc/source/cli/osc/v2/index.rst @@ -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 ============== diff --git a/manilaclient/osc/v2/share.py b/manilaclient/osc/v2/share.py index 03087089d..d92b1d3f3 100644 --- a/manilaclient/osc/v2/share.py +++ b/manilaclient/osc/v2/share.py @@ -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="", + 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="", + 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() diff --git a/manilaclient/tests/unit/osc/v2/test_share.py b/manilaclient/tests/unit/osc/v2/test_share.py index 7141b6570..cfb7f7e55 100644 --- a/manilaclient/tests/unit/osc/v2/test_share.py +++ b/manilaclient/tests/unit/osc/v2/test_share.py @@ -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) diff --git a/setup.cfg b/setup.cfg index cf4f43c98..b731c8f9a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -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