Adding unit test
Applying pep8 fixes Note: teardown does not yet work properly. Thinking about replacing it with something that simply deletes the temporary sql lite db.
This commit is contained in:
parent
fcc0f44230
commit
a93c1b1acb
@ -133,7 +133,8 @@ class Controller(common.QuantumController):
|
||||
def get_resource(self, request, tenant_id, network_id, id):
|
||||
try:
|
||||
result = self.network_manager.get_port_details(
|
||||
tenant_id, network_id, id).get('attachment-id', None)
|
||||
tenant_id, network_id, id).get('attachment-id',
|
||||
None)
|
||||
return dict(attachment=result)
|
||||
except exception.NetworkNotFound as e:
|
||||
return faults.Fault(faults.NetworkNotFound(e))
|
||||
|
@ -96,7 +96,6 @@ class Port(BASE, QuantumBase):
|
||||
self.network_id = network_id
|
||||
self.state = "DOWN"
|
||||
|
||||
|
||||
def __repr__(self):
|
||||
return "<Port(%s,%s,%s,%s)>" % (self.uuid, self.network_id,
|
||||
self.state, self.interface_id)
|
||||
|
@ -35,6 +35,7 @@ from quantum_plugin_base import QuantumPluginBase
|
||||
CONFIG_FILE = "plugins.ini"
|
||||
LOG = logging.getLogger('quantum.manager')
|
||||
|
||||
|
||||
def find_config(basepath):
|
||||
for root, dirs, files in os.walk(basepath):
|
||||
if CONFIG_FILE in files:
|
||||
|
@ -23,6 +23,7 @@ from quantum.db import api as db
|
||||
|
||||
LOG = logging.getLogger('quantum.plugins.SamplePlugin')
|
||||
|
||||
|
||||
class QuantumEchoPlugin(object):
|
||||
|
||||
"""
|
||||
@ -245,9 +246,12 @@ class FakePlugin(object):
|
||||
|
||||
def _get_port(self, tenant_id, network_id, port_id):
|
||||
net = self._get_network(tenant_id, network_id)
|
||||
try:
|
||||
port = db.port_get(port_id)
|
||||
except:
|
||||
raise exc.PortNotFound(net_id=network_id, port_id=port_id)
|
||||
# Port must exist and belong to the appropriate network.
|
||||
if not port or port['network_id']!=net['uuid']:
|
||||
if port['network_id'] != net['uuid']:
|
||||
raise exc.PortNotFound(net_id=network_id, port_id=port_id)
|
||||
return port
|
||||
|
||||
@ -309,7 +313,7 @@ class FakePlugin(object):
|
||||
# Verify that no attachments are plugged into the network
|
||||
if net:
|
||||
for port in db.port_list(net_id):
|
||||
if port['interface-id']:
|
||||
if port['interface_id']:
|
||||
raise exc.NetworkInUse(net_id=net_id)
|
||||
db.network_destroy(net_id)
|
||||
return net
|
||||
@ -350,7 +354,6 @@ class FakePlugin(object):
|
||||
'attachment-id': port.interface_id,
|
||||
'port-state': port.state}
|
||||
|
||||
|
||||
def create_port(self, tenant_id, net_id, port_state=None):
|
||||
"""
|
||||
Creates a port on the specified Virtual Network.
|
||||
|
@ -17,8 +17,6 @@
|
||||
# under the License.
|
||||
|
||||
import gettext
|
||||
import json
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
gettext.install('quantum', unicode=1)
|
||||
@ -161,7 +159,8 @@ class QuantumTest(unittest.TestCase):
|
||||
#self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||
#resdict = json.loads(output)
|
||||
#attachment = resdict["attachment"]
|
||||
#self.assertEqual(attachment, "fudd", "Attachment: %s" % attachment)
|
||||
#self.assertEqual(attachment, "fudd", "Attachment: %s"
|
||||
#% attachment)
|
||||
|
||||
#def test_renameNetwork(self):
|
||||
#self.create_network(test_network1_data)
|
||||
|
@ -37,16 +37,15 @@ class APIPortsTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
"""Clear the test environment"""
|
||||
# Remove all the networks.
|
||||
network_req = testlib.create_list_networks_request(self.tenant_id)
|
||||
network_req = testlib.create_network_list_request(self.tenant_id)
|
||||
network_res = network_req.get_response(self.api)
|
||||
network_data = Serializer().deserialize(network_res.body,"application/xml")
|
||||
network_data = Serializer().deserialize(network_res.body,
|
||||
"application/xml")
|
||||
for network in network_data["networks"].values():
|
||||
network_delete_req = testlib. \
|
||||
create_network_delete_request(self.tenant_id, network['id'])
|
||||
network_delete_req.get_response(self.api)
|
||||
|
||||
|
||||
|
||||
# Fault names copied here for reference
|
||||
#
|
||||
# _fault_names = {
|
||||
@ -61,10 +60,11 @@ class APIPortsTest(unittest.TestCase):
|
||||
# 470: "serviceUnavailable",
|
||||
# 471: "pluginFault"}
|
||||
|
||||
|
||||
def _test_delete_port(self, format):
|
||||
LOG.debug("_test_delete_port - format:%s - START", format)
|
||||
content_type = "application/" + format
|
||||
port_state = "ACTIVE"
|
||||
LOG.debug("Creating network and port")
|
||||
network_req = testlib.create_new_network_request(self.tenant_id,
|
||||
self.network_name,
|
||||
format)
|
||||
@ -72,14 +72,14 @@ class APIPortsTest(unittest.TestCase):
|
||||
self.assertEqual(network_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(network_res.body,
|
||||
content_type)
|
||||
network_id = network_data["networks"]["network"]["id"]
|
||||
network_id = network_data['networks']['network']['id']
|
||||
port_req = testlib.create_new_port_request(self.tenant_id,
|
||||
network_id, port_state,
|
||||
format)
|
||||
port_res = port_req.get_response(self.api)
|
||||
self.assertEqual(port_res.status_int, 200)
|
||||
port_data = Serializer().deserialize(port_res.body, content_type)
|
||||
port_id = port_data["ports"]["port"]["id"]
|
||||
port_id = port_data['ports']['port']['id']
|
||||
LOG.debug("Deleting port %(port_id)s for network %(network_id)s"\
|
||||
" of tenant %(tenant_id)s", locals())
|
||||
delete_port_req = testlib.create_port_delete_request(self.tenant_id,
|
||||
@ -88,31 +88,23 @@ class APIPortsTest(unittest.TestCase):
|
||||
format)
|
||||
delete_port_res = delete_port_req.get_response(self.api)
|
||||
self.assertEqual(delete_port_res.status_int, 202)
|
||||
list_port_req = testlib.create_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_count = len(port_list_data['ports'])
|
||||
self.assertEqual(port_count, 0)
|
||||
LOG.debug("_test_delete_port - format:%s - END", format)
|
||||
|
||||
def test_deletePort_xml(self):
|
||||
def test_delete_port_xml(self):
|
||||
self._test_delete_port('xml')
|
||||
|
||||
def test_deletePort_json(self):
|
||||
def test_delete_port_json(self):
|
||||
self._test_delete_port('json')
|
||||
|
||||
|
||||
#def test_deletePortNegative(self):
|
||||
# tenant = "tenant1"
|
||||
# network = "test1"
|
||||
|
||||
# Check for network not found
|
||||
#rv = self.port.delete("", tenant, network, 2)
|
||||
#self.assertEqual(rv.wrapped_exc.status_int, 420)
|
||||
|
||||
# Create a network to put the port on
|
||||
#req = testlib.create_network_request(tenant, network)
|
||||
#network_obj = self.network.create(req, tenant)
|
||||
#network_id = network_obj["networks"]["network"]["id"]
|
||||
|
||||
# Test for portnotfound
|
||||
#rv = self.port.delete("", tenant, network_id, 2)
|
||||
#self.assertEqual(rv.wrapped_exc.status_int, 430)
|
||||
|
||||
def _test_delete_port_in_use(self):
|
||||
# Test for portinuse
|
||||
#rv = self.port.create(req, tenant, network_id)
|
||||
#port_id = rv["ports"]["port"]["id"]
|
||||
@ -122,4 +114,39 @@ class APIPortsTest(unittest.TestCase):
|
||||
#self.assertEqual(rv.status_int, 202)
|
||||
#rv = self.port.delete("", tenant, network_id, port_id)
|
||||
#self.assertEqual(rv.wrapped_exc.status_int, 432)
|
||||
#
|
||||
pass
|
||||
|
||||
|
||||
def _test_delete_port_with_bad_id(self,format):
|
||||
LOG.debug("_test_delete_port - format:%s - START", format)
|
||||
content_type = "application/" + format
|
||||
port_state = "ACTIVE"
|
||||
LOG.debug("Creating network and port")
|
||||
network_req = testlib.create_new_network_request(self.tenant_id,
|
||||
self.network_name,
|
||||
format)
|
||||
network_res = network_req.get_response(self.api)
|
||||
self.assertEqual(network_res.status_int, 200)
|
||||
network_data = Serializer().deserialize(network_res.body,
|
||||
content_type)
|
||||
network_id = network_data['networks']['network']['id']
|
||||
port_req = testlib.create_new_port_request(self.tenant_id,
|
||||
network_id, port_state,
|
||||
format)
|
||||
port_res = port_req.get_response(self.api)
|
||||
self.assertEqual(port_res.status_int, 200)
|
||||
|
||||
# Test for portnotfound
|
||||
delete_port_req = testlib.create_port_delete_request(self.tenant_id,
|
||||
network_id,
|
||||
"A_BAD_ID",
|
||||
format)
|
||||
delete_port_res = delete_port_req.get_response(self.api)
|
||||
self.assertEqual(delete_port_res.status_int, 430)
|
||||
|
||||
def test_delete_port_with_bad_id_xml(self):
|
||||
self._test_delete_port_wth_bad_id('xml')
|
||||
|
||||
def test_delete_port_with_bad_id_json(self):
|
||||
self._test_delete_port_with_bad_id('json')
|
||||
|
||||
|
@ -11,7 +11,8 @@ def create_request(path, body, content_type, method= 'GET'):
|
||||
req.body = body
|
||||
return req
|
||||
|
||||
def create_list_networks_request(tenant_id, format='xml'):
|
||||
|
||||
def create_network_list_request(tenant_id, format='xml'):
|
||||
method = 'GET'
|
||||
path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals()
|
||||
content_type = "application/" + format
|
||||
@ -35,6 +36,14 @@ def create_network_delete_request(tenant_id, network_id, format='xml'):
|
||||
return create_request(path, None, content_type, method)
|
||||
|
||||
|
||||
def create_port_list_request(tenant_id, network_id, format='xml'):
|
||||
method = 'GET'
|
||||
path = "/tenants/%(tenant_id)s/networks/" \
|
||||
"%(network_id)s/ports.%(format)s" % locals()
|
||||
content_type = "application/" + format
|
||||
return create_request(path, None, content_type, method)
|
||||
|
||||
|
||||
def create_new_port_request(tenant_id, network_id, port_state, format='xml'):
|
||||
method = 'POST'
|
||||
path = "/tenants/%(tenant_id)s/networks/" \
|
||||
@ -44,6 +53,7 @@ def create_new_port_request(tenant_id, network_id, port_state, format='xml'):
|
||||
body = Serializer().serialize(data, content_type)
|
||||
return create_request(path, body, content_type, method)
|
||||
|
||||
|
||||
def create_port_delete_request(tenant_id, network_id, port_id, format='xml'):
|
||||
method = 'DELETE'
|
||||
path = "/tenants/%(tenant_id)s/networks/" \
|
||||
|
Loading…
Reference in New Issue
Block a user