From b269aa4d7f40f259642474227e9258e982155f0d Mon Sep 17 00:00:00 2001 From: Matt Riedemann Date: Fri, 25 Mar 2016 13:17:56 -0400 Subject: [PATCH] Fix host-evacuate-live for 2.25 microversion Change I01b22593724616bc0a7793c509ecabf095d6927d made the live_migrate() method in the ServerManager conditional on the API version requested. This broke the host-evacuate-live command which is calling ServerManager.live_migrate() directly with one too many arguments for the v2.25 version of the method. This updates the host-evacuate-live shell to behave like the live-migration method and be aware of the API version when calling the live_migrate() method. Related to blueprint making-live-migration-api-friendly Conflicts: novaclient/v2/contrib/host_evacuate_live.py NOTE(mriedem): The conflict is due to 93913c84b67d3aefe79bef106fbe9a83f0bcdb71 not being in stable/mitaka. Also note that this is not for a blueprint, it's just related to a blueprint that landed in mitaka but introduced a regression here when support was added for that blueprint with the 2.25 microversion. Change-Id: I4dbeb6ebe03f03799b706be2d787d21484b5c664 Closes-Bug: #1561938 (cherry picked from commit 90fbbb29562a905e8f70badf2c31cfb4ec6841ed) --- novaclient/tests/unit/v2/test_shell.py | 24 +++++++++++++++++++++ novaclient/v2/contrib/host_evacuate_live.py | 21 ++++++++++++++---- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 68bc1b4e4..758faa479 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1729,6 +1729,15 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/servers/uuid3/action', body, pos=3) self.assert_called('POST', '/servers/uuid4/action', body, pos=4) + def test_host_evacuate_live_2_25(self): + self.run_command('host-evacuate-live hyper', api_version='2.25') + self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) + body = {'os-migrateLive': {'host': None, 'block_migration': 'auto'}} + self.assert_called('POST', '/servers/uuid1/action', body, pos=1) + self.assert_called('POST', '/servers/uuid2/action', body, pos=2) + self.assert_called('POST', '/servers/uuid3/action', body, pos=3) + self.assert_called('POST', '/servers/uuid4/action', body, pos=4) + def test_host_evacuate_live_with_target_host(self): self.run_command('host-evacuate-live hyper ' '--target-host hostname') @@ -1752,6 +1761,16 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/servers/uuid3/action', body, pos=3) self.assert_called('POST', '/servers/uuid4/action', body, pos=4) + def test_host_evacuate_live_with_block_migration_2_25(self): + self.run_command('host-evacuate-live --block-migrate hyper', + api_version='2.25') + self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) + body = {'os-migrateLive': {'host': None, 'block_migration': True}} + self.assert_called('POST', '/servers/uuid1/action', body, pos=1) + self.assert_called('POST', '/servers/uuid2/action', body, pos=2) + self.assert_called('POST', '/servers/uuid3/action', body, pos=3) + self.assert_called('POST', '/servers/uuid4/action', body, pos=4) + def test_host_evacuate_live_with_disk_over_commit(self): self.run_command('host-evacuate-live --disk-over-commit hyper') self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) @@ -1763,6 +1782,11 @@ class ShellTest(utils.TestCase): self.assert_called('POST', '/servers/uuid3/action', body, pos=3) self.assert_called('POST', '/servers/uuid4/action', body, pos=4) + def test_host_evacuate_live_with_disk_over_commit_2_25(self): + self.assertRaises(SystemExit, self.run_command, + 'host-evacuate-live --disk-over-commit hyper', + api_version='2.25') + def test_host_evacuate_list_with_max_servers(self): self.run_command('host-evacuate-live --max-servers 1 hyper') self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) diff --git a/novaclient/v2/contrib/host_evacuate_live.py b/novaclient/v2/contrib/host_evacuate_live.py index f91599bbd..8db4fa842 100644 --- a/novaclient/v2/contrib/host_evacuate_live.py +++ b/novaclient/v2/contrib/host_evacuate_live.py @@ -28,8 +28,13 @@ def _server_live_migrate(cs, server, args): success = True error_message = "" try: - cs.servers.live_migrate(server['uuid'], args.target_host, - args.block_migrate, args.disk_over_commit) + # API 2.0->2.24 + if 'disk_over_commit' in args: + cs.servers.live_migrate(server['uuid'], args.target_host, + args.block_migrate, args.disk_over_commit) + else: # API 2.25+ + cs.servers.live_migrate(server['uuid'], args.target_host, + args.block_migrate) except Exception as e: success = False error_message = _("Error while live migrating instance: %s") % e @@ -48,12 +53,20 @@ def _server_live_migrate(cs, server, args): '--block-migrate', action='store_true', default=False, - help=_('Enable block migration.')) + help=_('Enable block migration. (Default=False)'), + start_version="2.0", end_version="2.24") +@cliutils.arg( + '--block-migrate', + action='store_true', + default="auto", + help=_('Enable block migration. (Default=auto)'), + start_version="2.25") @cliutils.arg( '--disk-over-commit', action='store_true', default=False, - help=_('Enable disk overcommit.')) + help=_('Enable disk overcommit.'), + start_version="2.0", end_version="2.24") @cliutils.arg( '--max-servers', type=int,