summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsampathP <sam47priya@gmail.com>2016-05-24 15:04:52 +0900
committerZhou Zheng Sheng <zhengsheng@awcloud.com>2016-06-21 09:42:45 +0000
commit019d1380fa3f70b0a810bd2586be8551a837a7d6 (patch)
treed41d638bc8c461c6920c6306a870d78545d6b8a6
parent451e7f5d147fb28438e3f9ad1dac62b852540409 (diff)
downloadpython-novaclient-019d1380fa3f70b0a810bd2586be8551a837a7d6.tar.gz
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 (cherry picked from commit fc90f825f478ac20762c30ec2c84d538acb3ea84)
-rw-r--r--novaclient/tests/unit/v2/test_shell.py13
-rw-r--r--novaclient/v2/contrib/host_evacuate.py16
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 758faa47..bfdcd920 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -1919,6 +1919,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 b08e28cd..32788fb1 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.openstack.common import cliutils
@@ -27,8 +28,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
@@ -50,7 +58,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)