Skip to content

Commit

Permalink
Backport fix for API listing of os-hosts.
Browse files Browse the repository at this point in the history
Backports fix for bug 1014925 to stable/essex, which resolves issue
where querying /v1.1/$tenant/os-hosts returns an empty list.

Original fix by Joe Gordon reviewed into Folsom at:

    https://review.openstack.org/#/c/8682/2

Change-Id: I44ac2e519b7af9b8f3b37a42280ac6fe71c31a1c
  • Loading branch information
Adam Gandelman committed Jul 23, 2012
1 parent c6a714c commit 08e5128
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 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 api as scheduler_api


LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -98,7 +97,10 @@ def _list_hosts(req, service=None):
by service type.
"""
context = req.environ['nova.context']
hosts = scheduler_api.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
11 changes: 8 additions & 3 deletions nova/tests/api/openstack/compute/contrib/test_hosts.py
Expand Up @@ -36,10 +36,15 @@
{"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(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,7 +109,7 @@ def setUp(self):
super(HostTestCase, self).setUp()
self.controller = os_hosts.HostController()
self.req = FakeRequest()
self.stubs.Set(scheduler_api, '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 08e5128

Please sign in to comment.