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:
parent
70d793c816
commit
49344b17c4
@ -79,5 +79,3 @@ class APIRouterV01(wsgi.Router):
|
||||
controller=ports.Controller(plugin),
|
||||
action="detach_resource",
|
||||
conditions=dict(method=['DELETE']))
|
||||
print "MAPPED ROUTES"
|
||||
print mapper
|
||||
|
@ -38,6 +38,7 @@ class Controller(common.QuantumController):
|
||||
"network": ["id", "name"],
|
||||
"port": ["id", "state"],
|
||||
},
|
||||
"plurals": {"networks": "network"}
|
||||
},
|
||||
}
|
||||
|
||||
@ -52,11 +53,13 @@ class Controller(common.QuantumController):
|
||||
|
||||
def _item(self, req, tenant_id, network_id,
|
||||
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)
|
||||
builder = networks_view.get_view_builder(req)
|
||||
result = builder.build(network, net_details, port_details)
|
||||
return dict(networks=result)
|
||||
result = builder.build(network, net_details, port_details)['network']
|
||||
return dict(network=result)
|
||||
|
||||
def _items(self, req, tenant_id, net_details=False, port_details=False):
|
||||
""" Returns a list of networks. """
|
||||
@ -79,10 +82,11 @@ class Controller(common.QuantumController):
|
||||
network_id = kwargs.get('id')
|
||||
try:
|
||||
if network_id:
|
||||
# show details for a given network
|
||||
return self._item(request, tenant_id, network_id,
|
||||
net_details=True, port_details=True)
|
||||
else:
|
||||
#do like show but with detaik
|
||||
# show details for all networks
|
||||
return self._items(request, tenant_id,
|
||||
net_details=True, port_details=False)
|
||||
network = self._plugin.get_network_details(
|
||||
|
@ -40,7 +40,10 @@ class Controller(common.QuantumController):
|
||||
_serialization_metadata = {
|
||||
"application/xml": {
|
||||
"attributes": {
|
||||
"port": ["id", "state"], }, }, }
|
||||
"port": ["id", "state"], },
|
||||
"plurals": {"ports": "port"}
|
||||
},
|
||||
}
|
||||
|
||||
def __init__(self, plugin):
|
||||
self._resource_name = 'port'
|
||||
@ -68,8 +71,8 @@ class Controller(common.QuantumController):
|
||||
tenant_id, network_id, id)
|
||||
builder = ports_view.get_view_builder(request)
|
||||
#build response with details
|
||||
result = builder.build(port, True)
|
||||
return dict(ports=result)
|
||||
result = builder.build(port, True)['port']
|
||||
return dict(port=result)
|
||||
except exception.NetworkNotFound as e:
|
||||
return faults.Fault(faults.NetworkNotFound(e))
|
||||
except exception.PortNotFound as e:
|
||||
|
@ -50,10 +50,12 @@ class ViewBuilder(object):
|
||||
|
||||
def _build_detail(self, network_data):
|
||||
"""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'],
|
||||
name=network_data['net-name'],
|
||||
PortCount=len(network_data['net-ports'].
|
||||
keys())))
|
||||
PortCount=portcount))
|
||||
|
||||
def _build_port(self, port_data):
|
||||
"""Return details about a specific logical port."""
|
||||
|
@ -38,11 +38,10 @@ class ViewBuilder(object):
|
||||
return port
|
||||
|
||||
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']))
|
||||
|
||||
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'],
|
||||
state=port_data['port-state'],
|
||||
attachment=port_data['attachment']))
|
||||
state=port_data['port-state']))
|
||||
|
@ -283,8 +283,11 @@ class FakePlugin(object):
|
||||
"""
|
||||
LOG.debug("FakePlugin.get_network_details() called")
|
||||
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),
|
||||
'net-name': net.name}
|
||||
'net-name': net.name,
|
||||
'net-ports': ports}
|
||||
|
||||
def create_network(self, tenant_id, net_name):
|
||||
"""
|
||||
|
@ -75,7 +75,7 @@ class APITest(unittest.TestCase):
|
||||
network_data = Serializer().deserialize(show_network_res.body,
|
||||
content_type)
|
||||
self.assertEqual(network_id,
|
||||
network_data['networks']['network']['id'])
|
||||
network_data['network']['id'])
|
||||
LOG.debug("_test_create_network - format:%s - END", format)
|
||||
|
||||
def _test_create_network_badrequest(self, format):
|
||||
@ -96,8 +96,8 @@ class APITest(unittest.TestCase):
|
||||
format)
|
||||
list_network_res = list_network_req.get_response(self.api)
|
||||
self.assertEqual(list_network_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(list_network_res.body,
|
||||
content_type)
|
||||
network_data = self._net_serializer.deserialize(
|
||||
list_network_res.body, content_type)
|
||||
# Check network count: should return 2
|
||||
self.assertEqual(len(network_data['networks']), 2)
|
||||
LOG.debug("_test_list_networks - format:%s - END", format)
|
||||
@ -111,10 +111,12 @@ class APITest(unittest.TestCase):
|
||||
format)
|
||||
show_network_res = show_network_req.get_response(self.api)
|
||||
self.assertEqual(show_network_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(show_network_res.body,
|
||||
content_type)
|
||||
self.assertEqual({'id': network_id, 'name': self.network_name},
|
||||
network_data['networks']['network'])
|
||||
network_data = self._net_serializer.deserialize(
|
||||
show_network_res.body, content_type)
|
||||
self.assertEqual({'id': network_id,
|
||||
'name': self.network_name,
|
||||
'PortCount': 0},
|
||||
network_data['network'])
|
||||
LOG.debug("_test_show_network - format:%s - END", format)
|
||||
|
||||
def _test_show_network_not_found(self, format):
|
||||
@ -142,10 +144,12 @@ class APITest(unittest.TestCase):
|
||||
format)
|
||||
show_network_res = show_network_req.get_response(self.api)
|
||||
self.assertEqual(show_network_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(show_network_res.body,
|
||||
content_type)
|
||||
self.assertEqual({'id': network_id, 'name': new_name},
|
||||
network_data['networks']['network'])
|
||||
network_data = self._net_serializer.deserialize(
|
||||
show_network_res.body, content_type)
|
||||
self.assertEqual({'id': network_id,
|
||||
'name': new_name,
|
||||
'PortCount': 0},
|
||||
network_data['network'])
|
||||
LOG.debug("_test_rename_network - format:%s - END", 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,
|
||||
format)
|
||||
list_network_res = list_network_req.get_response(self.api)
|
||||
network_list_data = Serializer().deserialize(list_network_res.body,
|
||||
content_type)
|
||||
network_list_data = self._net_serializer.deserialize(
|
||||
list_network_res.body, content_type)
|
||||
network_count = len(network_list_data['networks'])
|
||||
self.assertEqual(network_count, 0)
|
||||
LOG.debug("_test_delete_network - format:%s - END", format)
|
||||
@ -233,8 +237,8 @@ class APITest(unittest.TestCase):
|
||||
network_id, format)
|
||||
list_port_res = list_port_req.get_response(self.api)
|
||||
self.assertEqual(list_port_res.status_int, 200)
|
||||
port_data = Serializer().deserialize(list_port_res.body,
|
||||
content_type)
|
||||
port_data = self._port_serializer.deserialize(
|
||||
list_port_res.body, content_type)
|
||||
# Check port count: should return 2
|
||||
self.assertEqual(len(port_data['ports']), 2)
|
||||
LOG.debug("_test_list_ports - format:%s - END", format)
|
||||
@ -250,10 +254,10 @@ class APITest(unittest.TestCase):
|
||||
format)
|
||||
show_port_res = show_port_req.get_response(self.api)
|
||||
self.assertEqual(show_port_res.status_int, 200)
|
||||
port_data = Serializer().deserialize(show_port_res.body,
|
||||
content_type)
|
||||
port_data = self._port_serializer.deserialize(
|
||||
show_port_res.body, content_type)
|
||||
self.assertEqual({'id': port_id, 'state': port_state},
|
||||
port_data['ports']['port'])
|
||||
port_data['port'])
|
||||
LOG.debug("_test_show_port - format:%s - END", format)
|
||||
|
||||
def _test_show_port_networknotfound(self, format):
|
||||
@ -291,8 +295,9 @@ class APITest(unittest.TestCase):
|
||||
network_id, port_id, format)
|
||||
show_port_res = show_port_req.get_response(self.api)
|
||||
self.assertEqual(show_port_res.status_int, 200)
|
||||
port_data = Serializer().deserialize(show_port_res.body, content_type)
|
||||
self.assertEqual(port_id, port_data['ports']['port']['id'])
|
||||
port_data = self._port_serializer.deserialize(
|
||||
show_port_res.body, content_type)
|
||||
self.assertEqual(port_id, port_data['port']['id'])
|
||||
LOG.debug("_test_create_port - format:%s - END", 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,
|
||||
format)
|
||||
list_port_res = list_port_req.get_response(self.api)
|
||||
port_list_data = Serializer().deserialize(list_port_res.body,
|
||||
content_type)
|
||||
port_list_data = self._port_serializer.deserialize(
|
||||
list_port_res.body, content_type)
|
||||
port_count = len(port_list_data['ports'])
|
||||
self.assertEqual(port_count, 0)
|
||||
LOG.debug("_test_delete_port - format:%s - END", format)
|
||||
@ -405,10 +410,10 @@ class APITest(unittest.TestCase):
|
||||
format)
|
||||
show_port_res = show_port_req.get_response(self.api)
|
||||
self.assertEqual(show_port_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(show_port_res.body,
|
||||
content_type)
|
||||
port_data = self._port_serializer.deserialize(
|
||||
show_port_res.body, content_type)
|
||||
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)
|
||||
|
||||
def _test_set_port_state_networknotfound(self, format):
|
||||
@ -620,6 +625,10 @@ class APITest(unittest.TestCase):
|
||||
self.api = server.APIRouterV01(options)
|
||||
self.tenant_id = "test_tenant"
|
||||
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):
|
||||
"""Clear the test environment"""
|
||||
|
Loading…
Reference in New Issue
Block a user