Allow "server migrate" (not live) to take "--host" option
Currently, doing a cold migration while specifying a target host is not possible however nova api supports it since version 2.56. This patch allows passing "--host" when doing a cold migration. It runs normally if --os-compute-api-version is 2.56 or greater and returns an error otherwise. Change-Id: I960109008096ce8bb4e4c8ca6ffb22c33aacd995 Story: 2003325 Task: 24359
This commit is contained in:
parent
82823f89f0
commit
1aad94349b
@ -1470,13 +1470,13 @@ class MigrateServer(command.Command):
|
|||||||
'and ``--live-migration`` are used, ``--live-migration`` '
|
'and ``--live-migration`` are used, ``--live-migration`` '
|
||||||
'takes priority.'),
|
'takes priority.'),
|
||||||
)
|
)
|
||||||
# TODO(mriedem): Add support for --os-compute-api-version >= 2.56 where
|
|
||||||
# you can cold migrate to a specified target host.
|
|
||||||
host_group.add_argument(
|
host_group.add_argument(
|
||||||
'--host',
|
'--host',
|
||||||
metavar='<hostname>',
|
metavar='<hostname>',
|
||||||
help=_('Live migrate the server to the specified host. Requires '
|
help=_('Migrate the server to the specified host. Requires '
|
||||||
'``--os-compute-api-version`` 2.30 or greater.'),
|
'``--os-compute-api-version`` 2.30 or greater when used '
|
||||||
|
'with the ``--live-migration`` option, otherwise requires '
|
||||||
|
'``--os-compute-api-version`` 2.56 or greater.'),
|
||||||
)
|
)
|
||||||
migration_group = parser.add_mutually_exclusive_group()
|
migration_group = parser.add_mutually_exclusive_group()
|
||||||
migration_group.add_argument(
|
migration_group.add_argument(
|
||||||
@ -1566,16 +1566,22 @@ class MigrateServer(command.Command):
|
|||||||
kwargs['disk_over_commit'] = parsed_args.disk_overcommit
|
kwargs['disk_over_commit'] = parsed_args.disk_overcommit
|
||||||
server.live_migrate(**kwargs)
|
server.live_migrate(**kwargs)
|
||||||
else:
|
else:
|
||||||
if (parsed_args.block_migration or parsed_args.disk_overcommit or
|
if parsed_args.block_migration or parsed_args.disk_overcommit:
|
||||||
parsed_args.host):
|
|
||||||
# TODO(mriedem): Allow --host for cold migration if
|
|
||||||
# --os-compute-api-version >= 2.56.
|
|
||||||
raise exceptions.CommandError(
|
raise exceptions.CommandError(
|
||||||
"--live-migration must be specified if "
|
"--live-migration must be specified if "
|
||||||
"--block-migration, --disk-overcommit or --host is "
|
"--block-migration or --disk-overcommit is "
|
||||||
"specified")
|
"specified")
|
||||||
|
if parsed_args.host:
|
||||||
|
if (compute_client.api_version <
|
||||||
|
api_versions.APIVersion('2.56')):
|
||||||
|
msg = _(
|
||||||
|
'--os-compute-api-version 2.56 or greater is '
|
||||||
|
'required to use --host without --live-migration.'
|
||||||
|
)
|
||||||
|
raise exceptions.CommandError(msg)
|
||||||
|
|
||||||
server.migrate()
|
kwargs = {'host': parsed_args.host} if parsed_args.host else {}
|
||||||
|
server.migrate(**kwargs)
|
||||||
|
|
||||||
if parsed_args.wait:
|
if parsed_args.wait:
|
||||||
if utils.wait_for_status(
|
if utils.wait_for_status(
|
||||||
|
@ -2528,6 +2528,32 @@ class TestServerMigrate(TestServer):
|
|||||||
self.assertNotCalled(self.servers_mock.live_migrate)
|
self.assertNotCalled(self.servers_mock.live_migrate)
|
||||||
self.assertIsNone(result)
|
self.assertIsNone(result)
|
||||||
|
|
||||||
|
def test_server_migrate_with_host_2_56(self):
|
||||||
|
# Tests that --host is allowed for a cold migration
|
||||||
|
# for microversion 2.56 and greater.
|
||||||
|
arglist = [
|
||||||
|
'--host', 'fakehost', self.server.id,
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('live', None),
|
||||||
|
('live_migration', False),
|
||||||
|
('host', 'fakehost'),
|
||||||
|
('block_migration', False),
|
||||||
|
('disk_overcommit', False),
|
||||||
|
('wait', False),
|
||||||
|
]
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
self.app.client_manager.compute.api_version = \
|
||||||
|
api_versions.APIVersion('2.56')
|
||||||
|
|
||||||
|
result = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
self.servers_mock.get.assert_called_with(self.server.id)
|
||||||
|
self.server.migrate.assert_called_with(host='fakehost')
|
||||||
|
self.assertNotCalled(self.servers_mock.live_migrate)
|
||||||
|
self.assertIsNone(result)
|
||||||
|
|
||||||
def test_server_migrate_with_block_migration(self):
|
def test_server_migrate_with_block_migration(self):
|
||||||
arglist = [
|
arglist = [
|
||||||
'--block-migration', self.server.id,
|
'--block-migration', self.server.id,
|
||||||
@ -2566,8 +2592,9 @@ class TestServerMigrate(TestServer):
|
|||||||
self.assertNotCalled(self.servers_mock.live_migrate)
|
self.assertNotCalled(self.servers_mock.live_migrate)
|
||||||
self.assertNotCalled(self.servers_mock.migrate)
|
self.assertNotCalled(self.servers_mock.migrate)
|
||||||
|
|
||||||
def test_server_migrate_with_host(self):
|
def test_server_migrate_with_host_pre_2_56(self):
|
||||||
# Tests that --host is not allowed for a cold migration.
|
# Tests that --host is not allowed for a cold migration
|
||||||
|
# before microversion 2.56 (the test defaults to 2.1).
|
||||||
arglist = [
|
arglist = [
|
||||||
'--host', 'fakehost', self.server.id,
|
'--host', 'fakehost', self.server.id,
|
||||||
]
|
]
|
||||||
@ -2585,9 +2612,10 @@ class TestServerMigrate(TestServer):
|
|||||||
parsed_args)
|
parsed_args)
|
||||||
|
|
||||||
# Make sure it's the error we expect.
|
# Make sure it's the error we expect.
|
||||||
self.assertIn("--live-migration must be specified if "
|
self.assertIn('--os-compute-api-version 2.56 or greater is required '
|
||||||
"--block-migration, --disk-overcommit or --host is "
|
'to use --host without --live-migration.',
|
||||||
"specified", six.text_type(ex))
|
six.text_type(ex))
|
||||||
|
|
||||||
self.servers_mock.get.assert_called_with(self.server.id)
|
self.servers_mock.get.assert_called_with(self.server.id)
|
||||||
self.assertNotCalled(self.servers_mock.live_migrate)
|
self.assertNotCalled(self.servers_mock.live_migrate)
|
||||||
self.assertNotCalled(self.servers_mock.migrate)
|
self.assertNotCalled(self.servers_mock.migrate)
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
Added the ability to specify ``--host`` with ``server migrate``
|
||||||
|
(cold migration) to specify the target host of the migration.
|
||||||
|
Requires ``--os-compute-api-version`` 2.56 or greater to target a
|
||||||
|
specific host for the (cold) migration.
|
||||||
|
[Story `2003325 <https://storyboard.openstack.org/#!/story/2003325>`_]
|
Loading…
Reference in New Issue
Block a user