Merge "Adding Nova Client support for auto find host APIv2"

This commit is contained in:
Jenkins 2014-08-21 23:24:49 +00:00 committed by Gerrit Code Review
commit e0ed6a1e76
5 changed files with 37 additions and 26 deletions

View File

@ -636,7 +636,9 @@ class FakeHTTPClient(base_client.HTTPClient):
keys = list(body[action])
if 'adminPass' in keys:
keys.remove('adminPass')
assert set(keys) == set(['host', 'onSharedStorage'])
if 'host' in keys:
keys.remove('host')
assert set(keys) == set(['onSharedStorage'])
else:
raise AssertionError("Unexpected server action: %s" % action)
return (resp, _headers, _body)

View File

@ -1529,17 +1529,13 @@ class ShellTest(utils.TestCase):
self.run_command('host-evacuate --on-shared-storage hyper')
self.assert_called('GET', '/os-hypervisors/hyper/servers', pos=0)
self.assert_called('POST', '/servers/uuid1/action',
{'evacuate': {'host': None,
'onSharedStorage': True}}, pos=1)
{'evacuate': {'onSharedStorage': True}}, pos=1)
self.assert_called('POST', '/servers/uuid2/action',
{'evacuate': {'host': None,
'onSharedStorage': True}}, pos=2)
{'evacuate': {'onSharedStorage': True}}, pos=2)
self.assert_called('POST', '/servers/uuid3/action',
{'evacuate': {'host': None,
'onSharedStorage': True}}, pos=3)
{'evacuate': {'onSharedStorage': True}}, pos=3)
self.assert_called('POST', '/servers/uuid4/action',
{'evacuate': {'host': None,
'onSharedStorage': True}}, pos=4)
{'evacuate': {'onSharedStorage': True}}, pos=4)
def test_host_servers_migrate(self):
self.run_command('host-servers-migrate hyper')
@ -1844,16 +1840,24 @@ class ShellTest(utils.TestCase):
{'evacuate': {'host': 'new_host',
'onSharedStorage': False,
'adminPass': 'NewAdminPass'}})
self.run_command('evacuate sample-server new_host')
self.assert_called('POST', '/servers/1234/action',
{'evacuate': {'host': 'new_host',
'onSharedStorage': False}})
self.run_command('evacuate sample-server new_host '
'--on-shared-storage')
self.assert_called('POST', '/servers/1234/action',
{'evacuate': {'host': 'new_host',
'onSharedStorage': True}})
def test_evacuate_with_no_target_host(self):
self.run_command('evacuate sample-server')
self.assert_called('POST', '/servers/1234/action',
{'evacuate': {'onSharedStorage': False}})
self.run_command('evacuate sample-server --password NewAdminPass')
self.assert_called('POST', '/servers/1234/action',
{'evacuate': {'onSharedStorage': False,
'adminPass': 'NewAdminPass'}})
self.run_command('evacuate sample-server --on-shared-storage')
self.assert_called('POST', '/servers/1234/action',
{'evacuate': {'onSharedStorage': True}})
def test_get_password(self):
self.run_command('get-password sample-server /foo/id_rsa')
self.assert_called('GET', '/servers/1234/os-server-password')

View File

@ -26,8 +26,8 @@ def _server_evacuate(cs, server, args):
success = True
error_message = ""
try:
cs.servers.evacuate(server['uuid'], args.target_host,
args.on_shared_storage)
cs.servers.evacuate(server=server['uuid'], host=args.target_host,
on_shared_storage=args.on_shared_storage)
except Exception as e:
success = False
error_message = _("Error while evacuating instance: %s") % e
@ -41,7 +41,9 @@ def _server_evacuate(cs, server, args):
@utils.arg('--target_host',
metavar='<target_host>',
default=None,
help=_('Name of target host.'))
help=_('Name of target host. '
'If no host is specified the scheduler'
' will select a target.'))
@utils.arg('--on-shared-storage',
dest='on_shared_storage',
action="store_true",
@ -49,7 +51,7 @@ def _server_evacuate(cs, server, args):
help=_('Specifies whether all instances files are on shared '
' storage'))
def do_host_evacuate(cs, args):
"""Evacuate all instances from failed host to specified one."""
"""Evacuate all instances from failed host."""
hypervisors = cs.hypervisors.search(args.host, servers=True)
response = []
for hyper in hypervisors:

View File

@ -365,7 +365,7 @@ class Server(base.Resource):
"""
return self.manager.list_security_group(self)
def evacuate(self, host, on_shared_storage, password=None):
def evacuate(self, host=None, on_shared_storage=True, password=None):
"""
Evacuate an instance from failed host to specified host.
@ -1151,7 +1151,8 @@ class ServerManager(base.BootingManagerWithFind):
base.getid(server), 'security_groups',
security_groups.SecurityGroup)
def evacuate(self, server, host, on_shared_storage, password=None):
def evacuate(self, server, host=None, on_shared_storage=True,
password=None):
"""
Evacuate a server instance.
@ -1161,10 +1162,10 @@ class ServerManager(base.BootingManagerWithFind):
on shared storage
:param password: string to set as password on the evacuated server.
"""
body = {
'host': host,
'onSharedStorage': on_shared_storage,
}
body = {'onSharedStorage': on_shared_storage}
if host is not None:
body['host'] = host
if password is not None:
body['adminPass'] = password

View File

@ -3593,11 +3593,12 @@ def do_quota_class_update(cs, args):
@utils.arg('server', metavar='<server>', help=_('Name or ID of server.'))
@utils.arg('host', metavar='<host>', help=_('Name or ID of target host.'))
@utils.arg('host', metavar='<host>', nargs='?',
help=_("Name or ID of the target host. "
"If no host is specified, the scheduler will choose one."))
@utils.arg('--password',
dest='password',
metavar='<password>',
default=None,
help=_("Set the provided password on the evacuated server. Not applicable "
"with on-shared-storage flag"))
@utils.arg('--on-shared-storage',
@ -3606,7 +3607,8 @@ def do_quota_class_update(cs, args):
default=False,
help=_('Specifies whether server files are located on shared storage'))
def do_evacuate(cs, args):
"""Evacuate server from failed host to specified one."""
"""Evacuate server from failed host."""
server = _find_server(cs, args.server)
res = server.evacuate(args.host, args.on_shared_storage, args.password)[1]