Merge "[OSC] Implement Share Server Migration Cancel and Complete Command"

This commit is contained in:
Zuul 2022-08-19 11:53:24 +00:00 committed by Gerrit Code Review
commit f3b1b3032e
3 changed files with 122 additions and 0 deletions

View File

@ -409,3 +409,62 @@ class SetShareServer(command.Command):
{'status': parsed_args.status, 'exception': e})
LOG.error(msg)
raise exceptions.CommandError(msg)
class ShareServerMigrationCancel(command.Command):
"""Attempts to cancel migration for a given share server
:param share_server: either share_server object or text with its ID.
"""
_description = _("Cancels migration of a given share server when copying")
def get_parser(self, prog_name):
parser = super(ShareServerMigrationCancel, self).get_parser(prog_name)
parser.add_argument(
'share_server',
metavar='<share_server>',
help=_('ID of share server to cancel migration.')
)
return parser
def take_action(self, parsed_args):
share_client = self.app.client_manager.share
share_server = osc_utils.find_resource(
share_client.share_servers,
parsed_args.share_server)
if share_client.api_version >= api_versions.APIVersion("2.57"):
share_server.migration_cancel()
else:
raise exceptions.CommandError(
"Share Server Migration cancel is only available "
"with manila API version >= 2.57")
class ShareServerMigrationComplete(command.Command):
"""Completes migration for a given share server (Admin only, Experimental).
"""
_description = _("Completes migration for a given share server")
def get_parser(self, prog_name):
parser = super(ShareServerMigrationComplete, self).get_parser(
prog_name)
parser.add_argument(
'share_server',
metavar='<share_server>',
help=_('ID of share server to complete migration.')
)
return parser
def take_action(self, parsed_args):
share_client = self.app.client_manager.share
share_server = osc_utils.find_resource(
share_client.share_servers,
parsed_args.share_server)
if share_client.api_version >= api_versions.APIVersion("2.57"):
share_server.migration_complete()
else:
raise exceptions.CommandError(
"Share Server Migration complete is only available "
"with manila API version >= 2.57")

View File

@ -509,3 +509,64 @@ class TestSetShareServer(TestShareServer):
exceptions.CommandError,
self.cmd.take_action,
parsed_args)
class TestShareServerMigrationCancel(TestShareServer):
def setUp(self):
super(TestShareServerMigrationCancel, self).setUp()
self.share_server = (
manila_fakes.FakeShareServer.create_one_server(
attrs={
'status': 'migrating',
},
methods={'migration_cancel': None}
)
)
self.servers_mock.get.return_value = self.share_server
# Get the command objects to test
self.cmd = osc_share_servers.ShareServerMigrationCancel(self.app, None)
def test_share_server_migration_cancel(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_cancel.assert_called
class TestShareServerMigrationComplete(TestShareServer):
def setUp(self):
super(TestShareServerMigrationComplete, self).setUp()
self.share_server = (
manila_fakes.FakeShareServer.create_one_server(
attrs={
'status': 'migrating',
},
methods={'migration_complete': None}
)
)
self.servers_mock.get.return_value = self.share_server
# Get the command objects to test
self.cmd = osc_share_servers.ShareServerMigrationComplete(
self.app, None)
def test_share_server_migration_complete(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_complete.assert_called

View File

@ -155,6 +155,8 @@ openstack.share.v2 =
share_server_adopt = manilaclient.osc.v2.share_servers:AdoptShareServer
share_server_abandon = manilaclient.osc.v2.share_servers:AbandonShareServer
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
[coverage:run]
omit = manilaclient/tests/*