Merge "Fix nova host-evacuate for v2.14"

This commit is contained in:
Jenkins 2016-06-03 19:33:40 +00:00 committed by Gerrit Code Review
commit e8354f1098
2 changed files with 26 additions and 3 deletions

View File

@ -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)

View File

@ -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)