diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index 41b2ec616..30728b0c4 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1757,6 +1757,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') @@ -1780,6 +1789,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) @@ -1791,6 +1810,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 794c3a8fa..badc4d1b3 100644 --- a/novaclient/v2/contrib/host_evacuate_live.py +++ b/novaclient/v2/contrib/host_evacuate_live.py @@ -27,8 +27,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 @@ -47,12 +52,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") +@utils.arg( + '--block-migrate', + action='store_true', + default="auto", + help=_('Enable block migration. (Default=auto)'), + start_version="2.25") @utils.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") @utils.arg( '--max-servers', type=int,