Browse Source

Remove XML support

XML support in Neutron has always been a second class feature to the
JSON API and broken for many extensions and outputs. The XML API been marked as
deprecated for the Icehouse and Juno release and is ready for removal in
Kilo.

Change-Id: I611aa9382ba3bfb08b2970c63e83b0fdd3d2e8a4
Closes-Bug: #1380787
changes/95/128095/2
Mark McClain 8 years ago
parent
commit
1b4ad95758
  1. 11
      neutron/api/extensions.py
  2. 13
      neutron/api/v2/attributes.py
  3. 12
      neutron/api/v2/resource.py
  4. 6
      neutron/api/v2/router.py
  5. 9
      neutron/api/versions.py
  6. 13
      neutron/common/constants.py
  7. 4
      neutron/tests/unit/cisco/l3/test_l3_router_appliance_plugin.py
  8. 4
      neutron/tests/unit/db/firewall/test_db_firewall.py
  9. 4
      neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py
  10. 4
      neutron/tests/unit/db/metering/test_db_metering.py
  11. 4
      neutron/tests/unit/db/vpn/test_db_vpnaas.py
  12. 12
      neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py
  13. 10
      neutron/tests/unit/ml2/test_security_group.py
  14. 8
      neutron/tests/unit/mlnx/test_mlnx_security_group.py
  15. 10
      neutron/tests/unit/nec/test_security_group.py
  16. 10
      neutron/tests/unit/oneconvergence/test_security_group.py
  17. 4
      neutron/tests/unit/openvswitch/test_agent_scheduler.py
  18. 5
      neutron/tests/unit/plumgrid/extensions/test_securitygroups.py
  19. 4
      neutron/tests/unit/ryu/test_ryu_security_group.py
  20. 4
      neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py
  21. 4
      neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py
  22. 8
      neutron/tests/unit/services/loadbalancer/test_loadbalancer_quota_ext.py
  23. 4
      neutron/tests/unit/services/vpn/test_vpnaas_extension.py
  24. 4
      neutron/tests/unit/test_agent_ext_plugin.py
  25. 4
      neutron/tests/unit/test_api_v2.py
  26. 82
      neutron/tests/unit/test_api_v2_resource.py
  27. 20
      neutron/tests/unit/test_db_plugin.py
  28. 4
      neutron/tests/unit/test_extension_allowedaddresspairs.py
  29. 4
      neutron/tests/unit/test_extension_ext_net.py
  30. 8
      neutron/tests/unit/test_extension_extraroute.py
  31. 4
      neutron/tests/unit/test_extension_firewall.py
  32. 8
      neutron/tests/unit/test_extension_security_group.py
  33. 4
      neutron/tests/unit/test_extensions.py
  34. 12
      neutron/tests/unit/test_l3_plugin.py
  35. 8
      neutron/tests/unit/test_quota_ext.py
  36. 4
      neutron/tests/unit/test_security_groups_rpc.py
  37. 8
      neutron/tests/unit/test_servicetype.py
  38. 413
      neutron/tests/unit/test_wsgi.py
  39. 7
      neutron/tests/unit/testlib_api.py
  40. 350
      neutron/wsgi.py

11
neutron/api/extensions.py

@ -25,7 +25,6 @@ import six
import webob.dec
import webob.exc
from neutron.api.v2 import attributes
from neutron.common import exceptions
import neutron.extensions
from neutron import manager
@ -479,19 +478,9 @@ class ExtensionManager(object):
attr_map[resource].update(resource_attrs)
else:
attr_map[resource] = resource_attrs
if extended_attrs:
attributes.EXT_NSES[ext.get_alias()] = (
ext.get_namespace())
except AttributeError:
LOG.exception(_("Error fetching extended attributes for "
"extension '%s'"), ext.get_name())
try:
comp_map = ext.get_alias_namespace_compatibility_map()
attributes.EXT_NSES_BC.update(comp_map)
except AttributeError:
LOG.info(_("Extension '%s' provides no backward "
"compatibility map for extended attributes"),
ext.get_name())
processed_exts.add(ext_name)
del exts_to_process[ext_name]
if len(processed_exts) == processed_ext_count:

13
neutron/api/v2/attributes.py

@ -762,16 +762,3 @@ PLURALS = {NETWORKS: NETWORK,
'allocation_pools': 'allocation_pool',
'fixed_ips': 'fixed_ip',
'extensions': 'extension'}
EXT_NSES = {}
# Namespaces to be added for backward compatibility
# when existing extended resource attributes are
# provided by other extension than original one.
EXT_NSES_BC = {}
def get_attr_metadata():
return {'plurals': PLURALS,
'xmlns': constants.XML_NS_V20,
constants.EXT_NS: EXT_NSES,
constants.EXT_NS_COMP: EXT_NSES_BC}

12
neutron/api/v2/resource.py

@ -24,7 +24,6 @@ import six
import webob.dec
import webob.exc
from neutron.api.v2 import attributes
from neutron.common import exceptions
from neutron.openstack.common import gettextutils
from neutron.openstack.common import log as logging
@ -42,14 +41,9 @@ def Resource(controller, faults=None, deserializers=None, serializers=None):
"""Represents an API entity resource and the associated serialization and
deserialization logic
"""
xml_deserializer = wsgi.XMLDeserializer(attributes.get_attr_metadata())
default_deserializers = {'application/xml': xml_deserializer,
'application/json': wsgi.JSONDeserializer()}
xml_serializer = wsgi.XMLDictSerializer(attributes.get_attr_metadata())
default_serializers = {'application/xml': xml_serializer,
'application/json': wsgi.JSONDictSerializer()}
format_types = {'xml': 'application/xml',
'json': 'application/json'}
default_deserializers = {'application/json': wsgi.JSONDeserializer()}
default_serializers = {'application/json': wsgi.JSONDictSerializer()}
format_types = {'json': 'application/json'}
action_status = dict(create=201, delete=204)
default_deserializers.update(deserializers or {})

