Merge "Use nova os-services to retrieve host list"

This commit is contained in:
Zuul 2018-02-07 05:03:10 +00:00 committed by Gerrit Code Review
commit 795b10280a
7 changed files with 124 additions and 167 deletions

View File

@ -984,11 +984,6 @@ def aggregate_set_metadata(request, aggregate_id, metadata):
return novaclient(request).aggregates.set_metadata(aggregate_id, metadata) return novaclient(request).aggregates.set_metadata(aggregate_id, metadata)
@profiler.trace
def host_list(request):
return novaclient(request).hosts.list()
@profiler.trace @profiler.trace
def add_host_to_aggregate(request, aggregate_id, host): def add_host_to_aggregate(request, aggregate_id, host):
return novaclient(request).aggregates.add_host(aggregate_id, host) return novaclient(request).aggregates.add_host(aggregate_id, host)

View File

@ -30,39 +30,21 @@ class BaseAggregateWorkflowTests(test.BaseAdminViewTests):
"availability_zone": aggregate.availability_zone} "availability_zone": aggregate.availability_zone}
if hosts: if hosts:
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
host_field_name = 'add_host_to_aggregate_role_member' host_field_name = 'add_host_to_aggregate_role_member'
aggregate_info[host_field_name] = \ aggregate_info[host_field_name] = hosts
[h.host_name for h in compute_hosts]
return aggregate_info
def _get_manage_workflow_data(self, aggregate, hosts=None, ):
aggregate_info = {"id": aggregate.id}
if hosts:
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
host_field_name = 'add_host_to_aggregate_role_member'
aggregate_info[host_field_name] = \
[h.host_name for h in compute_hosts]
return aggregate_info return aggregate_info
class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests): class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
@test.create_stubs({api.nova: ('host_list', ), }) @test.create_stubs({api.nova: ('service_list', ), })
def test_workflow_get(self): def test_workflow_get(self):
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list()) compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
self.mox.ReplayAll() self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL) url = reverse(constants.AGGREGATES_CREATE_URL)
@ -76,13 +58,16 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
['<SetAggregateInfoStep: set_aggregate_info>', ['<SetAggregateInfoStep: set_aggregate_info>',
'<AddHostsToAggregateStep: add_host_to_aggregate>']) '<AddHostsToAggregateStep: add_host_to_aggregate>'])
@test.create_stubs({api.nova: ('host_list', 'aggregate_details_list', @test.create_stubs({api.nova: ('service_list', 'aggregate_details_list',
'aggregate_create'), }) 'aggregate_create'), })
def _test_generic_create_aggregate(self, workflow_data, aggregate, def _test_generic_create_aggregate(self, workflow_data, aggregate,
existing_aggregates=(), existing_aggregates=(),
error_count=0, error_count=0,
expected_error_message=None): expected_error_message=None):
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list()) compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.aggregate_details_list(IsA(http.HttpRequest)) \ api.nova.aggregate_details_list(IsA(http.HttpRequest)) \
.AndReturn(existing_aggregates) .AndReturn(existing_aggregates)
if not expected_error_message: if not expected_error_message:
@ -140,33 +125,32 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
existing_aggregates, 1, existing_aggregates, 1,
expected_error_message) expected_error_message)
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'aggregate_details_list', 'aggregate_details_list',
'aggregate_create', 'aggregate_create',
'add_host_to_aggregate'), }) 'add_host_to_aggregate'), })
def test_create_aggregate_with_hosts(self): def test_create_aggregate_with_hosts(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
hosts = self.hosts.list()
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list()) compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
compute_hosts = [s.host for s in compute_services]
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.aggregate_details_list(IsA(http.HttpRequest)).AndReturn([]) api.nova.aggregate_details_list(IsA(http.HttpRequest)).AndReturn([])
workflow_data = self._get_create_workflow_data(aggregate, hosts) workflow_data = self._get_create_workflow_data(aggregate,
compute_hosts)
api.nova.aggregate_create( api.nova.aggregate_create(
IsA(http.HttpRequest), IsA(http.HttpRequest),
name=workflow_data['name'], name=workflow_data['name'],
availability_zone=workflow_data['availability_zone'], availability_zone=workflow_data['availability_zone'],
).AndReturn(aggregate) ).AndReturn(aggregate)
compute_hosts = []
for host in hosts:
if host.service == 'compute':
compute_hosts.append(host)
for host in compute_hosts: for host in compute_hosts:
api.nova.add_host_to_aggregate( api.nova.add_host_to_aggregate(
IsA(http.HttpRequest), IsA(http.HttpRequest),
aggregate.id, host.host_name).InAnyOrder() aggregate.id, host).InAnyOrder()
self.mox.ReplayAll() self.mox.ReplayAll()
@ -177,18 +161,13 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
self.assertRedirectsNoFollow(res, self.assertRedirectsNoFollow(res,
reverse(constants.AGGREGATES_INDEX_URL)) reverse(constants.AGGREGATES_INDEX_URL))
@test.create_stubs({api.nova: ('host_list', 'aggregate_details_list', ), }) @test.create_stubs({api.nova: ('service_list',
def test_host_list_nova_compute(self): 'aggregate_details_list', ), })
def test_service_list_nova_compute(self):
hosts = self.hosts.list() compute_services = [s for s in self.services.list()
compute_hosts = [] if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
for host in hosts: .AndReturn(compute_services)
if host.service == 'compute':
compute_hosts.append(host)
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
self.mox.ReplayAll() self.mox.ReplayAll()
url = reverse(constants.AGGREGATES_CREATE_URL) url = reverse(constants.AGGREGATES_CREATE_URL)
@ -197,7 +176,7 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
step = workflow.get_step("add_host_to_aggregate") step = workflow.get_step("add_host_to_aggregate")
field_name = step.get_member_field_name('member') field_name = step.get_member_field_name('member')
self.assertEqual(len(step.action.fields[field_name].choices), self.assertEqual(len(step.action.fields[field_name].choices),
len(compute_hosts)) len(compute_services))
class AggregatesViewTests(test.BaseAdminViewTests): class AggregatesViewTests(test.BaseAdminViewTests):
@ -273,14 +252,16 @@ class AggregatesViewTests(test.BaseAdminViewTests):
class ManageHostsTests(test.BaseAdminViewTests): class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'host_list')}) @test.create_stubs({api.nova: ('aggregate_get', 'service_list')})
def test_manage_hosts(self): def test_manage_hosts(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \ compute_services = [s for s in self.services.list()
.AndReturn(self.hosts.list()) if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
self.mox.ReplayAll() self.mox.ReplayAll()
res = self.client.get(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL, res = self.client.get(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
@ -291,13 +272,14 @@ class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate', @test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate', 'remove_host_from_aggregate',
'host_list')}) 'service_list')})
def test_manage_hosts_update_add_remove_not_empty_aggregate(self): def test_manage_hosts_update_add_remove_not_empty_aggregate(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
aggregate.hosts = ['host1', 'host2'] aggregate.hosts = ['host1', 'host2']
host = self.hosts.list()[0] compute_services = [s for s in self.services.list()
form_data = {'manageaggregatehostsaction_role_member': if s.binary == 'nova-compute']
[host.host_name]} host = compute_services[0].host
form_data = {'manageaggregatehostsaction_role_member': [host]}
api.nova.remove_host_from_aggregate(IsA(http.HttpRequest), api.nova.remove_host_from_aggregate(IsA(http.HttpRequest),
str(aggregate.id), str(aggregate.id),
@ -307,12 +289,14 @@ class ManageHostsTests(test.BaseAdminViewTests):
'host1').InAnyOrder() 'host1').InAnyOrder()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \ compute_services = [s for s in self.services.list()
.AndReturn(self.hosts.list()) if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
api.nova.add_host_to_aggregate(IsA(http.HttpRequest), api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id), host.host_name) str(aggregate.id), host)
self.mox.ReplayAll() self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL, res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
@ -324,23 +308,25 @@ class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate', @test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate', 'remove_host_from_aggregate',
'host_list')}) 'service_list')})
def test_manage_hosts_update_add_not_empty_aggregate_should_fail(self): def test_manage_hosts_update_add_not_empty_aggregate_should_fail(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
aggregate.hosts = ['devstack001'] aggregate.hosts = ['devstack001']
host1 = self.hosts.list()[0] compute_services = [s for s in self.services.list()
host3 = self.hosts.list()[2] if s.binary == 'nova-compute']
form_data = {'manageaggregatehostsaction_role_member': host1 = compute_services[0].host
[host1.host_name, host3.host_name]} host3 = compute_services[2].host
form_data = {'manageaggregatehostsaction_role_member': [host1, host3]}
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.InAnyOrder().AndReturn(aggregate) .InAnyOrder().AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.InAnyOrder().AndReturn(self.hosts.list()) .AndReturn(compute_services)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.InAnyOrder().AndReturn(aggregate) .InAnyOrder().AndReturn(aggregate)
api.nova.add_host_to_aggregate(IsA(http.HttpRequest), api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id), host3.host_name) \ str(aggregate.id),
host3) \
.InAnyOrder().AndRaise(self.exceptions.nova) .InAnyOrder().AndRaise(self.exceptions.nova)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -354,7 +340,7 @@ class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate', @test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate', 'remove_host_from_aggregate',
'host_list')}) 'service_list')})
def test_manage_hosts_update_clean_not_empty_aggregate_should_fail(self): def test_manage_hosts_update_clean_not_empty_aggregate_should_fail(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
aggregate.hosts = ['host2'] aggregate.hosts = ['host2']
@ -367,8 +353,10 @@ class ManageHostsTests(test.BaseAdminViewTests):
.AndRaise(self.exceptions.nova) .AndRaise(self.exceptions.nova)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \ compute_services = [s for s in self.services.list()
.AndReturn(self.hosts.list()) if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -383,7 +371,7 @@ class ManageHostsTests(test.BaseAdminViewTests):
@test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate', @test.create_stubs({api.nova: ('aggregate_get', 'add_host_to_aggregate',
'remove_host_from_aggregate', 'remove_host_from_aggregate',
'host_list')}) 'service_list')})
def _test_manage_hosts_update(self, def _test_manage_hosts_update(self,
host, host,
aggregate, aggregate,
@ -402,14 +390,16 @@ class ManageHostsTests(test.BaseAdminViewTests):
'host1').InAnyOrder() 'host1').InAnyOrder()
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
api.nova.host_list(IsA(http.HttpRequest)) \ compute_services = [s for s in self.services.list()
.AndReturn(self.hosts.list()) if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \ api.nova.aggregate_get(IsA(http.HttpRequest), str(aggregate.id)) \
.AndReturn(aggregate) .AndReturn(aggregate)
if addAggregate: if addAggregate:
api.nova.add_host_to_aggregate(IsA(http.HttpRequest), api.nova.add_host_to_aggregate(IsA(http.HttpRequest),
str(aggregate.id), str(aggregate.id),
host.host_name) host)
self.mox.ReplayAll() self.mox.ReplayAll()
res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL, res = self.client.post(reverse(constants.AGGREGATES_MANAGE_HOSTS_URL,
@ -421,10 +411,11 @@ class ManageHostsTests(test.BaseAdminViewTests):
def test_manage_hosts_update_nothing_not_empty_aggregate(self): def test_manage_hosts_update_nothing_not_empty_aggregate(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
host = self.hosts.list()[0] compute_services = [s for s in self.services.list()
aggregate.hosts = [host.host_name] if s.binary == 'nova-compute']
form_data = {'manageaggregatehostsaction_role_member': host = compute_services[0].host
[host.host_name]} aggregate.hosts = [host]
form_data = {'manageaggregatehostsaction_role_member': [host]}
self._test_manage_hosts_update(host, self._test_manage_hosts_update(host,
aggregate, aggregate,
form_data, form_data,
@ -443,9 +434,10 @@ class ManageHostsTests(test.BaseAdminViewTests):
def test_manage_hosts_update_add_empty_aggregate(self): def test_manage_hosts_update_add_empty_aggregate(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
aggregate.hosts = [] aggregate.hosts = []
host = self.hosts.list()[0] compute_services = [s for s in self.services.list()
form_data = {'manageaggregatehostsaction_role_member': if s.binary == 'nova-compute']
[host.host_name]} host = compute_services[0].host
form_data = {'manageaggregatehostsaction_role_member': [host]}
self._test_manage_hosts_update(host, self._test_manage_hosts_update(host,
aggregate, aggregate,
form_data, form_data,
@ -454,10 +446,11 @@ class ManageHostsTests(test.BaseAdminViewTests):
def test_manage_hosts_update_add_not_empty_aggregate(self): def test_manage_hosts_update_add_not_empty_aggregate(self):
aggregate = self.aggregates.first() aggregate = self.aggregates.first()
aggregate.hosts = ['devstack001'] aggregate.hosts = ['devstack001']
host1 = self.hosts.list()[0] compute_services = [s for s in self.services.list()
host3 = self.hosts.list()[2] if s.binary == 'nova-compute']
form_data = {'manageaggregatehostsaction_role_member': host1 = compute_services[0].host
[host1.host_name, host3.host_name]} host3 = compute_services[2].host
form_data = {'manageaggregatehostsaction_role_member': [host1, host3]}
self._test_manage_hosts_update(host3, self._test_manage_hosts_update(host3,
aggregate, aggregate,
form_data, form_data,

View File

@ -76,16 +76,13 @@ class AddHostsToAggregateAction(workflows.MembershipAction):
field_name = self.get_member_field_name('member') field_name = self.get_member_field_name('member')
self.fields[field_name] = forms.MultipleChoiceField(required=False) self.fields[field_name] = forms.MultipleChoiceField(required=False)
hosts = [] services = []
try: try:
hosts = api.nova.host_list(request) services = api.nova.service_list(request, binary='nova-compute')
except Exception: except Exception:
exceptions.handle(request, err_msg) exceptions.handle(request, err_msg)
host_names = [] host_names = [s.host for s in services]
for host in hosts:
if host.host_name not in host_names and host.service == u'compute':
host_names.append(host.host_name)
host_names.sort() host_names.sort()
self.fields[field_name].choices = \ self.fields[field_name].choices = \
@ -114,16 +111,13 @@ class ManageAggregateHostsAction(workflows.MembershipAction):
aggregate = api.nova.aggregate_get(request, aggregate_id) aggregate = api.nova.aggregate_get(request, aggregate_id)
current_aggregate_hosts = aggregate.hosts current_aggregate_hosts = aggregate.hosts
hosts = [] services = []
try: try:
hosts = api.nova.host_list(request) services = api.nova.service_list(request, binary='nova-compute')
except Exception: except Exception:
exceptions.handle(request, err_msg) exceptions.handle(request, err_msg)
host_names = [] host_names = [s.host for s in services]
for host in hosts:
if host.host_name not in host_names and host.service == u'compute':
host_names.append(host.host_name)
host_names.sort() host_names.sort()
self.fields[field_name].choices = \ self.fields[field_name].choices = \

View File

@ -48,11 +48,7 @@ class LiveMigrateForm(forms.SelfHandlingForm):
def populate_host_choices(self, request, initial): def populate_host_choices(self, request, initial):
hosts = initial.get('hosts') hosts = initial.get('hosts')
current_host = initial.get('current_host') current_host = initial.get('current_host')
host_list = [(host.host_name, host_list = [(host, host) for host in hosts if host != current_host]
host.host_name)
for host in hosts
if (host.service.startswith('compute') and
host.host_name != current_host)]
if host_list: if host_list:
host_list.insert(0, ("AUTO_SCHEDULE", host_list.insert(0, ("AUTO_SCHEDULE",
_("Automatically schedule new host."))) _("Automatically schedule new host.")))

View File

@ -257,14 +257,16 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertContains(res, "instances__revert") self.assertContains(res, "instances__revert")
self.assertNotContains(res, "instances__migrate") self.assertNotContains(res, "instances__migrate")
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get',)}) 'server_get',)})
def test_instance_live_migrate_get(self): def test_instance_live_migrate_get(self):
server = self.servers.first() server = self.servers.first()
compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(self.hosts.list()) .AndReturn(compute_services)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -288,13 +290,13 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get',)}) 'server_get',)})
def test_instance_live_migrate_list_hypervisor_get_exception(self): def test_instance_live_migrate_list_host_get_exception(self):
server = self.servers.first() server = self.servers.first()
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndRaise(self.exceptions.nova) .AndRaise(self.exceptions.nova)
self.mox.ReplayAll() self.mox.ReplayAll()
@ -304,40 +306,42 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get',)}) 'server_get',)})
def test_instance_live_migrate_list_hypervisor_without_current(self): def test_instance_live_migrate_list_host_without_current(self):
server = self.servers.first() server = self.servers.first()
compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(self.hosts.list()) .AndReturn(compute_services)
self.mox.ReplayAll() self.mox.ReplayAll()
url = reverse('horizon:admin:instances:live_migrate', url = reverse('horizon:admin:instances:live_migrate',
args=[server.id]) args=[server.id])
res = self.client.get(url) res = self.client.get(url)
self.assertNotContains(
res, "<option value=\"instance-host\">devstack004</option>")
self.assertContains( self.assertContains(
res, "<option value=\"devstack001\">devstack001</option>") res, "<option value=\"devstack001\">devstack001</option>")
self.assertNotContains(
res, "<option value=\"devstack002\">devstack002</option>")
self.assertContains( self.assertContains(
res, "<option value=\"devstack003\">devstack003</option>") res, "<option value=\"devstack002\">devstack002</option>")
self.assertNotContains(
res, "<option value=\"instance-host\">instance-host</option>")
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get', 'server_get',
'server_live_migrate',)}) 'server_live_migrate',)})
def test_instance_live_migrate_post(self): def test_instance_live_migrate_post(self):
server = self.servers.first() server = self.servers.first()
host = self.hosts.first().host_name compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
host = compute_services[0].host
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(self.hosts.list()) .AndReturn(compute_services)
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host, api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host,
block_migration=False, block_migration=False,
disk_over_commit=False) \ disk_over_commit=False) \
@ -351,7 +355,7 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get', 'server_get',
'server_live_migrate',)}) 'server_live_migrate',)})
def test_instance_live_migrate_auto_sched(self): def test_instance_live_migrate_auto_sched(self):
@ -359,8 +363,10 @@ class InstanceViewTest(test.BaseAdminViewTests):
host = "AUTO_SCHEDULE" host = "AUTO_SCHEDULE"
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ compute_services = [s for s in self.services.list()
.AndReturn(self.hosts.list()) if s.binary == 'nova-compute']
api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(compute_services)
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, None, api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, None,
block_migration=False, block_migration=False,
disk_over_commit=False) \ disk_over_commit=False) \
@ -374,17 +380,19 @@ class InstanceViewTest(test.BaseAdminViewTests):
self.assertNoFormErrors(res) self.assertNoFormErrors(res)
self.assertRedirectsNoFollow(res, INDEX_URL) self.assertRedirectsNoFollow(res, INDEX_URL)
@test.create_stubs({api.nova: ('host_list', @test.create_stubs({api.nova: ('service_list',
'server_get', 'server_get',
'server_live_migrate',)}) 'server_live_migrate',)})
def test_instance_live_migrate_post_api_exception(self): def test_instance_live_migrate_post_api_exception(self):
server = self.servers.first() server = self.servers.first()
host = self.hosts.first().host_name compute_services = [s for s in self.services.list()
if s.binary == 'nova-compute']
host = compute_services[0].host
api.nova.server_get(IsA(http.HttpRequest), server.id) \ api.nova.server_get(IsA(http.HttpRequest), server.id) \
.AndReturn(server) .AndReturn(server)
api.nova.host_list(IsA(http.HttpRequest)) \ api.nova.service_list(IsA(http.HttpRequest), binary='nova-compute') \
.AndReturn(self.hosts.list()) .AndReturn(compute_services)
api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host, api.nova.server_live_migrate(IsA(http.HttpRequest), server.id, host,
block_migration=False, block_migration=False,
disk_over_commit=False) \ disk_over_commit=False) \

