From 80bd1de65a3b8e7502ece9cedca3c027d176de39 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 7 Feb 2013 14:46:08 -0800 Subject: Simplify and optimize az server output extension. Displaying two different az results to users is confusing, so just return the az that the instance is actually in. Also, cache the result from looking up the az by host for an hour to avoid making lots of expensive db requests. DocImpact Change-Id: Ib39bf94c608874695aab00e61035e64f9594a985 --- .../contrib/test_extended_availability_zone.py | 30 ++++++++++------------ .../api_samples/OS-EXT-AZ/server-get-resp.json.tpl | 3 +-- .../api_samples/OS-EXT-AZ/server-get-resp.xml.tpl | 2 +- .../OS-EXT-AZ/servers-detail-resp.json.tpl | 3 +-- .../OS-EXT-AZ/servers-detail-resp.xml.tpl | 2 +- .../all_extensions/server-get-resp.json.tpl | 3 +-- .../all_extensions/server-get-resp.xml.tpl | 2 +- .../all_extensions/servers-details-resp.json.tpl | 3 +-- .../all_extensions/servers-details-resp.xml.tpl | 2 +- 9 files changed, 22 insertions(+), 28 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/compute/contrib/test_extended_availability_zone.py b/nova/tests/api/openstack/compute/contrib/test_extended_availability_zone.py index 8ebd810ac..d847e54f9 100644 --- a/nova/tests/api/openstack/compute/contrib/test_extended_availability_zone.py +++ b/nova/tests/api/openstack/compute/contrib/test_extended_availability_zone.py @@ -17,6 +17,7 @@ from lxml import etree import webob from nova.api.openstack.compute.contrib import extended_availability_zone +from nova import availability_zones from nova import compute from nova import exception from nova.openstack.common import jsonutils @@ -29,19 +30,20 @@ UUID3 = '00000000-0000-0000-0000-000000000003' def fake_compute_get(*args, **kwargs): - inst = fakes.stub_instance(1, uuid=UUID3, host="host-fake") - inst['availability_zone'] = 'az-i' + inst = fakes.stub_instance(1, uuid=UUID3, host="get-host") return inst def fake_compute_get_all(*args, **kwargs): - inst1 = fakes.stub_instance(1, uuid=UUID1, host="host-1") - inst2 = fakes.stub_instance(2, uuid=UUID2, host="host-2") - inst1['availability_zone'] = 'az-i' - inst2['availability_zone'] = 'az-i' + inst1 = fakes.stub_instance(1, uuid=UUID1, host="all-host") + inst2 = fakes.stub_instance(2, uuid=UUID2, host="all-host") return [inst1, inst2] +def fake_get_host_availability_zone(context, host): + return host + + class ExtendedServerAttributesTest(test.TestCase): content_type = 'application/json' prefix = 'OS-EXT-AZ:' @@ -51,6 +53,8 @@ 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(availability_zones, 'get_host_availability_zone', + fake_get_host_availability_zone) self.flags( osapi_compute_extension=[ @@ -69,20 +73,16 @@ class ExtendedServerAttributesTest(test.TestCase): def _get_servers(self, body): return jsonutils.loads(body).get('servers') - def assertServerAttributes(self, server, az_instance, az_host): + def assertServerAttributes(self, server, az): self.assertEqual(server.get('%savailability_zone' % self.prefix), - az_instance) - self.assertEqual(server.get('%shost_availability_zone' % self.prefix), - az_host) + az) def test_show(self): url = '/v2/fake/servers/%s' % UUID3 res = self._make_request(url) self.assertEqual(res.status_int, 200) - self.assertServerAttributes(self._get_server(res.body), - az_instance='az-i', - az_host='nova') + self.assertServerAttributes(self._get_server(res.body), 'get-host') def test_detail(self): url = '/v2/fake/servers/detail' @@ -90,9 +90,7 @@ class ExtendedServerAttributesTest(test.TestCase): self.assertEqual(res.status_int, 200) for i, server in enumerate(self._get_servers(res.body)): - self.assertServerAttributes(server, - az_instance='az-i', - az_host='nova') + self.assertServerAttributes(server, 'all-host') def test_no_instance_passthrough_404(self): diff --git a/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.json.tpl b/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.json.tpl index 25915610d..413f3ce95 100644 --- a/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.json.tpl @@ -2,8 +2,7 @@ "server": { "updated": "%(timestamp)s", "created": "%(timestamp)s", - "OS-EXT-AZ:availability_zone": null, - "OS-EXT-AZ:host_availability_zone": "nova", + "OS-EXT-AZ:availability_zone": "nova", "accessIPv4": "", "accessIPv6": "", "addresses": { diff --git a/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.xml.tpl b/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.xml.tpl index 1cdbd2012..849b9b750 100644 --- a/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/OS-EXT-AZ/server-get-resp.xml.tpl @@ -1,5 +1,5 @@ - + diff --git a/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.json.tpl b/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.json.tpl index 895f0a514..362c85085 100644 --- a/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.json.tpl +++ b/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.json.tpl @@ -3,8 +3,7 @@ { "updated": "%(timestamp)s", "created": "%(timestamp)s", - "OS-EXT-AZ:availability_zone": null, - "OS-EXT-AZ:host_availability_zone": "nova", + "OS-EXT-AZ:availability_zone": "nova", "accessIPv4": "", "accessIPv6": "", "addresses": { diff --git a/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.xml.tpl b/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.xml.tpl index 15cd9b1e1..9cd820cd0 100644 --- a/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/OS-EXT-AZ/servers-detail-resp.xml.tpl @@ -1,5 +1,5 @@ - + diff --git a/nova/tests/integrated/api_samples/all_extensions/server-get-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/server-get-resp.json.tpl index fefa37b4d..ccefc2dc7 100644 --- a/nova/tests/integrated/api_samples/all_extensions/server-get-resp.json.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/server-get-resp.json.tpl @@ -1,8 +1,7 @@ { "server": { "OS-DCF:diskConfig": "AUTO", - "OS-EXT-AZ:availability_zone": null, - "OS-EXT-AZ:host_availability_zone": "nova", + "OS-EXT-AZ:availability_zone": "nova", "OS-EXT-SRV-ATTR:host": "%(compute_host)s", "OS-EXT-SRV-ATTR:hypervisor_hostname": "%(hypervisor_hostname)s", "OS-EXT-SRV-ATTR:instance_name": "instance-00000001", diff --git a/nova/tests/integrated/api_samples/all_extensions/server-get-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/server-get-resp.xml.tpl index 4ba06b42e..973305854 100644 --- a/nova/tests/integrated/api_samples/all_extensions/server-get-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/server-get-resp.xml.tpl @@ -1,5 +1,5 @@ - + diff --git a/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.json.tpl b/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.json.tpl index 667ef6471..d50088837 100644 --- a/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.json.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.json.tpl @@ -2,8 +2,7 @@ "servers": [ { "OS-DCF:diskConfig": "AUTO", - "OS-EXT-AZ:availability_zone": null, - "OS-EXT-AZ:host_availability_zone": "nova", + "OS-EXT-AZ:availability_zone": "nova", "OS-EXT-SRV-ATTR:host": "%(compute_host)s", "OS-EXT-SRV-ATTR:hypervisor_hostname": "%(hypervisor_hostname)s", "OS-EXT-SRV-ATTR:instance_name": "instance-00000001", diff --git a/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.xml.tpl index 104c82bc5..e2166c2ff 100644 --- a/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/servers-details-resp.xml.tpl @@ -1,6 +1,6 @@ - + -- cgit