summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem@us.ibm.com>2016-03-25 13:17:56 -0400
committerMatt Riedemann <mriedem@us.ibm.com>2016-03-29 17:08:47 -0400
commitb269aa4d7f40f259642474227e9258e982155f0d (patch)
treead3c3e665423ce88b827c0dc4c1fc14f9219ff49
parent5ee8908706f7d292dcc3d238e545ab4a95637757 (diff)
downloadpython-novaclient-b269aa4d7f40f259642474227e9258e982155f0d.tar.gz
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)
-rw-r--r--novaclient/tests/unit/v2/test_shell.py24
-rw-r--r--novaclient/v2/contrib/host_evacuate_live.py21
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 68bc1b4e..758faa47 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 f91599bb..8db4fa84 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,