Skip to content

Commit

Permalink
Fix bug 1014925: fix os-hosts
Browse files Browse the repository at this point in the history
List all hosts API.

Change-Id: I95231ac98223c7b8cc07e867283da8c8d90fed38
  • Loading branch information
jogo committed Jun 19, 2012
1 parent eae762a commit 2c0adf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
8 changes: 5 additions & 3 deletions nova/api/openstack/compute/contrib/hosts.py
Expand Up @@ -27,7 +27,6 @@
from nova import exception
from nova import flags
from nova import log as logging
from nova.scheduler import rpcapi as scheduler_rpcapi


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,8 +97,11 @@ def _list_hosts(req, service=None):
by service type.
"""
context = req.environ['nova.context']
rpcapi = scheduler_rpcapi.SchedulerAPI()
hosts = rpcapi.get_host_list(context)
services = db.service_get_all(context, False)

hosts = []
for host in services:
hosts.append({"host_name": host['host'], 'service': host['topic']})
if service:
hosts = [host for host in hosts
if host["service"] == service]
Expand Down
15 changes: 9 additions & 6 deletions nova/tests/api/openstack/compute/contrib/test_hosts.py
Expand Up @@ -24,22 +24,25 @@
from nova import exception
from nova import flags
from nova import log as logging
from nova.scheduler import rpcapi as scheduler_rpcapi
from nova import test


FLAGS = flags.FLAGS
LOG = logging.getLogger(__name__)
# Simulate the hosts returned by the zone manager.
HOST_LIST = [
{"host_name": "host_c1", "service": "compute"},
{"host_name": "host_c2", "service": "compute"},
{"host_name": "host_v1", "service": "volume"},
{"host_name": "host_v2", "service": "volume"}]
SERVICES_LIST = [
{"host": "host_c1", "topic": "compute"},
{"host": "host_c2", "topic": "compute"},
{"host": "host_v1", "topic": "volume"},
{"host": "host_v2", "topic": "volume"}]


def stub_get_host_list(self, req):
return HOST_LIST
def stub_service_get_all(self, req):
return SERVICES_LIST


def stub_set_host_enabled(context, host, enabled):
Expand Down Expand Up @@ -104,8 +107,8 @@ def setUp(self):
super(HostTestCase, self).setUp()
self.controller = os_hosts.HostController()
self.req = FakeRequest()
self.stubs.Set(scheduler_rpcapi.SchedulerAPI, 'get_host_list',
stub_get_host_list)
self.stubs.Set(db, 'service_get_all',
stub_service_get_all)
self.stubs.Set(self.controller.api, 'set_host_enabled',
stub_set_host_enabled)
self.stubs.Set(self.controller.api, 'set_host_maintenance',
Expand Down

0 comments on commit 2c0adf1

Please sign in to comment.