6
neutron/api/v2/router.py

@ -36,7 +36,7 @@ RESOURCES = {'network': 'networks',
SUB_RESOURCES = {}
COLLECTION_ACTIONS = ['index', 'create']
MEMBER_ACTIONS = ['show', 'update', 'delete']
REQUIREMENTS = {'id': attributes.UUID_PATTERN, 'format': 'xml|json'}
REQUIREMENTS = {'id': attributes.UUID_PATTERN, 'format': 'json'}
class Index(wsgi.Application):
@ -45,9 +45,7 @@ class Index(wsgi.Application):
@webob.dec.wsgify(RequestClass=wsgi.Request)
def __call__(self, req):
metadata = {'application/xml': {'attributes': {
'resource': ['name', 'collection'],
'link': ['href', 'rel']}}}
metadata = {}
layout = []
for name, collection in self.resources.iteritems():

9
neutron/api/versions.py

@ -49,14 +49,7 @@ class Versions(object):
builder = versions_view.get_view_builder(req)
versions = [builder.build(version) for version in version_objs]
response = dict(versions=versions)
metadata = {
"application/xml": {
"attributes": {
"version": ["status", "id"],
"link": ["rel", "href"],
}
}
}
metadata = {}
content_type = req.best_match_content_type()
body = (wsgi.Serializer(metadata=metadata).

13
neutron/common/constants.py

@ -72,19 +72,6 @@ MAX_VXLAN_VNI = 2 ** 24 - 1
FLOODING_ENTRY = ['00:00:00:00:00:00', '0.0.0.0']
EXT_NS_COMP = '_backward_comp_e_ns'
EXT_NS = '_extension_ns'
XML_NS_V20 = 'http://openstack.org/quantum/api/v2.0'
XSI_NAMESPACE = "http://www.w3.org/2001/XMLSchema-instance"
XSI_ATTR = "xsi:nil"
XSI_NIL_ATTR = "xmlns:xsi"
ATOM_NAMESPACE = "http://www.w3.org/2005/Atom"
ATOM_XMLNS = "xmlns:atom"
ATOM_LINK_NOTATION = "{%s}link" % ATOM_NAMESPACE
TYPE_XMLNS = "xmlns:quantum"
TYPE_ATTR = "quantum:type"
VIRTUAL_ROOT_KEY = "_v_root"
TYPE_BOOL = "bool"
TYPE_INT = "int"
TYPE_LONG = "long"

4
neutron/tests/unit/cisco/l3/test_l3_router_appliance_plugin.py

@ -203,10 +203,6 @@ class L3RouterApplianceVMTestCase(
'neutron.db.l3_db.L3_NAT_dbonly_mixin._check_and_get_fip_assoc')
class L3RouterApplianceVMTestCaseXML(L3RouterApplianceVMTestCase):
fmt = 'xml'
class CfgAgentRouterApplianceVMTestCase(L3RouterApplianceTestCaseBase,
test_l3_plugin.L3AgentDbTestCaseBase):

4
neutron/tests/unit/db/firewall/test_db_firewall.py

@ -1237,7 +1237,3 @@ class TestFirewallDBPlugin(FirewallPluginDbTestCase):
expected_code=webob.exc.HTTPNotFound.code,
expected_body=None,
body_data={'firewall_rule_id': None})
class TestFirewallDBPluginXML(TestFirewallDBPlugin):
fmt = 'xml'

4
neutron/tests/unit/db/loadbalancer/test_db_loadbalancer.py

@ -1584,7 +1584,3 @@ class TestLoadBalancer(LoadBalancerPluginDbTestCase):
SystemExit,
loadbalancer_plugin.LoadBalancerPlugin
)
class TestLoadBalancerXML(TestLoadBalancer):
fmt = 'xml'

4
neutron/tests/unit/db/metering/test_db_metering.py

@ -294,7 +294,3 @@ class TestMetering(MeteringPluginDbTestCase):
self._test_list_resources('metering-label-rule',
metering_label_rule)
class TestMeteringDbXML(TestMetering):
fmt = 'xml'

4
neutron/tests/unit/db/vpn/test_db_vpnaas.py

@ -1596,7 +1596,3 @@ class TestVpnaas(VPNPluginDbTestCase):
)
delete_res = delete_req.get_response(self.ext_api)
self.assertEqual(409, delete_res.status_int)
class TestVpnaasXML(TestVpnaas):
fmt = 'xml'

12
neutron/tests/unit/ml2/drivers/cisco/nexus/test_cisco_mech.py

@ -752,15 +752,3 @@ class TestCiscoSubnetsV2(CiscoML2MechanismTestCase,
res,
'subnets',
wexc.HTTPInternalServerError.code)
class TestCiscoPortsV2XML(TestCiscoPortsV2):
fmt = 'xml'
class TestCiscoNetworksV2XML(TestCiscoNetworksV2):
fmt = 'xml'
class TestCiscoSubnetsV2XML(TestCiscoSubnetsV2):
fmt = 'xml'

10
neutron/tests/unit/ml2/test_security_group.py

