From fc90f825f478ac20762c30ec2c84d538acb3ea84 Mon Sep 17 00:00:00 2001 From: sampathP Date: Tue, 24 May 2016 15:04:52 +0900 Subject: [PATCH] Fix nova host-evacuate for v2.14 From API micro version 2.14, evacuate does not need onSharedStorage flag. This patch check the API micro version and set/ignore the onSharedStorage flag before call evacuate for each instance. Closes-Bug: #1581336 Change-Id: I825653d66f94d36a945b8240ec52285827423375 --- novaclient/tests/unit/v2/test_shell.py | 13 +++++++++++++ novaclient/v2/contrib/host_evacuate.py | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py index c5bbd66b6..9e8e228e0 100644 --- a/novaclient/tests/unit/v2/test_shell.py +++ b/novaclient/tests/unit/v2/test_shell.py @@ -1980,6 +1980,19 @@ class ShellTest(utils.TestCase): self.assert_called( 'GET', '/os-hosts/sample-host/reboot') + def test_host_evacuate_v2_14(self): + self.run_command('host-evacuate hyper --target target_hyper', + api_version='2.14') + self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) + self.assert_called('POST', '/servers/uuid1/action', + {'evacuate': {'host': 'target_hyper'}}, pos=1) + self.assert_called('POST', '/servers/uuid2/action', + {'evacuate': {'host': 'target_hyper'}}, pos=2) + self.assert_called('POST', '/servers/uuid3/action', + {'evacuate': {'host': 'target_hyper'}}, pos=3) + self.assert_called('POST', '/servers/uuid4/action', + {'evacuate': {'host': 'target_hyper'}}, pos=4) + def test_host_evacuate(self): self.run_command('host-evacuate hyper --target target_hyper') self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0) diff --git a/novaclient/v2/contrib/host_evacuate.py b/novaclient/v2/contrib/host_evacuate.py index 8b1016378..2a0335d30 100644 --- a/novaclient/v2/contrib/host_evacuate.py +++ b/novaclient/v2/contrib/host_evacuate.py @@ -13,6 +13,7 @@ # License for the specific language governing permissions and limitations # under the License. +from novaclient import api_versions from novaclient import base from novaclient.i18n import _ from novaclient import utils @@ -26,8 +27,15 @@ def _server_evacuate(cs, server, args): success = True error_message = "" try: - cs.servers.evacuate(server=server['uuid'], host=args.target_host, - on_shared_storage=args.on_shared_storage) + on_shared_storage = getattr(args, 'on_shared_storage', None) + if api_versions.APIVersion("2.14") <= cs.api_version: + # if microversion >= 2.14 + cs.servers.evacuate(server=server['uuid'], host=args.target_host) + else: + # else microversion 2.0 - 2.13 + cs.servers.evacuate(server=server['uuid'], + host=args.target_host, + on_shared_storage=on_shared_storage) except Exception as e: success = False error_message = _("Error while evacuating instance: %s") % e @@ -49,7 +57,9 @@ def _server_evacuate(cs, server, args): dest='on_shared_storage', action="store_true", default=False, - help=_('Specifies whether all instances files are on shared storage')) + help=_('Specifies whether all instances files are on shared storage'), + start_version='2.0', + end_version='2.13') def do_host_evacuate(cs, args): """Evacuate all instances from failed host.""" hypervisors = cs.hypervisors.search(args.host, servers=True)