From 7498fa608def9613552cf0e26dcb03fddf7b298d Mon Sep 17 00:00:00 2001 From: John Tran Date: Fri, 15 Jul 2011 22:56:16 +0000 Subject: renamed priv method arg_to_dict since it's not just used for revoke. modified to conform to latest AWS EC2 API spec for authorize & revoke ingress params using the IpPermissions data structure, which nests lists of CIDR blocks (IpRanges) as well as lists of Group data --- nova/tests/test_cloud.py | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index d71a03aff..7becf1963 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -239,25 +239,60 @@ class CloudTestCase(test.TestCase): delete = self.cloud.delete_security_group self.assertRaises(exception.ApiError, delete, self.context) - def test_authorize_revoke_security_group_ingress(self): + def test_authorize_security_group_ingress(self): kwargs = {'project_id': self.context.project_id, 'name': 'test'} sec = db.security_group_create(self.context, kwargs) authz = self.cloud.authorize_security_group_ingress kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} - authz(self.context, group_name=sec['name'], **kwargs) + self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + + def test_authorize_security_group_ingress_ip_permissions_ip_ranges(self): + kwargs = {'project_id': self.context.project_id, 'name': 'test'} + sec = db.security_group_create(self.context, kwargs) + authz = self.cloud.authorize_security_group_ingress + kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, + 'ip_ranges': {'1': {'cidr_ip': u'0.0.0.0/0'}, + '2': {'cidr_ip': u'10.10.10.10/32'}}, + 'ip_protocol': u'tcp'}]} + self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + + def test_authorize_security_group_ingress_ip_permissions_groups(self): + kwargs = {'project_id': self.context.project_id, 'name': 'test'} + sec = db.security_group_create(self.context, kwargs) + authz = self.cloud.authorize_security_group_ingress + kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, + 'ip_ranges': {'1': {'cidr_ip': u'0.0.0.0/0'}, '2': {'cidr_ip': u'10.10.10.10/32'}}, + 'groups': {'1': {'user_id': u'someuser', 'group_name': u'somegroup1'}, + '2': {'user_id': u'someuser', 'group_name': u'othergroup2'}}, + 'ip_protocol': u'tcp'}]} + self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) + + def test_revoke_security_group_ingress(self): + kwargs = {'project_id': self.context.project_id, 'name': 'test'} + sec = db.security_group_create(self.context, kwargs) + authz = self.cloud.authorize_security_group_ingress + kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} + authz(self.context, group_id=sec['id'], **kwargs) revoke = self.cloud.revoke_security_group_ingress self.assertTrue(revoke(self.context, group_name=sec['name'], **kwargs)) - def test_authorize_revoke_security_group_ingress_by_id(self): - sec = db.security_group_create(self.context, - {'project_id': self.context.project_id, - 'name': 'test'}) + def test_revoke_security_group_ingress_by_id(self): + kwargs = {'project_id': self.context.project_id, 'name': 'test'} + sec = db.security_group_create(self.context, kwargs) authz = self.cloud.authorize_security_group_ingress kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} authz(self.context, group_id=sec['id'], **kwargs) revoke = self.cloud.revoke_security_group_ingress self.assertTrue(revoke(self.context, group_id=sec['id'], **kwargs)) + def test_authorize_security_group_ingress_by_id(self): + sec = db.security_group_create(self.context, + {'project_id': self.context.project_id, + 'name': 'test'}) + authz = self.cloud.authorize_security_group_ingress + kwargs = {'to_port': '999', 'from_port': '999', 'ip_protocol': 'tcp'} + self.assertTrue(authz(self.context, group_id=sec['id'], **kwargs)) + def test_authorize_security_group_ingress_missing_protocol_params(self): sec = db.security_group_create(self.context, {'project_id': self.context.project_id, -- cgit From ab42384131077bae3986141279b605d8f994143c Mon Sep 17 00:00:00 2001 From: John Tran Date: Mon, 18 Jul 2011 03:45:16 +0000 Subject: resolved pep8 issues --- nova/tests/test_cloud.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index 7becf1963..0dc0b2d53 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -251,8 +251,9 @@ class CloudTestCase(test.TestCase): sec = db.security_group_create(self.context, kwargs) authz = self.cloud.authorize_security_group_ingress kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, - 'ip_ranges': {'1': {'cidr_ip': u'0.0.0.0/0'}, - '2': {'cidr_ip': u'10.10.10.10/32'}}, + 'ip_ranges': + {'1': {'cidr_ip': u'0.0.0.0/0'}, + '2': {'cidr_ip': u'10.10.10.10/32'}}, 'ip_protocol': u'tcp'}]} self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) @@ -261,9 +262,12 @@ class CloudTestCase(test.TestCase): sec = db.security_group_create(self.context, kwargs) authz = self.cloud.authorize_security_group_ingress kwargs = {'ip_permissions': [{'to_port': 81, 'from_port': 81, - 'ip_ranges': {'1': {'cidr_ip': u'0.0.0.0/0'}, '2': {'cidr_ip': u'10.10.10.10/32'}}, - 'groups': {'1': {'user_id': u'someuser', 'group_name': u'somegroup1'}, - '2': {'user_id': u'someuser', 'group_name': u'othergroup2'}}, + 'ip_ranges':{'1': {'cidr_ip': u'0.0.0.0/0'}, + '2': {'cidr_ip': u'10.10.10.10/32'}}, + 'groups': {'1': {'user_id': u'someuser', + 'group_name': u'somegroup1'}, + '2': {'user_id': u'someuser', + 'group_name': u'othergroup2'}}, 'ip_protocol': u'tcp'}]} self.assertTrue(authz(self.context, group_name=sec['name'], **kwargs)) -- cgit From 848de98876aecd084bb568907c3b121a7f5e38f0 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 21 Jul 2011 12:45:53 -0500 Subject: allow 2 dns servers to be specified on network create --- nova/tests/__init__.py | 3 ++- nova/tests/test_network.py | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index 7df6c06eb..49c1ccc56 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -67,7 +67,8 @@ def setup(): bridge=FLAGS.flat_network_bridge, bridge_interface=bridge_interface, vpn_start=FLAGS.vpn_start, - vlan_start=FLAGS.vlan_start) + vlan_start=FLAGS.vlan_start, + dns=FLAGS.flat_network_dns) for net in db.network_get_all(ctxt): network.set_network_host(ctxt, net) diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index 7cc174842..9fefc6959 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -56,6 +56,7 @@ networks = [{'id': 0, 'gateway': '192.168.0.1', 'broadcast': '192.168.0.255', 'dns': '192.168.0.1', + 'dns2': '192.168.0.2', 'vlan': None, 'host': None, 'project_id': 'fake_project', @@ -74,6 +75,7 @@ networks = [{'id': 0, 'gateway': '192.168.1.1', 'broadcast': '192.168.1.255', 'dns': '192.168.0.1', + 'dns2': '192.168.0.2', 'vlan': None, 'host': None, 'project_id': 'fake_project', -- cgit From af5c549d7795fcf9fdcb7d8e9193aa985f121fc6 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Thu, 21 Jul 2011 15:08:46 -0400 Subject: Moving lp:~rackspace-titan/nova/extensions-xml-serialization to new branch based off of trunk. To remove dep on another branch. --- nova/tests/api/openstack/test_extensions.py | 113 +++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 3 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 697c62e5c..6d3c1b1be 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -16,10 +16,11 @@ # under the License. import json +import os.path import stubout import unittest import webob -import os.path +from xml.etree import ElementTree from nova import context from nova import flags @@ -80,19 +81,73 @@ class StubExtensionManager(object): class ExtensionControllerTest(unittest.TestCase): - def test_index(self): + def setUp(self): + FLAGS.osapi_extensions_path = os.path.join( + os.path.dirname(__file__), "extensions") + + def test_list_extensions_json(self): app = openstack.APIRouterV11() ext_midware = extensions.ExtensionMiddleware(app) request = webob.Request.blank("/extensions") response = request.get_response(ext_midware) self.assertEqual(200, response.status_int) - def test_get_by_alias(self): + # Make sure we have all the extensions. + data = json.loads(response.body) + names = [x['name'] for x in data['extensions']] + names.sort() + self.assertEqual(names, ["FlavorExtraSpecs", "Floating_ips", + "Fox In Socks", "Hosts", "Multinic", "Volumes"]) + + # Make sure that at least Fox in Sox is correct. + (fox_ext,) = [ + x for x in data['extensions'] if x['alias'] == 'FOXNSOX'] + self.assertEqual(fox_ext, { + "namespace" : "http://www.fox.in.socks/api/ext/pie/v1.0", + "name" : "Fox In Socks", + "updated" : "2011-01-22T13:25:27-06:00", + "description" : "The Fox In Socks Extension", + "alias" : "FOXNSOX", + "links" : [] + } + ) + + def test_get_extension_json(self): + app = openstack.APIRouterV11() + ext_midware = extensions.ExtensionMiddleware(app) + request = webob.Request.blank("/extensions/FOXNSOX") + response = request.get_response(ext_midware) + self.assertEqual(200, response.status_int) + + data = json.loads(response.body) + self.assertEqual(data['extension'], { + "namespace" : "http://www.fox.in.socks/api/ext/pie/v1.0", + "name" : "Fox In Socks", + "updated" : "2011-01-22T13:25:27-06:00", + "description" : "The Fox In Socks Extension", + "alias" : "FOXNSOX", + "links" : [] + } + ) + + def test_get_extension_xml(self): app = openstack.APIRouterV11() ext_midware = extensions.ExtensionMiddleware(app) request = webob.Request.blank("/extensions/FOXNSOX") + request.accept = "application/xml" response = request.get_response(ext_midware) self.assertEqual(200, response.status_int) + print response.body + + elem = ElementTree.XML(response.body.replace(" ", "")) + self.assertEqual(elem.get('alias'), 'FOXNSOX') + self.assertEqual(elem.get('name'), 'Fox In Socks') + self.assertEqual(elem.get('namespace'), + 'http://www.fox.in.socks/api/ext/pie/v1.0') + self.assertEqual(elem.get('updated'), '2011-01-22T13:25:27-06:00') + ns = "{http://docs.openstack.org/compute/api/v1.1}" + self.assertEqual(elem.findtext('{0}description'.format(ns)), + 'The Fox In Socks Extension') class ResourceExtensionTest(unittest.TestCase): @@ -244,3 +299,55 @@ class RequestExtensionTest(unittest.TestCase): response_data = json.loads(response.body) self.assertEqual('newblue', response_data['flavor']['googoose']) self.assertEqual("Pig Bands!", response_data['big_bands']) + +class ExtensionsXMLSerializerTest(unittest.TestCase): + def test_serialize(self): + serializer = extensions.ExtensionsXMLSerializer() + data = { + 'extension': { + 'name': 'ext1', + "namespace" : "http://docs.rack.com/servers/api/ext/pie/v1.0", + "alias" : "RS-PIE", + "updated" : "2011-01-22T13:25:27-06:00", + "description" : "Adds the capability to share an image.", + "links" : [ + { + "rel" : "describedby", + "type" : "application/pdf", + "href" : "http://docs.rack.com/servers/api/ext/cs.pdf" + }, + { + "rel" : "describedby", + "type" : "application/vnd.sun.wadl+xml", + "href" : "http://docs.rack.com/servers/api/ext/cs.wadl" + } + ] + }, + } + + ns = "{http://docs.openstack.org/compute/api/v1.1}" + atomns = "{http://www.w3.org/2005/Atom}" + elem = ElementTree.XML(serializer.serialize(data, 'show')) + self.assertEqual(elem.tag.split('extension')[0], ns) + self.assertEqual(elem.get('alias'), 'RS-PIE') + self.assertEqual(elem.get('name'), 'ext1') + self.assertEqual(elem.get('namespace'), + 'http://docs.rack.com/servers/api/ext/pie/v1.0') + self.assertEqual(elem.get('updated'), '2011-01-22T13:25:27-06:00') + self.assertEqual(elem.findtext('{0}description'.format(ns)), + 'Adds the capability to share an image.') + + link_nodes = elem.findall('{0}link'.format(atomns)) + self.assertEqual(len(link_nodes), 2) + link_nodes.sort(key=lambda x: x.get('type')) + + self.assertEqual(link_nodes[0].get('type'), 'application/pdf') + self.assertEqual(link_nodes[0].get('rel'), 'describedby') + self.assertEqual(link_nodes[0].get('href'), + 'http://docs.rack.com/servers/api/ext/cs.pdf') + + self.assertEqual(link_nodes[1].get('type'), + 'application/vnd.sun.wadl+xml') + self.assertEqual(link_nodes[1].get('rel'), 'describedby') + self.assertEqual(link_nodes[1].get('href'), + 'http://docs.rack.com/servers/api/ext/cs.wadl') -- cgit From f087db34b840a74f9ba093128808230fd97ea9ec Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Thu, 21 Jul 2011 16:20:32 -0500 Subject: pep8 --- nova/tests/api/openstack/test_versions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_versions.py b/nova/tests/api/openstack/test_versions.py index 0eae18a62..da964ee1f 100644 --- a/nova/tests/api/openstack/test_versions.py +++ b/nova/tests/api/openstack/test_versions.py @@ -174,7 +174,7 @@ class VersionsTest(test.TestCase): { "rel": "self", "href": "http://test/2.7.1", - } + }, ], }, ] @@ -204,7 +204,7 @@ class VersionsTest(test.TestCase): { "rel": "self", "href": "http://test/2.9.8", - } + }, ], }, ] -- cgit From 16aa079b933a8788c926745e0794d85558d442a8 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Thu, 21 Jul 2011 22:35:26 -0400 Subject: Added xml serialization for GET => /extensions. Added corresponding tests. --- nova/tests/api/openstack/test_extensions.py | 72 ++++++++++++++++++++--------- 1 file changed, 50 insertions(+), 22 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 6d3c1b1be..c651c030a 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -103,12 +103,12 @@ class ExtensionControllerTest(unittest.TestCase): (fox_ext,) = [ x for x in data['extensions'] if x['alias'] == 'FOXNSOX'] self.assertEqual(fox_ext, { - "namespace" : "http://www.fox.in.socks/api/ext/pie/v1.0", - "name" : "Fox In Socks", - "updated" : "2011-01-22T13:25:27-06:00", - "description" : "The Fox In Socks Extension", - "alias" : "FOXNSOX", - "links" : [] + 'namespace' : 'http://www.fox.in.socks/api/ext/pie/v1.0', + 'name' : 'Fox In Socks', + 'updated' : '2011-01-22T13:25:27-06:00', + 'description' : 'The Fox In Socks Extension', + 'alias' : 'FOXNSOX', + 'links' : [] } ) @@ -130,6 +130,32 @@ class ExtensionControllerTest(unittest.TestCase): } ) + def test_list_extensions_xml(self): + app = openstack.APIRouterV11() + ext_midware = extensions.ExtensionMiddleware(app) + request = webob.Request.blank("/extensions") + request.accept = "application/xml" + response = request.get_response(ext_midware) + self.assertEqual(200, response.status_int) + print response.body + + ns = "{http://docs.openstack.org/compute/api/v1.1}" + root = ElementTree.XML(response.body) + self.assertEqual(root.tag, 'extensions') + + # Make sure we have all the extensions. + exts = root.findall('{0}extension'.format(ns)) + self.assertEqual(len(exts), 6) + + # Make sure that at least Fox in Sox is correct. + (fox_ext,) = [ x for x in exts if x.get('alias') == 'FOXNSOX' ] + self.assertEqual(fox_ext.get('name'), 'Fox In Socks') + self.assertEqual(fox_ext.get('namespace'), + 'http://www.fox.in.socks/api/ext/pie/v1.0') + self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00') + self.assertEqual(fox_ext.findtext('{0}description'.format(ns)), + 'The Fox In Socks Extension') + def test_get_extension_xml(self): app = openstack.APIRouterV11() ext_midware = extensions.ExtensionMiddleware(app) @@ -139,14 +165,15 @@ class ExtensionControllerTest(unittest.TestCase): self.assertEqual(200, response.status_int) print response.body - elem = ElementTree.XML(response.body.replace(" ", "")) - self.assertEqual(elem.get('alias'), 'FOXNSOX') - self.assertEqual(elem.get('name'), 'Fox In Socks') - self.assertEqual(elem.get('namespace'), - 'http://www.fox.in.socks/api/ext/pie/v1.0') - self.assertEqual(elem.get('updated'), '2011-01-22T13:25:27-06:00') + root = ElementTree.XML(response.body) ns = "{http://docs.openstack.org/compute/api/v1.1}" - self.assertEqual(elem.findtext('{0}description'.format(ns)), + self.assertEqual(root.tag.split('extension')[0], ns) + self.assertEqual(root.get('alias'), 'FOXNSOX') + self.assertEqual(root.get('name'), 'Fox In Socks') + self.assertEqual(root.get('namespace'), + 'http://www.fox.in.socks/api/ext/pie/v1.0') + self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00') + self.assertEqual(root.findtext('{0}description'.format(ns)), 'The Fox In Socks Extension') @@ -247,7 +274,7 @@ class ActionExtensionTest(unittest.TestCase): def test_invalid_action(self): body = dict(blah=dict(name="test")) - response = self._send_server_action_request("/asdf/1/action", body) + response = self._send_server_action_request("/fdsa/1/action", body) self.assertEqual(404, response.status_int) @@ -327,17 +354,18 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): ns = "{http://docs.openstack.org/compute/api/v1.1}" atomns = "{http://www.w3.org/2005/Atom}" - elem = ElementTree.XML(serializer.serialize(data, 'show')) - self.assertEqual(elem.tag.split('extension')[0], ns) - self.assertEqual(elem.get('alias'), 'RS-PIE') - self.assertEqual(elem.get('name'), 'ext1') - self.assertEqual(elem.get('namespace'), + xml = serializer.serialize(data, 'show') + root = ElementTree.XML(xml) + self.assertEqual(root.tag.split('extension')[0], ns) + self.assertEqual(root.get('alias'), 'RS-PIE') + self.assertEqual(root.get('name'), 'ext1') + self.assertEqual(root.get('namespace'), 'http://docs.rack.com/servers/api/ext/pie/v1.0') - self.assertEqual(elem.get('updated'), '2011-01-22T13:25:27-06:00') - self.assertEqual(elem.findtext('{0}description'.format(ns)), + self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00') + self.assertEqual(root.findtext('{0}description'.format(ns)), 'Adds the capability to share an image.') - link_nodes = elem.findall('{0}link'.format(atomns)) + link_nodes = root.findall('{0}link'.format(atomns)) self.assertEqual(len(link_nodes), 2) link_nodes.sort(key=lambda x: x.get('type')) -- cgit From c83546c0c9d077fb69caf1d782e8cb420e399a20 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Thu, 21 Jul 2011 23:36:40 -0400 Subject: Correctly add xml namespaces to extensions xml. --- nova/tests/api/openstack/test_extensions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index c651c030a..55f16e9d4 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -141,7 +141,7 @@ class ExtensionControllerTest(unittest.TestCase): ns = "{http://docs.openstack.org/compute/api/v1.1}" root = ElementTree.XML(response.body) - self.assertEqual(root.tag, 'extensions') + self.assertEqual(root.tag.split('extensions')[0], ns) # Make sure we have all the extensions. exts = root.findall('{0}extension'.format(ns)) -- cgit From 7066537c32da8acaff0266634383efaccdfc6e9c Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Fri, 22 Jul 2011 14:17:37 -0400 Subject: pep8 fixes --- nova/tests/api/openstack/test_extensions.py | 57 +++++++++++++++-------------- 1 file changed, 29 insertions(+), 28 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 55f16e9d4..f3c9d9423 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -103,12 +103,12 @@ class ExtensionControllerTest(unittest.TestCase): (fox_ext,) = [ x for x in data['extensions'] if x['alias'] == 'FOXNSOX'] self.assertEqual(fox_ext, { - 'namespace' : 'http://www.fox.in.socks/api/ext/pie/v1.0', - 'name' : 'Fox In Socks', - 'updated' : '2011-01-22T13:25:27-06:00', - 'description' : 'The Fox In Socks Extension', - 'alias' : 'FOXNSOX', - 'links' : [] + 'namespace': 'http://www.fox.in.socks/api/ext/pie/v1.0', + 'name': 'Fox In Socks', + 'updated': '2011-01-22T13:25:27-06:00', + 'description': 'The Fox In Socks Extension', + 'alias': 'FOXNSOX', + 'links': [] } ) @@ -121,12 +121,12 @@ class ExtensionControllerTest(unittest.TestCase): data = json.loads(response.body) self.assertEqual(data['extension'], { - "namespace" : "http://www.fox.in.socks/api/ext/pie/v1.0", - "name" : "Fox In Socks", - "updated" : "2011-01-22T13:25:27-06:00", - "description" : "The Fox In Socks Extension", - "alias" : "FOXNSOX", - "links" : [] + "namespace": "http://www.fox.in.socks/api/ext/pie/v1.0", + "name": "Fox In Socks", + "updated": "2011-01-22T13:25:27-06:00", + "description": "The Fox In Socks Extension", + "alias": "FOXNSOX", + "links": [] } ) @@ -148,7 +148,7 @@ class ExtensionControllerTest(unittest.TestCase): self.assertEqual(len(exts), 6) # Make sure that at least Fox in Sox is correct. - (fox_ext,) = [ x for x in exts if x.get('alias') == 'FOXNSOX' ] + (fox_ext,) = [x for x in exts if x.get('alias') == 'FOXNSOX'] self.assertEqual(fox_ext.get('name'), 'Fox In Socks') self.assertEqual(fox_ext.get('namespace'), 'http://www.fox.in.socks/api/ext/pie/v1.0') @@ -327,29 +327,30 @@ class RequestExtensionTest(unittest.TestCase): self.assertEqual('newblue', response_data['flavor']['googoose']) self.assertEqual("Pig Bands!", response_data['big_bands']) + class ExtensionsXMLSerializerTest(unittest.TestCase): def test_serialize(self): serializer = extensions.ExtensionsXMLSerializer() data = { 'extension': { 'name': 'ext1', - "namespace" : "http://docs.rack.com/servers/api/ext/pie/v1.0", - "alias" : "RS-PIE", - "updated" : "2011-01-22T13:25:27-06:00", - "description" : "Adds the capability to share an image.", - "links" : [ + 'namespace': 'http://docs.rack.com/servers/api/ext/pie/v1.0', + 'alias': 'RS-PIE', + 'updated': '2011-01-22T13:25:27-06:00', + 'description': 'Adds the capability to share an image.', + 'links': [ { - "rel" : "describedby", - "type" : "application/pdf", - "href" : "http://docs.rack.com/servers/api/ext/cs.pdf" + 'rel': 'describedby', + 'type': 'application/pdf', + 'href': 'http://docs.rack.com/servers/api/ext/cs.pdf' }, { - "rel" : "describedby", - "type" : "application/vnd.sun.wadl+xml", - "href" : "http://docs.rack.com/servers/api/ext/cs.wadl" + 'rel': 'describedby', + 'type': 'application/vnd.sun.wadl+xml', + 'href': 'http://docs.rack.com/servers/api/ext/cs.wadl' } ] - }, + } } ns = "{http://docs.openstack.org/compute/api/v1.1}" @@ -371,11 +372,11 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): self.assertEqual(link_nodes[0].get('type'), 'application/pdf') self.assertEqual(link_nodes[0].get('rel'), 'describedby') - self.assertEqual(link_nodes[0].get('href'), + self.assertEqual(link_nodes[0].get('href'), 'http://docs.rack.com/servers/api/ext/cs.pdf') - self.assertEqual(link_nodes[1].get('type'), + self.assertEqual(link_nodes[1].get('type'), 'application/vnd.sun.wadl+xml') self.assertEqual(link_nodes[1].get('rel'), 'describedby') - self.assertEqual(link_nodes[1].get('href'), + self.assertEqual(link_nodes[1].get('href'), 'http://docs.rack.com/servers/api/ext/cs.wadl') -- cgit From faf71d498e9e98e60e65be94c7e306fc7b4e4f98 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Fri, 22 Jul 2011 16:54:25 -0400 Subject: updating images metadata resource --- nova/tests/api/openstack/test_image_metadata.py | 184 ++++++++++++++++++------ 1 file changed, 143 insertions(+), 41 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_image_metadata.py b/nova/tests/api/openstack/test_image_metadata.py index d9fb61e2a..31ca18497 100644 --- a/nova/tests/api/openstack/test_image_metadata.py +++ b/nova/tests/api/openstack/test_image_metadata.py @@ -103,8 +103,7 @@ class ImageMetaDataTest(test.TestCase): super(ImageMetaDataTest, self).tearDown() def test_index(self): - req = webob.Request.blank('/v1.1/images/1/meta') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata') res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) @@ -114,8 +113,7 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual(value, res_dict['metadata'][key]) def test_show(self): - req = webob.Request.blank('/v1.1/images/1/meta/key1') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/key1') res = req.get_response(fakes.wsgi_app()) res_dict = json.loads(res.body) self.assertEqual(200, res.status_int) @@ -124,42 +122,66 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual('value1', res_dict['meta']['key1']) def test_show_not_found(self): - req = webob.Request.blank('/v1.1/images/1/meta/key9') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/key9') res = req.get_response(fakes.wsgi_app()) self.assertEqual(404, res.status_int) def test_create(self): - req = webob.Request.blank('/v1.1/images/2/meta') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/2/metadata') req.method = 'POST' req.body = '{"metadata": {"key9": "value9"}}' req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) - res_dict = json.loads(res.body) + + self.assertEqual(200, res.status_int) + actual_output = json.loads(res.body) + + expected_output = { + 'metadata': { + 'key1': 'value1', + 'key2': 'value2', + 'key9': 'value9', + }, + } + + self.assertEqual(expected_output, actual_output) + + def test_update_all(self): + req = webob.Request.blank('/v1.1/images/2/metadata') + req.method = 'PUT' + req.body = '{"metadata": {"key9": "value9"}}' + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(200, res.status_int) - self.assertEqual('value9', res_dict['metadata']['key9']) - # other items should not be modified - self.assertEqual('value1', res_dict['metadata']['key1']) - self.assertEqual('value2', res_dict['metadata']['key2']) - self.assertEqual(1, len(res_dict)) + actual_output = json.loads(res.body) + + expected_output = { + 'metadata': { + 'key9': 'value9', + }, + } + + self.assertEqual(expected_output, actual_output) def test_update_item(self): - req = webob.Request.blank('/v1.1/images/1/meta/key1') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/key1') req.method = 'PUT' req.body = '{"meta": {"key1": "zz"}}' req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) + self.assertEqual(200, res.status_int) - res_dict = json.loads(res.body) - self.assertTrue('meta' in res_dict) - self.assertEqual(len(res_dict['meta']), 1) - self.assertEqual('zz', res_dict['meta']['key1']) + actual_output = json.loads(res.body) + expected_output = { + 'meta': { + 'key1': 'zz', + }, + } + self.assertEqual(actual_output, expected_output) def test_update_item_bad_body(self): - req = webob.Request.blank('/v1.1/images/1/meta/key1') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/key1') req.method = 'PUT' req.body = '{"key1": "zz"}' req.headers["content-type"] = "application/json" @@ -167,8 +189,7 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual(400, res.status_int) def test_update_item_too_many_keys(self): - req = webob.Request.blank('/v1.1/images/1/meta/key1') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/key1') req.method = 'PUT' req.body = '{"meta": {"key1": "value1", "key2": "value2"}}' req.headers["content-type"] = "application/json" @@ -176,24 +197,38 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual(400, res.status_int) def test_update_item_body_uri_mismatch(self): - req = webob.Request.blank('/v1.1/images/1/meta/bad') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/1/metadata/bad') req.method = 'PUT' req.body = '{"meta": {"key1": "value1"}}' req.headers["content-type"] = "application/json" res = req.get_response(fakes.wsgi_app()) self.assertEqual(400, res.status_int) + def test_update_item_xml(self): + req = webob.Request.blank('/v1.1/images/1/metadata/key1') + req.method = 'PUT' + req.body = 'five' + req.headers["content-type"] = "application/xml" + res = req.get_response(fakes.wsgi_app()) + + self.assertEqual(200, res.status_int) + actual_output = json.loads(res.body) + expected_output = { + 'meta': { + 'key1': 'five', + }, + } + self.assertEqual(actual_output, expected_output) + def test_delete(self): - req = webob.Request.blank('/v1.1/images/2/meta/key1') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/2/metadata/key1') req.method = 'DELETE' res = req.get_response(fakes.wsgi_app()) - self.assertEqual(200, res.status_int) + self.assertEqual(204, res.status_int) + self.assertEqual('', res.body) def test_delete_not_found(self): - req = webob.Request.blank('/v1.1/images/2/meta/blah') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/2/metadata/blah') req.method = 'DELETE' res = req.get_response(fakes.wsgi_app()) self.assertEqual(404, res.status_int) @@ -203,8 +238,7 @@ class ImageMetaDataTest(test.TestCase): for num in range(FLAGS.quota_metadata_items + 1): data['metadata']['key%i' % num] = "blah" json_string = str(data).replace("\'", "\"") - req = webob.Request.blank('/v1.1/images/2/meta') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/2/metadata') req.method = 'POST' req.body = json_string req.headers["content-type"] = "application/json" @@ -212,8 +246,7 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual(400, res.status_int) def test_too_many_metadata_items_on_put(self): - req = webob.Request.blank('/v1.1/images/3/meta/blah') - req.environ['api.version'] = '1.1' + req = webob.Request.blank('/v1.1/images/3/metadata/blah') req.method = 'PUT' req.body = '{"meta": {"blah": "blah"}}' req.headers["content-type"] = "application/json" @@ -221,9 +254,49 @@ class ImageMetaDataTest(test.TestCase): self.assertEqual(400, res.status_int) +class ImageMetadataXMLDeserializationTest(test.TestCase): + + deserializer = openstack.image_metadata.ImageMetadataXMLDeserializer() + + def test_create(self): + request_body = """ + + asdf + jkl; + """ + output = self.deserializer.deserialize(request_body, 'create') + expected = {"body": {"metadata": {"123": "asdf", "567": "jkl;"}}} + self.assertEquals(output, expected) + + def test_create_empty(self): + request_body = """ + """ + output = self.deserializer.deserialize(request_body, 'create') + expected = {"body": {"metadata": {}}} + self.assertEquals(output, expected) + + def test_update_all(self): + request_body = """ + + asdf + jkl; + """ + output = self.deserializer.deserialize(request_body, 'update_all') + expected = {"body": {"metadata": {"123": "asdf", "567": "jkl;"}}} + self.assertEquals(output, expected) + + def test_update(self): + request_body = """ + asdf""" + output = self.deserializer.deserialize(request_body, 'update') + expected = {"body": {"meta": {"123": "asdf"}}} + self.assertEquals(output, expected) + + class ImageMetadataXMLSerializationTest(test.TestCase): - def test_index_xml(self): + def test_index(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'metadata': { @@ -247,7 +320,7 @@ class ImageMetadataXMLSerializationTest(test.TestCase): self.assertEqual(expected.toxml(), actual.toxml()) - def test_index_xml_null(self): + def test_index_null(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'metadata': { @@ -267,7 +340,7 @@ class ImageMetadataXMLSerializationTest(test.TestCase): self.assertEqual(expected.toxml(), actual.toxml()) - def test_index_xml_unicode(self): + def test_index_unicode(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'metadata': { @@ -287,7 +360,7 @@ class ImageMetadataXMLSerializationTest(test.TestCase): self.assertEqual(expected.toxml(), actual.toxml()) - def test_show_xml(self): + def test_show(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'meta': { @@ -305,7 +378,31 @@ class ImageMetadataXMLSerializationTest(test.TestCase): self.assertEqual(expected.toxml(), actual.toxml()) - def test_update_item_xml(self): + def test_update_all(self): + serializer = openstack.image_metadata.ImageMetadataXMLSerializer() + fixture = { + 'metadata': { + 'key6': 'value6', + 'key4': 'value4', + }, + } + output = serializer.serialize(fixture, 'update_all') + actual = minidom.parseString(output.replace(" ", "")) + + expected = minidom.parseString(""" + + + value6 + + + value4 + + + """.replace(" ", "")) + + self.assertEqual(expected.toxml(), actual.toxml()) + + def test_update_item(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'meta': { @@ -323,7 +420,7 @@ class ImageMetadataXMLSerializationTest(test.TestCase): self.assertEqual(expected.toxml(), actual.toxml()) - def test_create_xml(self): + def test_create(self): serializer = openstack.image_metadata.ImageMetadataXMLSerializer() fixture = { 'metadata': { @@ -350,3 +447,8 @@ class ImageMetadataXMLSerializationTest(test.TestCase): """.replace(" ", "")) self.assertEqual(expected.toxml(), actual.toxml()) + + def test_delete(self): + serializer = openstack.image_metadata.ImageMetadataXMLSerializer() + output = serializer.serialize(None, 'delete') + self.assertEqual(output, '') -- cgit From e54f0cb05a3e10ad4234c672e2096da2a3eaa2da Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Fri, 22 Jul 2011 16:47:37 -0500 Subject: default to None in the method signature --- nova/tests/test_network.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py index c37e30c05..fbe7d769e 100644 --- a/nova/tests/test_network.py +++ b/nova/tests/test_network.py @@ -55,7 +55,7 @@ networks = [{'id': 0, 'bridge_interface': 'fake_fa0', 'gateway': '192.168.0.1', 'broadcast': '192.168.0.255', - 'dns': '192.168.0.1', + 'dns1': '192.168.0.1', 'dns2': '192.168.0.2', 'vlan': None, 'host': None, @@ -74,7 +74,7 @@ networks = [{'id': 0, 'bridge_interface': 'fake_fa1', 'gateway': '192.168.1.1', 'broadcast': '192.168.1.255', - 'dns': '192.168.0.1', + 'dns1': '192.168.0.1', 'dns2': '192.168.0.2', 'vlan': None, 'host': None, -- cgit From e92595896531d56ce38169468a740b98624cb714 Mon Sep 17 00:00:00 2001 From: Jason Koelker Date: Fri, 22 Jul 2011 17:01:35 -0500 Subject: pass in the right argument --- nova/tests/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/__init__.py b/nova/tests/__init__.py index 49c1ccc56..720d5b0e6 100644 --- a/nova/tests/__init__.py +++ b/nova/tests/__init__.py @@ -68,7 +68,7 @@ def setup(): bridge_interface=bridge_interface, vpn_start=FLAGS.vpn_start, vlan_start=FLAGS.vlan_start, - dns=FLAGS.flat_network_dns) + dns1=FLAGS.flat_network_dns) for net in db.network_get_all(ctxt): network.set_network_host(ctxt, net) -- cgit From a7fdcb0f7dacfe41b5c85faee38c027b31ddaf81 Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Sat, 23 Jul 2011 16:13:48 -0400 Subject: Added test_serialize_extenstions to test ExtensionsXMLSerializer.index(). --- nova/tests/api/openstack/test_extensions.py | 115 ++++++++++++++++++++-------- 1 file changed, 83 insertions(+), 32 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index f3c9d9423..47ec5ec89 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -31,7 +31,8 @@ from nova.api.openstack import wsgi from nova.tests.api.openstack import fakes FLAGS = flags.FLAGS - +NS = "{http://docs.openstack.org/compute/api/v1.1}" +ATOMNS = "{http://www.w3.org/2005/Atom}" response_body = "Try to say this Mr. Knox, sir..." @@ -139,12 +140,11 @@ class ExtensionControllerTest(unittest.TestCase): self.assertEqual(200, response.status_int) print response.body - ns = "{http://docs.openstack.org/compute/api/v1.1}" root = ElementTree.XML(response.body) - self.assertEqual(root.tag.split('extensions')[0], ns) + self.assertEqual(root.tag.split('extensions')[0], NS) # Make sure we have all the extensions. - exts = root.findall('{0}extension'.format(ns)) + exts = root.findall('{0}extension'.format(NS)) self.assertEqual(len(exts), 6) # Make sure that at least Fox in Sox is correct. @@ -153,7 +153,7 @@ class ExtensionControllerTest(unittest.TestCase): self.assertEqual(fox_ext.get('namespace'), 'http://www.fox.in.socks/api/ext/pie/v1.0') self.assertEqual(fox_ext.get('updated'), '2011-01-22T13:25:27-06:00') - self.assertEqual(fox_ext.findtext('{0}description'.format(ns)), + self.assertEqual(fox_ext.findtext('{0}description'.format(NS)), 'The Fox In Socks Extension') def test_get_extension_xml(self): @@ -166,14 +166,13 @@ class ExtensionControllerTest(unittest.TestCase): print response.body root = ElementTree.XML(response.body) - ns = "{http://docs.openstack.org/compute/api/v1.1}" - self.assertEqual(root.tag.split('extension')[0], ns) + self.assertEqual(root.tag.split('extension')[0], NS) self.assertEqual(root.get('alias'), 'FOXNSOX') self.assertEqual(root.get('name'), 'Fox In Socks') self.assertEqual(root.get('namespace'), 'http://www.fox.in.socks/api/ext/pie/v1.0') self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00') - self.assertEqual(root.findtext('{0}description'.format(ns)), + self.assertEqual(root.findtext('{0}description'.format(NS)), 'The Fox In Socks Extension') @@ -329,7 +328,8 @@ class RequestExtensionTest(unittest.TestCase): class ExtensionsXMLSerializerTest(unittest.TestCase): - def test_serialize(self): + + def test_serialize_extenstion(self): serializer = extensions.ExtensionsXMLSerializer() data = { 'extension': { @@ -353,30 +353,81 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): } } - ns = "{http://docs.openstack.org/compute/api/v1.1}" - atomns = "{http://www.w3.org/2005/Atom}" xml = serializer.serialize(data, 'show') root = ElementTree.XML(xml) - self.assertEqual(root.tag.split('extension')[0], ns) - self.assertEqual(root.get('alias'), 'RS-PIE') - self.assertEqual(root.get('name'), 'ext1') - self.assertEqual(root.get('namespace'), - 'http://docs.rack.com/servers/api/ext/pie/v1.0') - self.assertEqual(root.get('updated'), '2011-01-22T13:25:27-06:00') - self.assertEqual(root.findtext('{0}description'.format(ns)), - 'Adds the capability to share an image.') + ext_dict = data['extension'] + self.assertEqual(root.findtext('{0}description'.format(NS)), + ext_dict['description']) + + for key in ['name', 'namespace', 'alias', 'updated']: + self.assertEqual(root.get(key), ext_dict[key]) - link_nodes = root.findall('{0}link'.format(atomns)) + link_nodes = root.findall('{0}link'.format(ATOMNS)) self.assertEqual(len(link_nodes), 2) - link_nodes.sort(key=lambda x: x.get('type')) - - self.assertEqual(link_nodes[0].get('type'), 'application/pdf') - self.assertEqual(link_nodes[0].get('rel'), 'describedby') - self.assertEqual(link_nodes[0].get('href'), - 'http://docs.rack.com/servers/api/ext/cs.pdf') - - self.assertEqual(link_nodes[1].get('type'), - 'application/vnd.sun.wadl+xml') - self.assertEqual(link_nodes[1].get('rel'), 'describedby') - self.assertEqual(link_nodes[1].get('href'), - 'http://docs.rack.com/servers/api/ext/cs.wadl') + for i, link in enumerate(ext_dict['links']): + for key, value in link.items(): + self.assertEqual(link_nodes[i].get(key), value) + + def test_serialize_extenstions(self): + serializer = extensions.ExtensionsXMLSerializer() + data = { + "extensions": [ + { + "name": "Public Image Extension", + "namespace": "http://foo.com/servers/api/ext/pie/v1.0", + "alias": "RS-PIE", + "updated": "2011-01-22T13:25:27-06:00", + "description": "Adds the capability to share an image.", + "links": [ + { + "rel": "describedby", + "type": "application/pdf", + "href": "http://foo.com/servers/api/ext/cs-pie.pdf" + }, + { + "rel": "describedby", + "type": "application/vnd.sun.wadl+xml", + "href": "http://foo.com/servers/api/ext/cs-pie.wadl" + } + ] + }, + { + "name": "Cloud Block Storage", + "namespace": "http://foo.com/servers/api/ext/cbs/v1.0", + "alias": "RS-CBS", + "updated": "2011-01-12T11:22:33-06:00", + "description": "Allows mounting cloud block storage.", + "links": [ + { + "rel": "describedby", + "type": "application/pdf", + "href": "http://foo.com/servers/api/ext/cs-cbs.pdf" + }, + { + "rel": "describedby", + "type": "application/vnd.sun.wadl+xml", + "href": "http://foo.com/servers/api/ext/cs-cbs.wadl" + } + ] + } + ] + } + + xml = serializer.serialize(data, 'index') + print xml + root = ElementTree.XML(xml) + ext_elems = root.findall('{0}extension'.format(NS)) + self.assertEqual(len(ext_elems), 2) + for i, ext_elem in enumerate(ext_elems): + ext_dict = data['extensions'][i] + self.assertEqual(ext_elem.findtext('{0}description'.format(NS)), + ext_dict['description']) + + for key in ['name', 'namespace', 'alias', 'updated']: + self.assertEqual(ext_elem.get(key), ext_dict[key]) + + link_nodes = ext_elem.findall('{0}link'.format(ATOMNS)) + self.assertEqual(len(link_nodes), 2) + for i, link in enumerate(ext_dict['links']): + for key, value in link.items(): + self.assertEqual(link_nodes[i].get(key), value) -- cgit From a158166a1148a1ea35a04fb25b10361d86f36138 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 25 Jul 2011 12:08:49 -0400 Subject: Updated Faults controller to choose an xml serializer based on api version found in the request url --- nova/tests/api/openstack/test_common.py | 18 ++++++ nova/tests/api/openstack/test_faults.py | 107 ++++++++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_common.py b/nova/tests/api/openstack/test_common.py index 4c4d03995..f09270b34 100644 --- a/nova/tests/api/openstack/test_common.py +++ b/nova/tests/api/openstack/test_common.py @@ -247,3 +247,21 @@ class MiscFunctionsTest(test.TestCase): self.assertRaises(ValueError, common.get_id_from_href, fixture) + + def test_get_version_from_href(self): + fixture = 'http://www.testsite.com/v1.1/images' + expected = '1.1' + actual = common.get_version_from_href(fixture) + self.assertEqual(actual, expected) + + def test_get_version_from_href_2(self): + fixture = 'http://www.testsite.com/v1.1' + expected = '1.1' + actual = common.get_version_from_href(fixture) + self.assertEqual(actual, expected) + + def test_get_version_from_href_default(self): + fixture = 'http://www.testsite.com/images' + expected = '1.0' + actual = common.get_version_from_href(fixture) + self.assertEqual(actual, expected) diff --git a/nova/tests/api/openstack/test_faults.py b/nova/tests/api/openstack/test_faults.py index 927009e77..6da27540a 100644 --- a/nova/tests/api/openstack/test_faults.py +++ b/nova/tests/api/openstack/test_faults.py @@ -16,6 +16,7 @@ # under the License. import json +from xml.dom import minidom import webob import webob.dec @@ -24,6 +25,7 @@ import webob.exc from nova import test from nova.api.openstack import common from nova.api.openstack import faults +from nova.api.openstack import wsgi class TestFaults(test.TestCase): @@ -144,3 +146,108 @@ class TestFaults(test.TestCase): """Ensure the status_int is set correctly on faults""" fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='what?')) self.assertEqual(fault.status_int, 400) + + def test_v10_xml_serializer(self): + """Ensure that a v1.0 request responds with a v1.0 xmlns""" + request = webob.Request.blank('/', + headers={"Accept": "application/xml"}) + + fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + response = request.get_response(fault) + + self.assertTrue(common.XML_NS_V10 in response.body) + self.assertEqual(response.content_type, "application/xml") + self.assertEqual(response.status_int, 400) + + def test_v11_xml_serializer(self): + """Ensure that a v1.1 request responds with a v1.1 xmlns""" + request = webob.Request.blank('/v1.1', + headers={"Accept": "application/xml"}) + + fault = faults.Fault(webob.exc.HTTPBadRequest(explanation='scram')) + response = request.get_response(fault) + + self.assertTrue(common.XML_NS_V11 in response.body) + self.assertEqual(response.content_type, "application/xml") + self.assertEqual(response.status_int, 400) + + +class FaultsXMLSerializationTestV11(test.TestCase): + """Tests covering `nova.api.openstack.faults:Fault` class.""" + + def _prepare_xml(self, xml_string): + xml_string = xml_string.replace(" ", "") + xml_string = xml_string.replace("\n", "") + xml_string = xml_string.replace("\t", "") + return xml_string + + def test_400_fault(self): + metadata = {'attributes': {"badRequest": 'code'}} + serializer = wsgi.XMLDictSerializer(metadata=metadata, + xmlns=common.XML_NS_V11) + + fixture = { + "badRequest": { + "message": "scram", + "code": 400, + }, + } + + output = serializer.serialize(fixture) + actual = minidom.parseString(self._prepare_xml(output)) + + expected = minidom.parseString(self._prepare_xml(""" + + scram + + """) % common.XML_NS_V11) + + self.assertEqual(expected.toxml(), actual.toxml()) + + def test_413_fault(self): + metadata = {'attributes': {"overLimit": 'code'}} + serializer = wsgi.XMLDictSerializer(metadata=metadata, + xmlns=common.XML_NS_V11) + + fixture = { + "overLimit": { + "message": "sorry", + "code": 413, + "retryAfter": 4, + }, + } + + output = serializer.serialize(fixture) + actual = minidom.parseString(self._prepare_xml(output)) + + expected = minidom.parseString(self._prepare_xml(""" + + sorry + 4 + + """) % common.XML_NS_V11) + + self.assertEqual(expected.toxml(), actual.toxml()) + + def test_404_fault(self): + metadata = {'attributes': {"itemNotFound": 'code'}} + serializer = wsgi.XMLDictSerializer(metadata=metadata, + xmlns=common.XML_NS_V11) + + fixture = { + "itemNotFound": { + "message": "sorry", + "code": 404, + }, + } + + output = serializer.serialize(fixture) + actual = minidom.parseString(self._prepare_xml(output)) + + expected = minidom.parseString(self._prepare_xml(""" + + sorry + + """) % common.XML_NS_V11) + + self.assertEqual(expected.toxml(), actual.toxml()) -- cgit From 2df7470b89289c1a2cae4db8c21b5588622baf3c Mon Sep 17 00:00:00 2001 From: Naveed Massjouni Date: Mon, 25 Jul 2011 12:43:10 -0400 Subject: pep8 + spelling fixes --- nova/tests/api/openstack/test_extensions.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_extensions.py b/nova/tests/api/openstack/test_extensions.py index 47ec5ec89..d459c694f 100644 --- a/nova/tests/api/openstack/test_extensions.py +++ b/nova/tests/api/openstack/test_extensions.py @@ -368,13 +368,13 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): for key, value in link.items(): self.assertEqual(link_nodes[i].get(key), value) - def test_serialize_extenstions(self): + def test_serialize_extensions(self): serializer = extensions.ExtensionsXMLSerializer() data = { "extensions": [ { "name": "Public Image Extension", - "namespace": "http://foo.com/servers/api/ext/pie/v1.0", + "namespace": "http://foo.com/api/ext/pie/v1.0", "alias": "RS-PIE", "updated": "2011-01-22T13:25:27-06:00", "description": "Adds the capability to share an image.", @@ -382,18 +382,18 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): { "rel": "describedby", "type": "application/pdf", - "href": "http://foo.com/servers/api/ext/cs-pie.pdf" + "href": "http://foo.com/api/ext/cs-pie.pdf" }, { "rel": "describedby", "type": "application/vnd.sun.wadl+xml", - "href": "http://foo.com/servers/api/ext/cs-pie.wadl" + "href": "http://foo.com/api/ext/cs-pie.wadl" } ] }, { "name": "Cloud Block Storage", - "namespace": "http://foo.com/servers/api/ext/cbs/v1.0", + "namespace": "http://foo.com/api/ext/cbs/v1.0", "alias": "RS-CBS", "updated": "2011-01-12T11:22:33-06:00", "description": "Allows mounting cloud block storage.", @@ -401,12 +401,12 @@ class ExtensionsXMLSerializerTest(unittest.TestCase): { "rel": "describedby", "type": "application/pdf", - "href": "http://foo.com/servers/api/ext/cs-cbs.pdf" + "href": "http://foo.com/api/ext/cs-cbs.pdf" }, { "rel": "describedby", "type": "application/vnd.sun.wadl+xml", - "href": "http://foo.com/servers/api/ext/cs-cbs.wadl" + "href": "http://foo.com/api/ext/cs-cbs.wadl" } ] } -- cgit From e24988c3b154d188ac69030d0b1d2811fb91d2e7 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 25 Jul 2011 13:28:22 -0400 Subject: Fixed bad test Fixed using wrong variable --- nova/tests/api/openstack/test_images.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_images.py b/nova/tests/api/openstack/test_images.py index 17f2fb755..87a695dde 100644 --- a/nova/tests/api/openstack/test_images.py +++ b/nova/tests/api/openstack/test_images.py @@ -538,7 +538,7 @@ class ImageControllerWithGlanceServiceTest(test.TestCase): # because the element hasn't changed definition expected = minidom.parseString(""" + xmlns="http://docs.openstack.org/compute/api/v1.1"> Image not found. -- cgit From 2e142a02014940ebb1e775c26b60c576ad1e2bb3 Mon Sep 17 00:00:00 2001 From: Alex Meade Date: Mon, 25 Jul 2011 15:36:28 -0400 Subject: Added check to make sure there is a server entity in the create server request --- nova/tests/api/openstack/test_servers.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 1c66c1aa6..fd2452dab 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -941,6 +941,18 @@ class ServersTest(test.TestCase): res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) + def test_create_instance_no_server_entity(self): + self._setup_for_create_instance() + + body = {} + + req = webob.Request.blank('/v1.0/servers') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 422) + def test_create_instance_whitespace_name(self): self._setup_for_create_instance() -- cgit From 175e42fe2310a3aff69527d5623d92f3d0b19258 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 25 Jul 2011 15:56:23 -0400 Subject: adding testing to solidify handling of None in wsgi serialization --- nova/tests/api/openstack/test_wsgi.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py index 5bdda7c7e..6dea78d17 100644 --- a/nova/tests/api/openstack/test_wsgi.py +++ b/nova/tests/api/openstack/test_wsgi.py @@ -256,6 +256,13 @@ class ResponseSerializerTest(test.TestCase): self.assertEqual(response.body, 'pew_json') self.assertEqual(response.status_int, 404) + def test_serialize_response_None(self): + response = self.serializer.serialize(None, 'application/json') + print response + self.assertEqual(response.headers['Content-Type'], 'application/json') + self.assertEqual(response.body, '') + self.assertEqual(response.status_int, 404) + def test_serialize_response_dict_to_unknown_content_type(self): self.assertRaises(exception.InvalidContentType, self.serializer.serialize, -- cgit From 67ccc98d6a0d9e8618889fd9fa398a39735d044a Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Mon, 25 Jul 2011 20:33:20 +0000 Subject: add a simple broken test to verify the bug --- nova/tests/test_cloud.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_cloud.py b/nova/tests/test_cloud.py index d71a03aff..87edaac36 100644 --- a/nova/tests/test_cloud.py +++ b/nova/tests/test_cloud.py @@ -518,6 +518,21 @@ class CloudTestCase(test.TestCase): self._wait_for_running(ec2_instance_id) return ec2_instance_id + def test_rescue_unrescue_instance(self): + instance_id = self._run_instance( + image_id='ami-1', + instance_type=FLAGS.default_instance_type, + max_count=1) + self.cloud.rescue_instance(context=self.context, + instance_id=instance_id) + # NOTE(vish): This currently does no validation, it simply makes sure + # that the code path doesn't throw an exception. + self.cloud.unrescue_instance(context=self.context, + instance_id=instance_id) + # TODO(soren): We need this until we can stop polling in the rpc code + # for unit tests. + self.cloud.terminate_instances(self.context, [instance_id]) + def test_console_output(self): instance_id = self._run_instance( image_id='ami-1', -- cgit From b32b5571807c36f30d5541d0e284fd0e66023626 Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Mon, 25 Jul 2011 17:00:19 -0400 Subject: adding xml serialization for /servers//ips and /servers//ips/ --- nova/tests/api/openstack/test_servers.py | 59 +++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) (limited to 'nova/tests') diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 1c66c1aa6..09118cde7 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -30,8 +30,9 @@ from nova import flags from nova import test from nova import utils import nova.api.openstack -from nova.api.openstack import servers from nova.api.openstack import create_instance_helper +from nova.api.openstack import servers +from nova.api.openstack import wsgi import nova.compute.api from nova.compute import instance_types from nova.compute import power_state @@ -2188,6 +2189,62 @@ b25zLiINCg0KLVJpY2hhcmQgQmFjaA==""", "http://localhost:8774/v1.1/images/1") +class TextAddressesXMLSerialization(test.TestCase): + + serializer = nova.api.openstack.ips.IPXMLSerializer() + + def test_show(self): + fixture = { + 'network_2': [ + {'addr': '192.168.0.1', 'version': 4}, + {'addr': 'fe80::beef', 'version': 6}, + ], + } + output = self.serializer.serialize(fixture, 'show') + actual = minidom.parseString(output.replace(" ", "")) + + expected = minidom.parseString(""" + + + + + """.replace(" ", "")) + + self.assertEqual(expected.toxml(), actual.toxml()) + + def test_index(self): + fixture = { + 'addresses': { + 'network_1': [ + {'addr': '192.168.0.3', 'version': 4}, + {'addr': '192.168.0.5', 'version': 4}, + ], + 'network_2': [ + {'addr': '192.168.0.1', 'version': 4}, + {'addr': 'fe80::beef', 'version': 6}, + ], + }, + } + output = self.serializer.serialize(fixture, 'index') + actual = minidom.parseString(output.replace(" ", "")) + + expected = minidom.parseString(""" + + + + + + + + + + + """.replace(" ", "")) + + self.assertEqual(expected.toxml(), actual.toxml()) + + class TestServerInstanceCreation(test.TestCase): def setUp(self): -- cgit