View File

@ -215,7 +215,9 @@ class LiveMigrateView(forms.ModalFormView):
@memoized.memoized_method @memoized.memoized_method
def get_hosts(self, *args, **kwargs): def get_hosts(self, *args, **kwargs):
try: try:
return api.nova.host_list(self.request) services = api.nova.service_list(self.request,
binary='nova-compute')
return [s.host for s in services]
except Exception: except Exception:
redirect = reverse("horizon:admin:instances:index") redirect = reverse("horizon:admin:instances:index")
msg = _('Unable to retrieve host information.') msg = _('Unable to retrieve host information.')

View File

@ -18,7 +18,6 @@ from novaclient.v2 import aggregates
from novaclient.v2 import availability_zones from novaclient.v2 import availability_zones
from novaclient.v2 import flavor_access from novaclient.v2 import flavor_access
from novaclient.v2 import flavors from novaclient.v2 import flavors
from novaclient.v2 import hosts
from novaclient.v2 import hypervisors from novaclient.v2 import hypervisors
from novaclient.v2 import keypairs from novaclient.v2 import keypairs
from novaclient.v2 import quotas from novaclient.v2 import quotas
@ -167,7 +166,6 @@ def data(TEST):
TEST.hypervisors = utils.TestDataContainer() TEST.hypervisors = utils.TestDataContainer()
TEST.services = utils.TestDataContainer() TEST.services = utils.TestDataContainer()
TEST.aggregates = utils.TestDataContainer() TEST.aggregates = utils.TestDataContainer()
TEST.hosts = utils.TestDataContainer()
TEST.server_groups = utils.TestDataContainer() TEST.server_groups = utils.TestDataContainer()
# Volumes # Volumes
@ -483,7 +481,7 @@ def data(TEST):
"vcpus_used": 1, "vcpus_used": 1,
"hypervisor_type": "QEMU", "hypervisor_type": "QEMU",
"local_gb_used": 20, "local_gb_used": 20,
"hypervisor_hostname": "devstack001", "hypervisor_hostname": "devstack002",
"memory_mb_used": 1500, "memory_mb_used": 1500,
"memory_mb": 2000, "memory_mb": 2000,
"current_workload": 0, "current_workload": 0,
@ -509,7 +507,7 @@ def data(TEST):
"vcpus_used": 1, "vcpus_used": 1,
"hypervisor_type": "QEMU", "hypervisor_type": "QEMU",
"local_gb_used": 20, "local_gb_used": 20,
"hypervisor_hostname": "devstack003", "hypervisor_hostname": "instance-host",
"memory_mb_used": 1500, "memory_mb_used": 1500,
"memory_mb": 2000, "memory_mb": 2000,
"current_workload": 0, "current_workload": 0,
@ -622,35 +620,6 @@ def data(TEST):
TEST.aggregates.add(aggregate_1) TEST.aggregates.add(aggregate_1)
TEST.aggregates.add(aggregate_2) TEST.aggregates.add(aggregate_2)
host1 = hosts.Host(hosts.HostManager(None), {
"host_name": "devstack001",
"service": "compute",
"zone": "testing",
})
host2 = hosts.Host(hosts.HostManager(None), {
"host_name": "devstack002",
"service": "nova-conductor",
"zone": "testing",
})
host3 = hosts.Host(hosts.HostManager(None), {
"host_name": "devstack003",
"service": "compute",
"zone": "testing",
})
host4 = hosts.Host(hosts.HostManager(None), {
"host_name": "devstack004",
"service": "compute",
"zone": "testing",
})
TEST.hosts.add(host1)
TEST.hosts.add(host2)
TEST.hosts.add(host3)
TEST.hosts.add(host4)
server_group_1 = server_groups.ServerGroup( server_group_1 = server_groups.ServerGroup(
server_groups.ServerGroupsManager(None), server_groups.ServerGroupsManager(None),
{ {