From 35be44a30c66ccb6b1044100ce6a8877bcac3878 Mon Sep 17 00:00:00 2001 From: Franca Mgbogu <franciedigital@gmail.com> Date: Thu, 4 Aug 2022 08:21:08 +0000 Subject: [PATCH] [OSC] Implement Share Server Migration Show Command This commit adds 'openstack share server migration show' command, that implement the same functionality as 'manila migration-get-progress ' command. Partially-implements: bp openstack-client-support Change-Id: I66843b91684645491e236464151d3733ef05cf3b --- manilaclient/osc/v2/share_servers.py | 34 ++++++++++++++++++ .../tests/unit/osc/v2/test_share_servers.py | 35 +++++++++++++++++++ setup.cfg | 1 + 3 files changed, 70 insertions(+) diff --git a/manilaclient/osc/v2/share_servers.py b/manilaclient/osc/v2/share_servers.py index f64ec2e0c..e09dbe808 100644 --- a/manilaclient/osc/v2/share_servers.py +++ b/manilaclient/osc/v2/share_servers.py @@ -468,3 +468,37 @@ class ShareServerMigrationComplete(command.Command): raise exceptions.CommandError( "Share Server Migration complete is only available " "with manila API version >= 2.57") + + +class ShareServerMigrationShow(command.ShowOne): + """Obtains progress of share migration for a given share server. + + (Admin only, Experimental). + + :param share_server: either share_server object or text with its ID. + + """ + _description = _( + "Gets migration progress of a given share server when copying") + + def get_parser(self, prog_name): + parser = super(ShareServerMigrationShow, self).get_parser(prog_name) + parser.add_argument( + 'share_server', + metavar='<share_server>', + help='ID of share server to show migration progress for.' + ) + return parser + + def take_action(self, parsed_args): + share_client = self.app.client_manager.share + if share_client.api_version >= api_versions.APIVersion("2.57"): + share_server = osc_utils.find_resource( + share_client.share_servers, + parsed_args.share_server) + result = share_server.migration_get_progress() + return self.dict2columns(result) + else: + raise exceptions.CommandError( + "Share Server Migration show is only available " + "with manila API version >= 2.57") diff --git a/manilaclient/tests/unit/osc/v2/test_share_servers.py b/manilaclient/tests/unit/osc/v2/test_share_servers.py index f6f665851..221ad7363 100644 --- a/manilaclient/tests/unit/osc/v2/test_share_servers.py +++ b/manilaclient/tests/unit/osc/v2/test_share_servers.py @@ -570,3 +570,38 @@ class TestShareServerMigrationComplete(TestShareServer): parsed_args = self.check_parser(self.cmd, arglist, verifylist) self.cmd.take_action(parsed_args) self.share_server.migration_complete.assert_called + + +class TestShareServerMigrationShow(TestShareServer): + + def setUp(self): + super(TestShareServerMigrationShow, self).setUp() + + self.new_share_network = manila_fakes.FakeShareNetwork \ + .create_one_share_network() + self.share_networks_mock.get.return_value = self.new_share_network + + self.share_server = ( + manila_fakes.FakeShareServer.create_one_server( + attrs={ + 'status': 'migrating', + 'task_state': 'migration_in_progress' + }, + methods={'migration_get_progress': None} + ) + ) + self.servers_mock.get.return_value = self.share_server + + # Get the command objects to test + self.cmd = osc_share_servers.ShareServerMigrationShow(self.app, None) + + def test_share_server_migration_show(self): + arglist = [ + self.share_server.id + ] + verifylist = [ + ('share_server', self.share_server.id) + ] + parsed_args = self.check_parser(self.cmd, arglist, verifylist) + self.cmd.take_action(parsed_args) + self.share_server.migration_get_progress.assert_called diff --git a/setup.cfg b/setup.cfg index ecdfc366e..50c7574c6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -157,6 +157,7 @@ openstack.share.v2 = share_server_set = manilaclient.osc.v2.share_servers:SetShareServer share_server_migration_cancel = manilaclient.osc.v2.share_servers:ShareServerMigrationCancel share_server_migration_complete = manilaclient.osc.v2.share_servers:ShareServerMigrationComplete + share_server_migration_show = manilaclient.osc.v2.share_servers:ShareServerMigrationShow [coverage:run] omit = manilaclient/tests/*