[OSC] Implement Share Server Migration Start Command

This commit adds 'openstack share server migration start'
command, that implement the same functionality as
'manila share-server-migration-start ' command.

Partially-implements: bp openstack-client-support
Change-Id: I73e0497d44eb591fdba63a6f8a9cea5f900db2d8
This commit is contained in:
Franca Mgbogu 2022-07-25 13:37:05 +00:00
parent 35be44a30c
commit 20638a5000
3 changed files with 164 additions and 0 deletions

View File

@ -20,6 +20,7 @@ from osc_lib import utils as osc_utils
from manilaclient import api_versions
from manilaclient.common._i18n import _
from manilaclient.common.apiclient import utils as apiutils
from manilaclient.common import constants
LOG = logging.getLogger(__name__)
@ -415,6 +416,7 @@ 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")
@ -478,6 +480,7 @@ class ShareServerMigrationShow(command.ShowOne):
:param share_server: either share_server object or text with its ID.
"""
_description = _(
"Gets migration progress of a given share server when copying")
@ -502,3 +505,78 @@ class ShareServerMigrationShow(command.ShowOne):
raise exceptions.CommandError(
"Share Server Migration show is only available "
"with manila API version >= 2.57")
class ShareServerMigrationStart(command.Command):
"""Migrates share server to a new host (Admin only, Experimental)."""
_description = _("Migrates share server to a new host.")
def get_parser(self, prog_name):
parser = super(ShareServerMigrationStart, self).get_parser(prog_name)
parser.add_argument(
'share_server',
metavar='<share_server>',
help=_('ID of share server to complete migration.')
)
parser.add_argument(
'host',
metavar='<host@backend>',
help=_("Destination to migrate the share server to. Use "
"the format '<node_hostname>@<backend_name>'.")
)
parser.add_argument(
'--preserve-snapshots',
metavar='<True|False>',
choices=['True', 'False'],
required=True,
help=_("Set to True if snapshots must be preserved at "
"the migration destination.")
)
parser.add_argument(
'--writable',
metavar='<True|False>',
choices=['True', 'False'],
required=True,
help=_("Enforces migration to keep all its shares writable"
"while contents are being moved.")
)
parser.add_argument(
'--nondisruptive',
metavar='<True|False>',
choices=['True', 'False'],
required=True,
help=_("Enforces migration to be nondisruptive.")
)
parser.add_argument(
'--new-share-network',
metavar='<new_share_network>',
required=False,
default=None,
help=_('Specify a new share network for the share server. Do not '
'specify this parameter if the migrating share server has '
'to be retained within its current share network.',)
)
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"):
new_share_net_id = None
if parsed_args.new_share_network:
new_share_net_id = apiutils.find_resource(
share_client.share_networks,
parsed_args.new_share_network).id
share_server.migration_start(parsed_args.host,
parsed_args.writable,
parsed_args.nondisruptive,
parsed_args.preserve_snapshots,
new_share_net_id)
else:
raise exceptions.CommandError(
"Share Server Migration is only available "
"with manila API version >= 2.57")

View File

@ -605,3 +605,88 @@ class TestShareServerMigrationShow(TestShareServer):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.cmd.take_action(parsed_args)
self.share_server.migration_get_progress.assert_called
class TestShareServerMigrationStart(TestShareServer):
def setUp(self):
super(TestShareServerMigrationStart, 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(
methods={'migration_start': None}
))
self.servers_mock.get.return_value = self.share_server
# Get the command objects to test
self.cmd = osc_share_servers.ShareServerMigrationStart(self.app, None)
def test_share_server_migration_start_with_new_share_network(self):
"""Test share server migration with new_share_network"""
arglist = [
'1234',
'host@backend',
'--preserve-snapshots', 'False',
'--writable', 'False',
'--nondisruptive', 'False',
'--new-share-network', self.new_share_network.id
]
verifylist = [
('share_server', '1234'),
('host', 'host@backend'),
('preserve_snapshots', 'False'),
('writable', 'False'),
('nondisruptive', 'False'),
('new_share_network', self.new_share_network.id)
]
self.app.client_manager.share.api_version = api_versions.APIVersion(
"2.57")
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
result = self.cmd.take_action(parsed_args)
self.share_server.migration_start.assert_called_with(
'host@backend',
'False',
'False',
'False',
self.new_share_network.id
)
self.assertIsNone(result)
def test_share_server_migration_start_with_api_version_exception(self):
"""Test share server migration start with API microversion exception"""
self.app.client_manager.share.api_version = api_versions.APIVersion(
"2.50")
arglist = [
'1234',
'host@backend',
'--preserve-snapshots', 'False',
'--writable', 'False',
'--nondisruptive', 'False',
'--new-share-network', self.new_share_network.id
]
verifylist = [
('share_server', '1234'),
('host', 'host@backend'),
('preserve_snapshots', 'False'),
('writable', 'False'),
('nondisruptive', 'False'),
('new_share_network', self.new_share_network.id)
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
self.servers_mock.migration_start.side_effect = Exception()
self.assertRaises(
exceptions.CommandError,
self.cmd.take_action,
parsed_args)

View File

@ -158,6 +158,7 @@ openstack.share.v2 =
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
share_server_migration_start = manilaclient.osc.v2.share_servers:ShareServerMigrationStart
[coverage:run]
omit = manilaclient/tests/*