summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Lindgren <hanlind@kth.se>2013-02-28 11:00:29 +0100
committerHans Lindgren <hanlind@kth.se>2013-03-10 13:51:06 +0100
commit0a22d9dd01dab78ff68829fd2b0651592c8d56b4 (patch)
tree77bf41e208c335ee29a183c8cef2acbb3419d867
parent92482459963e21cb692c0515450abc81d69e40ed (diff)
downloadnova-0a22d9dd01dab78ff68829fd2b0651592c8d56b4.tar.gz
nova-0a22d9dd01dab78ff68829fd2b0651592c8d56b4.tar.xz
nova-0a22d9dd01dab78ff68829fd2b0651592c8d56b4.zip
Extended server attributes can show wrong hypervisor_hostname
When using the extended server status (EXT-SRV-STS) extension, it might produce the wrong hypervisor_hostname on multi-node drivers like baremetal. The db query used is incorrect and in fact not needed anymore, since the info is already available in the instance dict itself. This patch resolves the issue by instead using instance['node'] directly and further removes the no longer used compute_node_get_by_host query. Resolves bug 1135506. Change-Id: I641c4f59a088754fe68378ae4bf217c59056b1d1
-rw-r--r--nova/api/openstack/compute/contrib/extended_server_attributes.py17
-rw-r--r--nova/db/api.py4
-rw-r--r--nova/db/sqlalchemy/api.py9
-rw-r--r--nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py19
-rw-r--r--nova/tests/api/openstack/fakes.py3
5 files changed, 11 insertions, 41 deletions
diff --git a/nova/api/openstack/compute/contrib/extended_server_attributes.py b/nova/api/openstack/compute/contrib/extended_server_attributes.py
index dd332ff13..4f74f389d 100644
--- a/nova/api/openstack/compute/contrib/extended_server_attributes.py
+++ b/nova/api/openstack/compute/contrib/extended_server_attributes.py
@@ -17,8 +17,6 @@
from nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
-from nova import compute
-from nova import db
from nova.openstack.common import log as logging
LOG = logging.getLogger(__name__)
@@ -27,22 +25,9 @@ authorize = extensions.soft_extension_authorizer('compute',
class ExtendedServerAttributesController(wsgi.Controller):
- def __init__(self, *args, **kwargs):
- super(ExtendedServerAttributesController, self).__init__(*args,
- **kwargs)
- self.compute_api = compute.API()
-
- def _get_hypervisor_hostname(self, context, instance):
- compute_node = db.compute_node_get_by_host(context, instance["host"])
-
- try:
- return compute_node["hypervisor_hostname"]
- except TypeError:
- return
-
def _extend_server(self, context, server, instance):
key = "%s:hypervisor_hostname" % Extended_server_attributes.alias
- server[key] = self._get_hypervisor_hostname(context, instance)
+ server[key] = instance['node']
for attr in ['host', 'name']:
if attr == 'name':
diff --git a/nova/db/api.py b/nova/db/api.py
index fd932c9ef..eac31bee5 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -208,10 +208,6 @@ def compute_node_delete(context, compute_id):
return IMPL.compute_node_delete(context, compute_id)
-def compute_node_get_by_host(context, host):
- return IMPL.compute_node_get_by_host(context, host)
-
-
def compute_node_statistics(context):
return IMPL.compute_node_statistics(context)
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index 96c77bce3..0bd9cfce7 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -546,15 +546,6 @@ def compute_node_delete(context, compute_id):
raise exception.ComputeHostNotFound(host=compute_id)
-def compute_node_get_by_host(context, host):
- """Get all capacity entries for the given host."""
- result = model_query(context, models.ComputeNode, read_deleted="no").\
- join('service').\
- filter(models.Service.host == host).\
- first()
- return result
-
-
def compute_node_statistics(context):
"""Compute statistics over all compute nodes."""
result = model_query(context,
diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py
index ff5ab7ac5..78c2ff9ae 100644
--- a/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py
+++ b/nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py
@@ -18,7 +18,6 @@ import webob
from nova.api.openstack.compute.contrib import extended_server_attributes
from nova import compute
-from nova import db
from nova import exception
from nova.openstack.common import jsonutils
from nova import test
@@ -30,20 +29,17 @@ UUID3 = '00000000-0000-0000-0000-000000000003'
def fake_compute_get(*args, **kwargs):
- return fakes.stub_instance(1, uuid=UUID3, host="host-fake")
+ return fakes.stub_instance(1, uuid=UUID3, host="host-fake",
+ node="node-fake")
def fake_compute_get_all(*args, **kwargs):
return [
- fakes.stub_instance(1, uuid=UUID1, host="host-1"),
- fakes.stub_instance(2, uuid=UUID2, host="host-2")
+ fakes.stub_instance(1, uuid=UUID1, host="host-1", node="node-1"),
+ fakes.stub_instance(2, uuid=UUID2, host="host-2", node="node-2")
]
-def fake_cn_get(context, host):
- return {"hypervisor_hostname": host}
-
-
class ExtendedServerAttributesTest(test.TestCase):
content_type = 'application/json'
prefix = 'OS-EXT-SRV-ATTR:'
@@ -53,7 +49,6 @@ class ExtendedServerAttributesTest(test.TestCase):
fakes.stub_out_nw_api(self.stubs)
self.stubs.Set(compute.api.API, 'get', fake_compute_get)
self.stubs.Set(compute.api.API, 'get_all', fake_compute_get_all)
- self.stubs.Set(db, 'compute_node_get_by_host', fake_cn_get)
self.flags(
osapi_compute_extension=[
'nova.api.openstack.compute.contrib.select_extensions'],
@@ -71,12 +66,12 @@ class ExtendedServerAttributesTest(test.TestCase):
def _get_servers(self, body):
return jsonutils.loads(body).get('servers')
- def assertServerAttributes(self, server, host, instance_name):
+ def assertServerAttributes(self, server, host, node, instance_name):
self.assertEqual(server.get('%shost' % self.prefix), host)
self.assertEqual(server.get('%sinstance_name' % self.prefix),
instance_name)
self.assertEqual(server.get('%shypervisor_hostname' % self.prefix),
- host)
+ node)
def test_show(self):
url = '/v2/fake/servers/%s' % UUID3
@@ -85,6 +80,7 @@ class ExtendedServerAttributesTest(test.TestCase):
self.assertEqual(res.status_int, 200)
self.assertServerAttributes(self._get_server(res.body),
host='host-fake',
+ node='node-fake',
instance_name='instance-1')
def test_detail(self):
@@ -95,6 +91,7 @@ class ExtendedServerAttributesTest(test.TestCase):
for i, server in enumerate(self._get_servers(res.body)):
self.assertServerAttributes(server,
host='host-%s' % (i + 1),
+ node='node-%s' % (i + 1),
instance_name='instance-%s' % (i + 1))
def test_no_instance_passthrough_404(self):
diff --git a/nova/tests/api/openstack/fakes.py b/nova/tests/api/openstack/fakes.py
index 97321212c..936dd622b 100644
--- a/nova/tests/api/openstack/fakes.py
+++ b/nova/tests/api/openstack/fakes.py
@@ -412,7 +412,7 @@ def fake_instance_get_all_by_filters(num_servers=5, **kwargs):
def stub_instance(id, user_id=None, project_id=None, host=None,
- vm_state=None, task_state=None,
+ node=None, vm_state=None, task_state=None,
reservation_id="", uuid=FAKE_UUID, image_ref="10",
flavor_id="1", name=None, key_name='',
access_ipv4=None, access_ipv6=None, progress=0,
@@ -477,6 +477,7 @@ def stub_instance(id, user_id=None, project_id=None, host=None,
"ephemeral_gb": 0,
"hostname": display_name or server_name,
"host": host,
+ "node": node,
"instance_type_id": 1,
"instance_type": dict(inst_type),
"user_data": "",