@ -89,17 +89,7 @@ class TestMl2SecurityGroups(Ml2SecurityGroupsTestCase,
self.assertIsNone(port_dict)
class TestMl2SecurityGroupsXML(TestMl2SecurityGroups):
fmt = 'xml'
class TestMl2SGServerRpcCallBack(
Ml2SecurityGroupsTestCase,
test_sg_rpc.SGServerRpcCallBackTestCase):
pass
class TestMl2SGServerRpcCallBackXML(
Ml2SecurityGroupsTestCase,
test_sg_rpc.SGServerRpcCallBackTestCaseXML):
pass

8
neutron/tests/unit/mlnx/test_mlnx_security_group.py

@ -56,10 +56,6 @@ class TestMlnxSecurityGroups(MlnxSecurityGroupsTestCase,
pass
class TestMlnxSecurityGroupsXML(TestMlnxSecurityGroups):
fmt = 'xml'
class TestMlnxSecurityGroupsDB(MlnxSecurityGroupsTestCase):
def test_security_group_get_port_from_device(self):
with self.network() as n:
@ -94,7 +90,3 @@ class TestMlnxSecurityGroupsDB(MlnxSecurityGroupsTestCase):
def test_security_group_get_port_from_device_with_no_port(self):
port_dict = mlnx_db.get_port_from_device('bad_device_id')
self.assertIsNone(port_dict)
class TestMlnxSecurityGroupsDBXML(TestMlnxSecurityGroupsDB):
fmt = 'xml'

10
neutron/tests/unit/nec/test_security_group.py

@ -56,12 +56,6 @@ class TestNecSGServerRpcCallBack(
pass
class TestNecSGServerRpcCallBackXML(
test_sg_rpc.SGServerRpcCallBackTestCaseXML,
NecSecurityGroupsTestCase):
pass
class TestNecSecurityGroups(NecSecurityGroupsTestCase,
test_sg.TestSecurityGroups,
test_sg_rpc.SGNotificationTestMixin):
@ -92,7 +86,3 @@ class TestNecSecurityGroups(NecSecurityGroupsTestCase,
self.assertEqual([fixed_ips[0]['ip_address']],
port_dict['fixed_ips'])
self._delete('ports', port_id)
class TestNecSecurityGroupsXML(TestNecSecurityGroups):
fmt = 'xml'

10
neutron/tests/unit/oneconvergence/test_security_group.py

@ -70,12 +70,6 @@ class TestOneConvergenceSGServerRpcCallBack(
pass
class TestOneConvergenceSGServerRpcCallBackXML(
OneConvergenceSecurityGroupsTestCase,
test_sg_rpc.SGServerRpcCallBackTestCaseXML):
pass
class TestOneConvergenceSecurityGroups(OneConvergenceSecurityGroupsTestCase,
test_sg.TestSecurityGroups,
test_sg_rpc.SGNotificationTestMixin):
@ -113,7 +107,3 @@ class TestOneConvergenceSecurityGroups(OneConvergenceSecurityGroupsTestCase,
plugin = manager.NeutronManager.get_plugin()
port_dict = plugin.get_port_from_device('bad_device_id')
self.assertIsNone(port_dict)
class TestOneConvergenceSecurityGroupsXML(TestOneConvergenceSecurityGroups):
fmt = 'xml'

4
neutron/tests/unit/openvswitch/test_agent_scheduler.py

@ -1413,7 +1413,3 @@ class OvsL3AgentNotifierTestCase(test_l3_plugin.L3NatTestCaseMixin,
mock.ANY, l3_notifier.make_msg(
'agent_updated', payload={'admin_state_up': False}),
topic='l3_agent.hosta')
class OvsAgentSchedulerTestCaseXML(OvsAgentSchedulerTestCase):
fmt = 'xml'

5
neutron/tests/unit/plumgrid/extensions/test_securitygroups.py

@ -60,8 +60,3 @@ class SecurityGroupsTestCase(ext_sg.SecurityGroupDBTestCase):
class TestSecurityGroups(ext_sg.TestSecurityGroups, SecurityGroupsTestCase):
pass
class TestSecurityGroupsXML(TestSecurityGroups):
fmt = 'xml'

4
neutron/tests/unit/ryu/test_ryu_security_group.py

@ -84,7 +84,3 @@ class TestRyuSecurityGroups(RyuSecurityGroupsTestCase,
plugin = manager.NeutronManager.get_plugin()
port_dict = plugin.get_port_from_device('bad_device_id')
self.assertIsNone(port_dict)
class TestRyuSecurityGroupsXML(TestRyuSecurityGroups):
fmt = 'xml'

4
neutron/tests/unit/services/loadbalancer/test_agent_scheduler.py

@ -215,7 +215,3 @@ class LBaaSAgentSchedulerTestCase(test_agent_ext_plugin.AgentDBTestMixIn,
'fake_id',
expected_code=exc.HTTPForbidden.code,
admin_context=False)
class LBaaSAgentSchedulerTestCaseXML(LBaaSAgentSchedulerTestCase):
fmt = 'xml'

4
neutron/tests/unit/services/loadbalancer/test_loadbalancer_plugin.py

@ -456,7 +456,3 @@ class LoadBalancerExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
instance.delete_pool_health_monitor.assert_called_with(
mock.ANY, health_monitor_id, pool_id='id1')
self.assertEqual(res.status_int, exc.HTTPNoContent.code)
class LoadBalancerExtensionTestCaseXML(LoadBalancerExtensionTestCase):
fmt = 'xml'

8
neutron/tests/unit/services/loadbalancer/test_loadbalancer_quota_ext.py

@ -127,10 +127,6 @@ class LBaaSQuotaExtensionDbTestCase(LBaaSQuotaExtensionTestCase):
self.assertEqual(-1, quota['quota']['health_monitor'])
class LBaaSQuotaExtensionDbTestCaseXML(LBaaSQuotaExtensionDbTestCase):
fmt = 'xml'
class LBaaSQuotaExtensionCfgTestCase(
LBaaSQuotaExtensionTestCase):
@ -160,7 +156,3 @@ class LBaaSQuotaExtensionCfgTestCase(
self.serialize(quotas),
expect_errors=True)
self.assertEqual(403, res.status_int)
class LBaaSQuotaExtensionCfgTestCaseXML(LBaaSQuotaExtensionCfgTestCase):
fmt = 'xml'

4
neutron/tests/unit/services/vpn/test_vpnaas_extension.py

@ -520,7 +520,3 @@ class VpnaasExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
def test_ipsec_site_connection_delete(self):
"""Test case to delete a ipsec_site_connection."""
self._test_entity_delete('ipsec_site_connection')
class VpnaasExtensionTestCaseXML(VpnaasExtensionTestCase):
fmt = 'xml'

4
neutron/tests/unit/test_agent_ext_plugin.py

@ -251,7 +251,3 @@ class AgentDBTestCase(AgentDBTestMixIn,
agents = self._list_agents(
query_string='binary=neutron-l3-agent&host=' + L3_HOSTB)
self.assertFalse(agents['agents'][0]['alive'])
class AgentDBTestCaseXML(AgentDBTestCase):
fmt = 'xml'

4
neutron/tests/unit/test_api_v2.py

@ -1196,10 +1196,6 @@ class SubresourceTest(base.BaseTestCase, testlib_plugin.PluginSetupHelper):
# Note: since all resources use the same controller and validation
# logic, we actually get really good coverage from testing just networks.
class XMLV2TestCase(JSONV2TestCase):
fmt = 'xml'
class V2Views(base.BaseTestCase):
def _view(self, keys, collection, resource):
data = dict((key, 'value') for key in keys)

82
neutron/tests/unit/test_api_v2_resource.py

@ -42,16 +42,15 @@ class RequestTestCase(base.BaseTestCase):
self.assertEqual(result, "application/json")
def test_content_type_from_accept(self):
for content_type in ('application/xml',
'application/json'):
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = content_type
result = request.best_match_content_type()
self.assertEqual(result, content_type)
content_type = 'application/json'
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = content_type
result = request.best_match_content_type()
self.assertEqual(result, content_type)
def test_content_type_from_accept_best(self):
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = "application/xml, application/json"
request.headers["Accept"] = "application/json"
result = request.best_match_content_type()
self.assertEqual(result, "application/json")
@ -59,13 +58,9 @@ class RequestTestCase(base.BaseTestCase):
request.headers["Accept"] = ("application/json; q=0.3, "
"application/xml; q=0.9")
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
self.assertEqual(result, "application/json")
def test_content_type_from_query_extension(self):
request = wsgi.Request.blank('/tests/123.xml')
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
request = wsgi.Request.blank('/tests/123.json')
result = request.best_match_content_type()
self.assertEqual(result, "application/json")
@ -75,10 +70,10 @@ class RequestTestCase(base.BaseTestCase):
self.assertEqual(result, "application/json")
def test_content_type_accept_and_query_extension(self):
request = wsgi.Request.blank('/tests/123.xml')
request.headers["Accept"] = "application/json"
request = wsgi.Request.blank('/tests/123.json')
request.headers["Accept"] = "application/xml"
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
self.assertEqual(result, "application/json")
def test_content_type_accept_default(self):
request = wsgi.Request.blank('/tests/123.unsupported')
@ -121,10 +116,7 @@ class ResourceTestCase(base.BaseTestCase):
@staticmethod
def _get_deserializer(req_format):
if req_format == 'json':
return wsgi.JSONDeserializer()
else:
return wsgi.XMLDeserializer()
return wsgi.JSONDeserializer()
def test_unmapped_neutron_error_with_json(self):
msg = u'\u7f51\u7edc'
@ -148,28 +140,6 @@ class ResourceTestCase(base.BaseTestCase):
self.assertEqual(wsgi.JSONDeserializer().deserialize(res.body),
expected_res)
def test_unmapped_neutron_error_with_xml(self):
msg = u'\u7f51\u7edc'
class TestException(n_exc.NeutronException):
message = msg
expected_res = {'body': {
'NeutronError': {
'type': 'TestException',
'message': msg,
'detail': ''}}}
controller = mock.MagicMock()
controller.test.side_effect = TestException()
resource = webtest.TestApp(wsgi_resource.Resource(controller))
environ = {'wsgiorg.routing_args': (None, {'action': 'test',
'format': 'xml'})}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPInternalServerError.code)
self.assertEqual(wsgi.XMLDeserializer().deserialize(res.body),
expected_res)
@mock.patch('neutron.openstack.common.gettextutils.translate')
def test_unmapped_neutron_error_localized(self, mock_translation):
gettextutils.install('blaa', lazy=True)
@ -216,30 +186,6 @@ class ResourceTestCase(base.BaseTestCase):
self.assertEqual(wsgi.JSONDeserializer().deserialize(res.body),
expected_res)
def test_mapped_neutron_error_with_xml(self):
msg = u'\u7f51\u7edc'
class TestException(n_exc.NeutronException):
message = msg
expected_res = {'body': {
'NeutronError': {
'type': 'TestException',
'message': msg,
'detail': ''}}}
controller = mock.MagicMock()
controller.test.side_effect = TestException()
faults = {TestException: exc.HTTPGatewayTimeout}
resource = webtest.TestApp(wsgi_resource.Resource(controller,
faults=faults))
environ = {'wsgiorg.routing_args': (None, {'action': 'test',
'format': 'xml'})}
res = resource.get('', extra_environ=environ, expect_errors=True)
self.assertEqual(res.status_int, exc.HTTPGatewayTimeout.code)
self.assertEqual(wsgi.XMLDeserializer().deserialize(res.body),
expected_res)
@mock.patch('neutron.openstack.common.gettextutils.translate')
def test_mapped_neutron_error_localized(self, mock_translation):
gettextutils.install('blaa', lazy=True)
@ -308,9 +254,6 @@ class ResourceTestCase(base.BaseTestCase):
def test_unhandled_error_with_json(self):
self._test_unhandled_error()
def test_unhandled_error_with_xml(self):
self._test_unhandled_error(req_format='xml')
def _test_not_implemented_error(self, req_format='json'):
expected_res = {'body': {'NeutronError':
{'detail': '',
@ -330,9 +273,6 @@ class ResourceTestCase(base.BaseTestCase):
def test_not_implemented_error_with_json(self):
self._test_not_implemented_error()
def test_not_implemented_error_with_xml(self):
self._test_not_implemented_error(req_format='xml')
def test_status_200(self):
controller = mock.MagicMock()
controller.test = lambda request: {'foo': 'bar'}

20
neutron/tests/unit/test_db_plugin.py

@ -4061,23 +4061,3 @@ class NeutronDbPluginV2AsMixinTestCase(testlib_api.SqlTestCase):
self.net_data['network']['status'] = 'BUILD'
net = self.plugin.create_network(self.context, self.net_data)
self.assertEqual(net['status'], 'BUILD')
class TestBasicGetXML(TestBasicGet):
fmt = 'xml'
class TestNetworksV2XML(TestNetworksV2):
fmt = 'xml'
class TestPortsV2XML(TestPortsV2):
fmt = 'xml'
class TestSubnetsV2XML(TestSubnetsV2):
fmt = 'xml'
class TestV2HTTPResponseXML(TestV2HTTPResponse):
fmt = 'xml'

4
neutron/tests/unit/test_extension_allowedaddresspairs.py

@ -282,7 +282,3 @@ class TestAllowedAddressPairs(AllowedAddressPairDBTestCase):
port = self.deserialize(self.fmt, req.get_response(self.api))
self.assertEqual(port['port'][addr_pair.ADDRESS_PAIRS], [])
self._delete('ports', port['port']['id'])
class TestAllowedAddressPairsXML(TestAllowedAddressPairs):
fmt = 'xml'

4
neutron/tests/unit/test_extension_ext_net.py

@ -180,7 +180,3 @@ class ExtNetDBTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
self.assertEqual(res.status_int, exc.HTTPNoContent.code)
(l3_mock.delete_disassociated_floatingips
.assert_called_once_with(mock.ANY, net['network']['id']))
class ExtNetDBTestCaseXML(ExtNetDBTestCase):
fmt = 'xml'

8
neutron/tests/unit/test_extension_extraroute.py

@ -469,10 +469,6 @@ class ExtraRouteDBIntTestCase(test_l3.L3NatDBIntTestCase,
self.setup_notification_driver()
class ExtraRouteDBIntTestCaseXML(ExtraRouteDBIntTestCase):
fmt = 'xml'
class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
ExtraRouteDBTestCaseBase):
def setUp(self):
@ -492,7 +488,3 @@ class ExtraRouteDBSepTestCase(test_l3.L3NatDBSepTestCase,
service_plugins=service_plugins)
self.setup_notification_driver()
class ExtraRouteDBSepTestCaseXML(ExtraRouteDBSepTestCase):
fmt = 'xml'

4
neutron/tests/unit/test_extension_firewall.py

@ -372,10 +372,6 @@ class FirewallExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
self.assertEqual(res, return_value)
class FirewallExtensionTestCaseXML(FirewallExtensionTestCase):
fmt = 'xml'
class TestFirewallAttributeValidators(base.BaseTestCase):
def test_validate_port_range(self):

8
neutron/tests/unit/test_extension_security_group.py

@ -168,10 +168,6 @@ class SecurityGroupsTestCase(test_db_plugin.NeutronDbPluginV2TestCase):
self.assertEqual(security_group_rule[k], v)
class SecurityGroupsTestCaseXML(SecurityGroupsTestCase):
fmt = 'xml'
class SecurityGroupTestPlugin(db_base_plugin_v2.NeutronDbPluginV2,
securitygroups_db.SecurityGroupDbMixin):
"""Test plugin that implements necessary calls on create/delete port for
@ -1445,7 +1441,3 @@ class TestConvertProtocol(base.BaseTestCase):
for val in ['bad', '256', '-1']:
self.assertRaises(ext_sg.SecurityGroupRuleInvalidProtocol,
ext_sg.convert_protocol, val)
class TestSecurityGroupsXML(TestSecurityGroups):
fmt = 'xml'

4
neutron/tests/unit/test_extensions.py

@ -627,10 +627,6 @@ class ExtensionControllerTest(testlib_api.WebTestCase):
self.assertEqual(response.status_int, 404)
class ExtensionControllerTestXML(ExtensionControllerTest):
fmt = 'xml'
def app_factory(global_conf, **local_conf):
conf = global_conf.copy()
conf.update(local_conf)

12
neutron/tests/unit/test_l3_plugin.py

@ -214,10 +214,6 @@ class L3NatExtensionTestCase(test_api_v2_extension.ExtensionTestCase):
self.assertEqual(res['subnet_id'], subnet_id)
class L3NatExtensionTestCaseXML(L3NatExtensionTestCase):
fmt = 'xml'
# This base plugin class is for tests.
class TestL3NatBasePlugin(db_base_plugin_v2.NeutronDbPluginV2,
external_net_db.External_net_db_mixin):
@ -2144,11 +2140,3 @@ class L3NatDBSepTestCase(L3BaseForSepTests, L3NatTestCaseBase):
"""Unit tests for a separate L3 routing service plugin."""
pass
class L3NatDBIntTestCaseXML(L3NatDBIntTestCase):
fmt = 'xml'
class L3NatDBSepTestCaseXML(L3NatDBSepTestCase):
fmt = 'xml'

8
neutron/tests/unit/test_quota_ext.py

@ -320,10 +320,6 @@ class QuotaExtensionDbTestCase(QuotaExtensionTestCase):
self.assertEqual(400, res.status_int)
class QuotaExtensionDbTestCaseXML(QuotaExtensionDbTestCase):
fmt = 'xml'
class QuotaExtensionCfgTestCase(QuotaExtensionTestCase):
fmt = 'json'
@ -378,10 +374,6 @@ class QuotaExtensionCfgTestCase(QuotaExtensionTestCase):
self.assertEqual(403, res.status_int)
class QuotaExtensionCfgTestCaseXML(QuotaExtensionCfgTestCase):
fmt = 'xml'
class TestDbQuotaDriver(base.BaseTestCase):
"""Test for neutron.db.quota_db.DbQuotaDriver."""

4
neutron/tests/unit/test_security_groups_rpc.py

@ -970,10 +970,6 @@ class SGServerRpcCallBackTestCase(test_sg.SecurityGroupDBTestCase):
self._delete('ports', port_id2)
class SGServerRpcCallBackTestCaseXML(SGServerRpcCallBackTestCase):
fmt = 'xml'
class SGAgentRpcCallBackMixinTestCase(base.BaseTestCase):
def setUp(self):
super(SGAgentRpcCallBackMixinTestCase, self).setUp()

8
neutron/tests/unit/test_servicetype.py

@ -202,10 +202,6 @@ class ServiceTypeExtensionTestCase(ServiceTypeExtensionTestCaseBase):
self.assertEqual(res.status_int, webexc.HTTPOk.code)
class ServiceTypeExtensionTestCaseXML(ServiceTypeExtensionTestCase):
fmt = 'xml'
class ServiceTypeManagerExtTestCase(ServiceTypeExtensionTestCaseBase):
"""Tests ServiceTypemanager as a public API."""
def setUp(self):
@ -227,7 +223,3 @@ class ServiceTypeManagerExtTestCase(ServiceTypeExtensionTestCaseBase):
data = self.deserialize(res)
self.assertIn('service_providers', data)
self.assertEqual(len(data['service_providers']), 2)
class ServiceTypeManagerExtTestCaseXML(ServiceTypeManagerExtTestCase):
fmt = 'xml'

413
neutron/tests/unit/test_wsgi.py

@ -23,8 +23,6 @@ import testtools
import webob
import webob.exc
from neutron.api.v2 import attributes
from neutron.common import constants
from neutron.common import exceptions as exception
from neutron.tests import base
from neutron import wsgi
@ -154,33 +152,16 @@ class SerializerTest(base.BaseTestCase):
"""Test serialize with content type json."""
input_data = {'servers': ['test=pass']}
content_type = 'application/json'
serializer = wsgi.Serializer(default_xmlns="fake")
serializer = wsgi.Serializer()
result = serializer.serialize(input_data, content_type)
self.assertEqual('{"servers": ["test=pass"]}', result)
def test_serialize_content_type_xml(self):
"""Test serialize with content type xml."""
input_data = {'servers': ['test=pass']}
content_type = 'application/xml'
serializer = wsgi.Serializer(default_xmlns="fake")
result = serializer.serialize(input_data, content_type)
expected = (
'<?xml version=\'1.0\''
' encoding=\'UTF-8\'?>\n'
'<servers xmlns="http://openstack.org/quantum/api/v2.0" '
'xmlns:quantum="http://openstack.org/quantum/api/v2.0" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<server>test=pass</server></servers>'
)
self.assertEqual(expected, result)
def test_deserialize_raise_bad_request(self):
"""Test serialize verifies that exception is raises."""
content_type = 'application/unknown'
data_string = 'test'
serializer = wsgi.Serializer(default_xmlns="fake")
serializer = wsgi.Serializer()
self.assertRaises(
webob.exc.HTTPBadRequest,
@ -190,100 +171,11 @@ class SerializerTest(base.BaseTestCase):
"""Test Serializer.deserialize with content type json."""
content_type = 'application/json'
data_string = '{"servers": ["test=pass"]}'
serializer = wsgi.Serializer(default_xmlns="fake")
serializer = wsgi.Serializer()
result = serializer.deserialize(data_string, content_type)
self.assertEqual({'body': {u'servers': [u'test=pass']}}, result)
def test_deserialize_xml_content_type(self):
"""Test deserialize with content type xml."""
content_type = 'application/xml'
data_string = (
'<servers xmlns="fake">'
'<server>test=pass</server>'
'</servers>'
)
serializer = wsgi.Serializer(
default_xmlns="fake", metadata={'xmlns': 'fake'})
result = serializer.deserialize(data_string, content_type)
expected = {'body': {'servers': {'server': 'test=pass'}}}
self.assertEqual(expected, result)
def test_deserialize_xml_content_type_with_meta(self):
"""Test deserialize with content type xml with meta."""
content_type = 'application/xml'
data_string = (
'<servers>'
'<server name="s1">'
'<test test="a">passed</test>'
'</server>'
'</servers>'
)
metadata = {'plurals': {'servers': 'server'}, 'xmlns': 'fake'}
serializer = wsgi.Serializer(
default_xmlns="fake", metadata=metadata)
result = serializer.deserialize(data_string, content_type)
expected = {'body': {'servers': [{'name': 's1', 'test': 'passed'}]}}
self.assertEqual(expected, result)
def test_serialize_xml_root_key_is_dict(self):
"""Test Serializer.serialize with content type xml with meta dict."""
content_type = 'application/xml'
data = {'servers': {'network': (2, 3)}}
metadata = {'xmlns': 'fake'}
serializer = wsgi.Serializer(default_xmlns="fake", metadata=metadata)
result = serializer.serialize(data, content_type)
result = result.replace('\n', '')
expected = (
'<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
'<servers xmlns="fake" xmlns:quantum="fake" '
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<network>(2, 3)</network></servers>'
)
self.assertEqual(result, expected)
def test_serialize_xml_root_key_is_list(self):
"""Test serialize with content type xml with meta list."""
input_dict = {'servers': ['test=pass']}
content_type = 'application/xml'
metadata = {'application/xml': {
'xmlns': 'fake'}}
serializer = wsgi.Serializer(default_xmlns="fake", metadata=metadata)
result = serializer.serialize(input_dict, content_type)
result = result.replace('\n', '').replace(' ', '')
expected = (
'<?xmlversion=\'1.0\''
'encoding=\'UTF-8\'?>'
'<serversxmlns="http://openstack.org/quantum/api/v2.0"'
'xmlns:quantum="http://openstack.org/quantum/api/v2.0"'
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'<server>test=pass</server></servers>'
)
self.assertEqual(result, expected)
def test_serialize_xml_root_is_None(self):
input_dict = {'test': 'pass'}
content_type = 'application/xml'
serializer = wsgi.Serializer(default_xmlns="fake")
result = serializer.serialize(input_dict, content_type)
result = result.replace('\n', '').replace(' ', '')
expected = (
'<?xmlversion=\'1.0\''
'encoding=\'UTF-8\'?>'
'<testxmlns="http://openstack.org/quantum/api/v2.0"'
'xmlns:quantum="http://openstack.org/quantum/api/v2.0"'
'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'
'pass</test>'
)
self.assertEqual(result, expected)
class RequestDeserializerTest(testtools.TestCase):
def setUp(self):
@ -293,13 +185,7 @@ class RequestDeserializerTest(testtools.TestCase):
def deserialize(self, data, action='default'):
return 'pew_json'
class XMLDeserializer(object):
def deserialize(self, data, action='default'):
return 'pew_xml'
self.body_deserializers = {
'application/json': JSONDeserializer(),
'application/xml': XMLDeserializer()}
self.body_deserializers = {'application/json': JSONDeserializer()}
self.deserializer = wsgi.RequestDeserializer(self.body_deserializers)
@ -307,15 +193,10 @@ class RequestDeserializerTest(testtools.TestCase):
"""Test RequestDeserializer.get_body_deserializer."""
expected_json_serializer = self.deserializer.get_body_deserializer(
'application/json')
expected_xml_serializer = self.deserializer.get_body_deserializer(
'application/xml')
self.assertEqual(
expected_json_serializer,
self.body_deserializers['application/json'])
self.assertEqual(
expected_xml_serializer,
self.body_deserializers['application/xml'])
def test_get_expected_content_type(self):
"""Test RequestDeserializer.get_expected_content_type."""
@ -345,9 +226,9 @@ class RequestDeserializerTest(testtools.TestCase):
self.deserializer, 'get_action_args') as mock_method:
mock_method.return_value = {'action': 'create'}
request = wsgi.Request.blank('/')
request.headers['Accept'] = 'application/xml'
request.headers['Accept'] = 'application/json'
deserialized = self.deserializer.deserialize(request)
expected = ('create', {}, 'application/xml')
expected = ('create', {}, 'application/json')
self.assertEqual(expected, deserialized)
@ -368,17 +249,11 @@ class ResponseSerializerTest(testtools.TestCase):
def serialize(self, data, action='default'):
return 'pew_json'
class XMLSerializer(object):
def serialize(self, data, action='default'):
return 'pew_xml'
class HeadersSerializer(object):
def serialize(self, response, data, action):
response.status_int = 404
self.body_serializers = {
'application/json': JSONSerializer(),
'application/xml': XMLSerializer()}
self.body_serializers = {'application/json': JSONSerializer()}
self.serializer = wsgi.ResponseSerializer(
self.body_serializers, HeadersSerializer())
@ -410,13 +285,6 @@ class ResponseSerializerTest(testtools.TestCase):
self.assertEqual(response.body, 'pew_json')
self.assertEqual(response.status_int, 404)
def test_serialize_xml_response(self):
response = self.serializer.serialize({}, 'application/xml')
self.assertEqual(response.headers['Content-Type'], 'application/xml')
self.assertEqual(response.body, 'pew_xml')
self.assertEqual(response.status_int, 404)
def test_serialize_response_None(self):
response = self.serializer.serialize(
None, 'application/json')
@ -455,12 +323,6 @@ class RequestTest(base.BaseTestCase):
self.assertIsNone(request.get_content_type())
def test_content_type_from_accept(self):
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = "application/xml"
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = "application/json"
result = request.best_match_content_type()
@ -468,24 +330,12 @@ class RequestTest(base.BaseTestCase):
self.assertEqual(result, "application/json")
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = "application/xml, application/json"
request.headers["Accept"] = ("application/json; q=0.3")
result = request.best_match_content_type()
self.assertEqual(result, "application/json")
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = ("application/json; q=0.3, "
"application/xml; q=0.9")
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
def test_content_type_from_query_extension(self):
request = wsgi.Request.blank('/tests/123.xml')
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
request = wsgi.Request.blank('/tests/123.json')
result = request.best_match_content_type()
@ -497,11 +347,11 @@ class RequestTest(base.BaseTestCase):
self.assertEqual(result, "application/json")
def test_content_type_accept_and_query_extension(self):
request = wsgi.Request.blank('/tests/123.xml')
request = wsgi.Request.blank('/tests/123.json')
request.headers["Accept"] = "application/json"
result = request.best_match_content_type()
self.assertEqual(result, "application/xml")
self.assertEqual(result, "application/json")
def test_content_type_accept_default(self):
request = wsgi.Request.blank('/tests/123.unsupported')
@ -662,39 +512,6 @@ class JSONDeserializerTest(base.BaseTestCase):
deserializer.deserialize(data), as_dict)
class XMLDeserializerTest(base.BaseTestCase):
def test_xml_empty(self):
xml = '<a></a>'
as_dict = {'body': {'a': ''}}
deserializer = wsgi.XMLDeserializer()
self.assertEqual(
deserializer.deserialize(xml), as_dict)
def test_initialization(self):
xml = '<a><b>test</b></a>'
deserializer = wsgi.XMLDeserializer()
self.assertEqual(
{'body': {u'a': {u'b': u'test'}}}, deserializer(xml))
def test_default_raise_Malformed_Exception(self):
"""Verify that exception MalformedRequestBody is raised."""
data_string = ""
deserializer = wsgi.XMLDeserializer()
self.assertRaises(
exception.MalformedRequestBody, deserializer.default, data_string)
def test_xml_with_utf8(self):
xml = '<a>\xe7\xbd\x91\xe7\xbb\x9c</a>'
as_dict = {'body': {'a': u'\u7f51\u7edc'}}
deserializer = wsgi.XMLDeserializer()
self.assertEqual(
deserializer.deserialize(xml), as_dict)
class RequestHeadersDeserializerTest(base.BaseTestCase):
def test_default(self):
@ -811,7 +628,7 @@ class ResourceTest(base.BaseTestCase):
return 'off'
resource = wsgi.Resource(Controller(), my_fault_body_function)
request = wsgi.Request.blank(
"/", method='POST', headers={'Content-Type': "xml"})
"/", method='POST', headers={'Content-Type': "json"})
response = resource.dispatch(
request, action='index', action_args='test')
@ -829,7 +646,7 @@ class ResourceTest(base.BaseTestCase):
def __init__(self):
self.url = 'http://where.no'
self.environ = 'environ'
self.body = '{"Content-Type": "xml"}'
self.body = '{"Content-Type": "json"}'
def method(self):
pass
@ -867,212 +684,6 @@ class FaultTest(base.BaseTestCase):
self.assertEqual(415, response.status_int)
class XMLDictSerializerTest(base.BaseTestCase):
def test_xml(self):
NETWORK = {'network': {'test': None,
'tenant_id': 'test-tenant',
'name': 'net1',
'admin_state_up': True,
'subnets': [],
'dict': {},
'int': 3,
'long': 4L,
'float': 5.0,
'prefix:external': True,
'tests': [{'test1': 'value1'},
{'test2': 2, 'test3': 3}]}}
# XML is:
# <network xmlns="http://openstack.org/quantum/api/v2.0"
# xmlns:prefix="http://xxxx.yy.com"
# xmlns:quantum="http://openstack.org/quantum/api/v2.0"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
# <subnets quantum:type="list" /> # Empty List
# <int quantum:type="int">3</int> # Integer text
# <int quantum:type="long">4</int> # Long text
# <int quantum:type="float">5.0</int> # Float text
# <dict quantum:type="dict" /> # Empty Dict
# <name>net1</name>
# <admin_state_up quantum:type="bool">True</admin_state_up> # Bool
# <test xsi:nil="true" /> # None
# <tenant_id>test-tenant</tenant_id>
# # We must have a namespace defined in root for prefix:external
# <prefix:external quantum:type="bool">True</prefix:external>
# <tests> # List
# <test><test1>value1</test1></test>
# <test><test3 quantum:type="int">3</test3>
# <test2 quantum:type="int">2</test2>
# </test></tests>
# </network>
metadata = attributes.get_attr_metadata()
ns = {'prefix': 'http://xxxx.yy.com'}
metadata[constants.EXT_NS] = ns
metadata['plurals'] = {'tests': 'test'}
serializer = wsgi.XMLDictSerializer(metadata)
result = serializer.serialize(NETWORK)
deserializer = wsgi.XMLDeserializer(metadata)
new_net = deserializer.deserialize(result)['body']
self.assertEqual(NETWORK, new_net)
def test_None(self):
data = None
# Since it is None, we use xsi:nil='true'.
# In addition, we use an
# virtual XML root _v_root to wrap the XML doc.
# XML is:
# <_v_root xsi:nil="true"
# xmlns="http://openstack.org/quantum/api/v2.0"
# xmlns:quantum="http://openstack.org/quantum/api/v2.0"
# xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
serializer = wsgi.XMLDictSerializer(attributes.get_attr_metadata())
result = serializer.serialize(data)
deserializer = wsgi.XMLDeserializer(attributes.get_attr_metadata())
new_data = deserializer.deserialize(result)['body']
self.assertIsNone(new_data)
def test_empty_dic_xml(self):
data = {}