diff options
| author | Hans Lindgren <hanlind@kth.se> | 2013-02-28 11:00:29 +0100 |
|---|---|---|
| committer | Hans Lindgren <hanlind@kth.se> | 2013-03-10 13:51:06 +0100 |
| commit | 0a22d9dd01dab78ff68829fd2b0651592c8d56b4 (patch) | |
| tree | 77bf41e208c335ee29a183c8cef2acbb3419d867 /nova/tests | |
| parent | 92482459963e21cb692c0515450abc81d69e40ed (diff) | |
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
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/api/openstack/compute/contrib/test_extended_server_attributes.py | 19 | ||||
| -rw-r--r-- | nova/tests/api/openstack/fakes.py | 3 |
2 files changed, 10 insertions, 12 deletions
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": "", |
