Skip to content

Instantly share code, notes, and snippets.

@vishvananda
Created March 10, 2012 23:12
Show Gist options
  • Select an option

  • Save vishvananda/2013851 to your computer and use it in GitHub Desktop.

Select an option

Save vishvananda/2013851 to your computer and use it in GitHub Desktop.
diff --git a/nova/api/openstack/compute/contrib/extended_server_attributes.py b/nova/api/openstack/compute/contrib/extended_server_attributes.py
index c1c85c6..a4794d7 100644
--- a/nova/api/openstack/compute/contrib/extended_server_attributes.py
+++ b/nova/api/openstack/compute/contrib/extended_server_attributes.py
@@ -69,7 +69,7 @@ class ExtendedServerAttributesController(wsgi.Controller):
context = req.environ['nova.context']
if authorize(context):
# Attach our slave template to the response object
- resp_obj.attach(xml=ExtendedServerAttributesTemplate())
+ resp_obj.attach(xml=ExtendedServerAttributeTemplate())
try:
instance = self.compute_api.get(context, id)
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 9944fc0..de8fa55 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
@@ -16,7 +16,9 @@
import json
import webob
+from lxml import etree
+from nova.api.openstack.compute.contrib import extended_server_attributes
from nova import compute
from nova import exception
from nova import flags
@@ -44,6 +46,7 @@ def fake_compute_get_all(*args, **kwargs):
class ExtendedServerAttributesTest(test.TestCase):
+ content_type = 'application/json'
def setUp(self):
super(ExtendedServerAttributesTest, self).setUp()
@@ -53,10 +56,16 @@ class ExtendedServerAttributesTest(test.TestCase):
def _make_request(self, url):
req = webob.Request.blank(url)
- req.headers['Accept'] = 'application/json'
+ req.headers['Accept'] = self.content_type
res = req.get_response(fakes.wsgi_app())
return res
+ def _get_server(self, body):
+ return json.loads(body).get('server')
+
+ def _get_servers(self, body):
+ return json.loads(body).get('servers')
+
def assertServerAttributes(self, server, host, instance_name):
self.assertEqual(server.get('OS-EXT-SRV-ATTR:host'), host)
self.assertEqual(server.get('OS-EXT-SRV-ATTR:instance_name'),
@@ -65,20 +74,18 @@ class ExtendedServerAttributesTest(test.TestCase):
def test_show(self):
url = '/v2/fake/servers/%s' % UUID3
res = self._make_request(url)
- body = json.loads(res.body)
self.assertEqual(res.status_int, 200)
- self.assertServerAttributes(body['server'],
+ self.assertServerAttributes(self._get_server(res.body),
host='host-fake',
instance_name='instance-1')
def test_detail(self):
url = '/v2/fake/servers/detail'
res = self._make_request(url)
- body = json.loads(res.body)
self.assertEqual(res.status_int, 200)
- for i, server in enumerate(body['servers']):
+ for i, server in enumerate(self._get_servers(res.body)):
self.assertServerAttributes(server,
host='host-%s' % (i + 1),
instance_name='instance-%s' % (i + 1))
@@ -93,3 +100,19 @@ class ExtendedServerAttributesTest(test.TestCase):
res = self._make_request(url)
self.assertEqual(res.status_int, 404)
+
+class ExtendedServerAttributesXmlTest(ExtendedServerAttributesTest):
+ content_type = 'application/xml'
+
+ def _get_server(self, body):
+ return etree.XML(body)
+
+ def _get_servers(self, body):
+ return etree.XML(body).getchildren()
+
+ def assertServerAttributes(self, server, host, instance_name):
+ ext = extended_server_attributes.Extended_server_attributes
+ self.assertEqual(server.get('{%s}host' % ext.namespace), host)
+ self.assertEqual(server.get('{%s}instance_name' % ext.namespace),
+ instance_name)
+
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment