Re-fixing issues with XML deserialization (changes got lost in merges with trunk)

Adapting assertions in unit tests merged from trunk to reflect changes in the API due to RFE requested by Erik Carlin
This commit is contained in:
Salvatore Orlando 2011-07-22 10:51:22 +01:00
parent 70d793c816
commit 49344b17c4
7 changed files with 59 additions and 41 deletions

View File

@ -79,5 +79,3 @@ class APIRouterV01(wsgi.Router):
controller=ports.Controller(plugin), controller=ports.Controller(plugin),
action="detach_resource", action="detach_resource",
conditions=dict(method=['DELETE'])) conditions=dict(method=['DELETE']))
print "MAPPED ROUTES"
print mapper

View File

@ -38,6 +38,7 @@ class Controller(common.QuantumController):
"network": ["id", "name"], "network": ["id", "name"],
"port": ["id", "state"], "port": ["id", "state"],
}, },
"plurals": {"networks": "network"}
}, },
} }
@ -52,11 +53,13 @@ class Controller(common.QuantumController):
def _item(self, req, tenant_id, network_id, def _item(self, req, tenant_id, network_id,
net_details=True, port_details=False): net_details=True, port_details=False):
network = self.network_manager.get_network_details( # We expect get_network_details to return information
# concerning logical ports as well.
network = self._plugin.get_network_details(
tenant_id, network_id) tenant_id, network_id)
builder = networks_view.get_view_builder(req) builder = networks_view.get_view_builder(req)
result = builder.build(network, net_details, port_details) result = builder.build(network, net_details, port_details)['network']
return dict(networks=result) return dict(network=result)
def _items(self, req, tenant_id, net_details=False, port_details=False): def _items(self, req, tenant_id, net_details=False, port_details=False):
""" Returns a list of networks. """ """ Returns a list of networks. """
@ -79,10 +82,11 @@ class Controller(common.QuantumController):
network_id = kwargs.get('id') network_id = kwargs.get('id')
try: try:
if network_id: if network_id:
# show details for a given network
return self._item(request, tenant_id, network_id, return self._item(request, tenant_id, network_id,
net_details=True, port_details=True) net_details=True, port_details=True)
else: else:
#do like show but with detaik # show details for all networks
return self._items(request, tenant_id, return self._items(request, tenant_id,
net_details=True, port_details=False) net_details=True, port_details=False)
network = self._plugin.get_network_details( network = self._plugin.get_network_details(

View File

@ -40,7 +40,10 @@ class Controller(common.QuantumController):
_serialization_metadata = { _serialization_metadata = {
"application/xml": { "application/xml": {
"attributes": { "attributes": {
"port": ["id", "state"], }, }, } "port": ["id", "state"], },
"plurals": {"ports": "port"}
},
}
def __init__(self, plugin): def __init__(self, plugin):
self._resource_name = 'port' self._resource_name = 'port'
@ -68,8 +71,8 @@ class Controller(common.QuantumController):
tenant_id, network_id, id) tenant_id, network_id, id)
builder = ports_view.get_view_builder(request) builder = ports_view.get_view_builder(request)
#build response with details #build response with details
result = builder.build(port, True) result = builder.build(port, True)['port']
return dict(ports=result) return dict(port=result)
except exception.NetworkNotFound as e: except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e)) return faults.Fault(faults.NetworkNotFound(e))
except exception.PortNotFound as e: except exception.PortNotFound as e:

View File

@ -50,10 +50,12 @@ class ViewBuilder(object):
def _build_detail(self, network_data): def _build_detail(self, network_data):
"""Return a detailed model of a network.""" """Return a detailed model of a network."""
# net-ports might not be present in response from plugin
ports = network_data.get('net-ports', None)
portcount = ports and len(ports) or 0
return dict(network=dict(id=network_data['net-id'], return dict(network=dict(id=network_data['net-id'],
name=network_data['net-name'], name=network_data['net-name'],
PortCount=len(network_data['net-ports']. PortCount=portcount))
keys())))
def _build_port(self, port_data): def _build_port(self, port_data):
"""Return details about a specific logical port.""" """Return details about a specific logical port."""

View File

@ -38,11 +38,10 @@ class ViewBuilder(object):
return port return port
def _build_simple(self, port_data): def _build_simple(self, port_data):
"""Return a simple model of a server.""" """Return a simple model of a port."""
return dict(port=dict(id=port_data['port-id'])) return dict(port=dict(id=port_data['port-id']))
def _build_detail(self, port_data): def _build_detail(self, port_data):
"""Return a simple model of a server.""" """Return a simple model of a port (with its state)."""
return dict(port=dict(id=port_data['port-id'], return dict(port=dict(id=port_data['port-id'],
state=port_data['port-state'], state=port_data['port-state']))
attachment=port_data['attachment']))

View File

@ -283,8 +283,11 @@ class FakePlugin(object):
""" """
LOG.debug("FakePlugin.get_network_details() called") LOG.debug("FakePlugin.get_network_details() called")
net = self._get_network(tenant_id, net_id) net = self._get_network(tenant_id, net_id)
# Retrieves ports for network
ports = self.get_all_ports(tenant_id, net_id)
return {'net-id': str(net.uuid), return {'net-id': str(net.uuid),
'net-name': net.name} 'net-name': net.name,
'net-ports': ports}
def create_network(self, tenant_id, net_name): def create_network(self, tenant_id, net_name):
""" """

View File

@ -75,7 +75,7 @@ class APITest(unittest.TestCase):
network_data = Serializer().deserialize(show_network_res.body, network_data = Serializer().deserialize(show_network_res.body,
content_type) content_type)
self.assertEqual(network_id, self.assertEqual(network_id,
network_data['networks']['network']['id']) network_data['network']['id'])
LOG.debug("_test_create_network - format:%s - END", format) LOG.debug("_test_create_network - format:%s - END", format)
def _test_create_network_badrequest(self, format): def _test_create_network_badrequest(self, format):
@ -96,8 +96,8 @@ class APITest(unittest.TestCase):
format) format)
list_network_res = list_network_req.get_response(self.api) list_network_res = list_network_req.get_response(self.api)
self.assertEqual(list_network_res.status_int, 200) self.assertEqual(list_network_res.status_int, 200)
network_data = Serializer().deserialize(list_network_res.body, network_data = self._net_serializer.deserialize(
content_type) list_network_res.body, content_type)
# Check network count: should return 2 # Check network count: should return 2
self.assertEqual(len(network_data['networks']), 2) self.assertEqual(len(network_data['networks']), 2)
LOG.debug("_test_list_networks - format:%s - END", format) LOG.debug("_test_list_networks - format:%s - END", format)
@ -111,10 +111,12 @@ class APITest(unittest.TestCase):
format) format)
show_network_res = show_network_req.get_response(self.api) show_network_res = show_network_req.get_response(self.api)
self.assertEqual(show_network_res.status_int, 200) self.assertEqual(show_network_res.status_int, 200)
network_data = Serializer().deserialize(show_network_res.body, network_data = self._net_serializer.deserialize(
content_type) show_network_res.body, content_type)
self.assertEqual({'id': network_id, 'name': self.network_name}, self.assertEqual({'id': network_id,
network_data['networks']['network']) 'name': self.network_name,
'PortCount': 0},
network_data['network'])
LOG.debug("_test_show_network - format:%s - END", format) LOG.debug("_test_show_network - format:%s - END", format)
def _test_show_network_not_found(self, format): def _test_show_network_not_found(self, format):
@ -142,10 +144,12 @@ class APITest(unittest.TestCase):
format) format)
show_network_res = show_network_req.get_response(self.api) show_network_res = show_network_req.get_response(self.api)
self.assertEqual(show_network_res.status_int, 200) self.assertEqual(show_network_res.status_int, 200)
network_data = Serializer().deserialize(show_network_res.body, network_data = self._net_serializer.deserialize(
content_type) show_network_res.body, content_type)
self.assertEqual({'id': network_id, 'name': new_name}, self.assertEqual({'id': network_id,
network_data['networks']['network']) 'name': new_name,
'PortCount': 0},
network_data['network'])
LOG.debug("_test_rename_network - format:%s - END", format) LOG.debug("_test_rename_network - format:%s - END", format)
def _test_rename_network_badrequest(self, format): def _test_rename_network_badrequest(self, format):
@ -189,8 +193,8 @@ class APITest(unittest.TestCase):
list_network_req = testlib.network_list_request(self.tenant_id, list_network_req = testlib.network_list_request(self.tenant_id,
format) format)
list_network_res = list_network_req.get_response(self.api) list_network_res = list_network_req.get_response(self.api)
network_list_data = Serializer().deserialize(list_network_res.body, network_list_data = self._net_serializer.deserialize(
content_type) list_network_res.body, content_type)
network_count = len(network_list_data['networks']) network_count = len(network_list_data['networks'])
self.assertEqual(network_count, 0) self.assertEqual(network_count, 0)
LOG.debug("_test_delete_network - format:%s - END", format) LOG.debug("_test_delete_network - format:%s - END", format)
@ -233,8 +237,8 @@ class APITest(unittest.TestCase):
network_id, format) network_id, format)
list_port_res = list_port_req.get_response(self.api) list_port_res = list_port_req.get_response(self.api)
self.assertEqual(list_port_res.status_int, 200) self.assertEqual(list_port_res.status_int, 200)
port_data = Serializer().deserialize(list_port_res.body, port_data = self._port_serializer.deserialize(
content_type) list_port_res.body, content_type)
# Check port count: should return 2 # Check port count: should return 2
self.assertEqual(len(port_data['ports']), 2) self.assertEqual(len(port_data['ports']), 2)
LOG.debug("_test_list_ports - format:%s - END", format) LOG.debug("_test_list_ports - format:%s - END", format)
@ -250,10 +254,10 @@ class APITest(unittest.TestCase):
format) format)
show_port_res = show_port_req.get_response(self.api) show_port_res = show_port_req.get_response(self.api)
self.assertEqual(show_port_res.status_int, 200) self.assertEqual(show_port_res.status_int, 200)
port_data = Serializer().deserialize(show_port_res.body, port_data = self._port_serializer.deserialize(
content_type) show_port_res.body, content_type)
self.assertEqual({'id': port_id, 'state': port_state}, self.assertEqual({'id': port_id, 'state': port_state},
port_data['ports']['port']) port_data['port'])
LOG.debug("_test_show_port - format:%s - END", format) LOG.debug("_test_show_port - format:%s - END", format)
def _test_show_port_networknotfound(self, format): def _test_show_port_networknotfound(self, format):
@ -291,8 +295,9 @@ class APITest(unittest.TestCase):
network_id, port_id, format) network_id, port_id, format)
show_port_res = show_port_req.get_response(self.api) show_port_res = show_port_req.get_response(self.api)
self.assertEqual(show_port_res.status_int, 200) self.assertEqual(show_port_res.status_int, 200)
port_data = Serializer().deserialize(show_port_res.body, content_type) port_data = self._port_serializer.deserialize(
self.assertEqual(port_id, port_data['ports']['port']['id']) show_port_res.body, content_type)
self.assertEqual(port_id, port_data['port']['id'])
LOG.debug("_test_create_port - format:%s - END", format) LOG.debug("_test_create_port - format:%s - END", format)
def _test_create_port_networknotfound(self, format): def _test_create_port_networknotfound(self, format):
@ -329,8 +334,8 @@ class APITest(unittest.TestCase):
list_port_req = testlib.port_list_request(self.tenant_id, network_id, list_port_req = testlib.port_list_request(self.tenant_id, network_id,
format) format)
list_port_res = list_port_req.get_response(self.api) list_port_res = list_port_req.get_response(self.api)
port_list_data = Serializer().deserialize(list_port_res.body, port_list_data = self._port_serializer.deserialize(
content_type) list_port_res.body, content_type)
port_count = len(port_list_data['ports']) port_count = len(port_list_data['ports'])
self.assertEqual(port_count, 0) self.assertEqual(port_count, 0)
LOG.debug("_test_delete_port - format:%s - END", format) LOG.debug("_test_delete_port - format:%s - END", format)
@ -405,10 +410,10 @@ class APITest(unittest.TestCase):
format) format)
show_port_res = show_port_req.get_response(self.api) show_port_res = show_port_req.get_response(self.api)
self.assertEqual(show_port_res.status_int, 200) self.assertEqual(show_port_res.status_int, 200)
network_data = Serializer().deserialize(show_port_res.body, port_data = self._port_serializer.deserialize(
content_type) show_port_res.body, content_type)
self.assertEqual({'id': port_id, 'state': new_port_state}, self.assertEqual({'id': port_id, 'state': new_port_state},
network_data['ports']['port']) port_data['port'])
LOG.debug("_test_set_port_state - format:%s - END", format) LOG.debug("_test_set_port_state - format:%s - END", format)
def _test_set_port_state_networknotfound(self, format): def _test_set_port_state_networknotfound(self, format):
@ -620,6 +625,10 @@ class APITest(unittest.TestCase):
self.api = server.APIRouterV01(options) self.api = server.APIRouterV01(options)
self.tenant_id = "test_tenant" self.tenant_id = "test_tenant"
self.network_name = "test_network" self.network_name = "test_network"
self._net_serializer = \
Serializer(server.networks.Controller._serialization_metadata)
self._port_serializer = \
Serializer(server.ports.Controller._serialization_metadata)
def tearDown(self): def tearDown(self):
"""Clear the test environment""" """Clear the test environment"""