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):
|
def get_resource(self, request, tenant_id, network_id, id):
|
||||||
try:
|
try:
|
||||||
result = self.network_manager.get_port_details(
|
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)
|
return dict(attachment=result)
|
||||||
except exception.NetworkNotFound as e:
|
except exception.NetworkNotFound as e:
|
||||||
return faults.Fault(faults.NetworkNotFound(e))
|
return faults.Fault(faults.NetworkNotFound(e))
|
||||||
|
@ -96,7 +96,6 @@ class Port(BASE, QuantumBase):
|
|||||||
self.network_id = network_id
|
self.network_id = network_id
|
||||||
self.state = "DOWN"
|
self.state = "DOWN"
|
||||||
|
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Port(%s,%s,%s,%s)>" % (self.uuid, self.network_id,
|
return "<Port(%s,%s,%s,%s)>" % (self.uuid, self.network_id,
|
||||||
self.state, self.interface_id)
|
self.state, self.interface_id)
|
||||||
|
@ -35,6 +35,7 @@ from quantum_plugin_base import QuantumPluginBase
|
|||||||
CONFIG_FILE = "plugins.ini"
|
CONFIG_FILE = "plugins.ini"
|
||||||
LOG = logging.getLogger('quantum.manager')
|
LOG = logging.getLogger('quantum.manager')
|
||||||
|
|
||||||
|
|
||||||
def find_config(basepath):
|
def find_config(basepath):
|
||||||
for root, dirs, files in os.walk(basepath):
|
for root, dirs, files in os.walk(basepath):
|
||||||
if CONFIG_FILE in files:
|
if CONFIG_FILE in files:
|
||||||
|
@ -23,6 +23,7 @@ from quantum.db import api as db
|
|||||||
|
|
||||||
LOG = logging.getLogger('quantum.plugins.SamplePlugin')
|
LOG = logging.getLogger('quantum.plugins.SamplePlugin')
|
||||||
|
|
||||||
|
|
||||||
class QuantumEchoPlugin(object):
|
class QuantumEchoPlugin(object):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -245,9 +246,12 @@ class FakePlugin(object):
|
|||||||
|
|
||||||
def _get_port(self, tenant_id, network_id, port_id):
|
def _get_port(self, tenant_id, network_id, port_id):
|
||||||
net = self._get_network(tenant_id, network_id)
|
net = self._get_network(tenant_id, network_id)
|
||||||
|
try:
|
||||||
port = db.port_get(port_id)
|
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.
|
# 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)
|
raise exc.PortNotFound(net_id=network_id, port_id=port_id)
|
||||||
return port
|
return port
|
||||||
|
|
||||||
@ -309,7 +313,7 @@ class FakePlugin(object):
|
|||||||
# Verify that no attachments are plugged into the network
|
# Verify that no attachments are plugged into the network
|
||||||
if net:
|
if net:
|
||||||
for port in db.port_list(net_id):
|
for port in db.port_list(net_id):
|
||||||
if port['interface-id']:
|
if port['interface_id']:
|
||||||
raise exc.NetworkInUse(net_id=net_id)
|
raise exc.NetworkInUse(net_id=net_id)
|
||||||
db.network_destroy(net_id)
|
db.network_destroy(net_id)
|
||||||
return net
|
return net
|
||||||
@ -350,7 +354,6 @@ class FakePlugin(object):
|
|||||||
'attachment-id': port.interface_id,
|
'attachment-id': port.interface_id,
|
||||||
'port-state': port.state}
|
'port-state': port.state}
|
||||||
|
|
||||||
|
|
||||||
def create_port(self, tenant_id, net_id, port_state=None):
|
def create_port(self, tenant_id, net_id, port_state=None):
|
||||||
"""
|
"""
|
||||||
Creates a port on the specified Virtual Network.
|
Creates a port on the specified Virtual Network.
|
||||||
|
@ -17,8 +17,6 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
import json
|
|
||||||
import sys
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
gettext.install('quantum', unicode=1)
|
gettext.install('quantum', unicode=1)
|
||||||
@ -161,7 +159,8 @@ class QuantumTest(unittest.TestCase):
|
|||||||
#self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
#self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
#resdict = json.loads(output)
|
#resdict = json.loads(output)
|
||||||
#attachment = resdict["attachment"]
|
#attachment = resdict["attachment"]
|
||||||
#self.assertEqual(attachment, "fudd", "Attachment: %s" % attachment)
|
#self.assertEqual(attachment, "fudd", "Attachment: %s"
|
||||||
|
#% attachment)
|
||||||
|
|
||||||
#def test_renameNetwork(self):
|
#def test_renameNetwork(self):
|
||||||
#self.create_network(test_network1_data)
|
#self.create_network(test_network1_data)
|
||||||
|
@ -37,16 +37,15 @@ class APIPortsTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
"""Clear the test environment"""
|
"""Clear the test environment"""
|
||||||
# Remove all the networks.
|
# 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_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():
|
for network in network_data["networks"].values():
|
||||||
network_delete_req = testlib. \
|
network_delete_req = testlib. \
|
||||||
create_network_delete_request(self.tenant_id, network['id'])
|
create_network_delete_request(self.tenant_id, network['id'])
|
||||||
network_delete_req.get_response(self.api)
|
network_delete_req.get_response(self.api)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Fault names copied here for reference
|
# Fault names copied here for reference
|
||||||
#
|
#
|
||||||
# _fault_names = {
|
# _fault_names = {
|
||||||
@ -61,10 +60,11 @@ class APIPortsTest(unittest.TestCase):
|
|||||||
# 470: "serviceUnavailable",
|
# 470: "serviceUnavailable",
|
||||||
# 471: "pluginFault"}
|
# 471: "pluginFault"}
|
||||||
|
|
||||||
|
|
||||||
def _test_delete_port(self, format):
|
def _test_delete_port(self, format):
|
||||||
|
LOG.debug("_test_delete_port - format:%s - START", format)
|
||||||
content_type = "application/" + format
|
content_type = "application/" + format
|
||||||
port_state = "ACTIVE"
|
port_state = "ACTIVE"
|
||||||
|
LOG.debug("Creating network and port")
|
||||||
network_req = testlib.create_new_network_request(self.tenant_id,
|
network_req = testlib.create_new_network_request(self.tenant_id,
|
||||||
self.network_name,
|
self.network_name,
|
||||||
format)
|
format)
|
||||||
@ -72,14 +72,14 @@ class APIPortsTest(unittest.TestCase):
|
|||||||
self.assertEqual(network_res.status_int, 200)
|
self.assertEqual(network_res.status_int, 200)
|
||||||
network_data = Serializer().deserialize(network_res.body,
|
network_data = Serializer().deserialize(network_res.body,
|
||||||
content_type)
|
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,
|
port_req = testlib.create_new_port_request(self.tenant_id,
|
||||||
network_id, port_state,
|
network_id, port_state,
|
||||||
format)
|
format)
|
||||||
port_res = port_req.get_response(self.api)
|
port_res = port_req.get_response(self.api)
|
||||||
self.assertEqual(port_res.status_int, 200)
|
self.assertEqual(port_res.status_int, 200)
|
||||||
port_data = Serializer().deserialize(port_res.body, content_type)
|
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"\
|
LOG.debug("Deleting port %(port_id)s for network %(network_id)s"\
|
||||||
" of tenant %(tenant_id)s", locals())
|
" of tenant %(tenant_id)s", locals())
|
||||||
delete_port_req = testlib.create_port_delete_request(self.tenant_id,
|
delete_port_req = testlib.create_port_delete_request(self.tenant_id,
|
||||||
@ -88,31 +88,23 @@ class APIPortsTest(unittest.TestCase):
|
|||||||
format)
|
format)
|
||||||
delete_port_res = delete_port_req.get_response(self.api)
|
delete_port_res = delete_port_req.get_response(self.api)
|
||||||
self.assertEqual(delete_port_res.status_int, 202)
|
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')
|
self._test_delete_port('xml')
|
||||||
|
|
||||||
def test_deletePort_json(self):
|
def test_delete_port_json(self):
|
||||||
self._test_delete_port('json')
|
self._test_delete_port('json')
|
||||||
|
|
||||||
|
def _test_delete_port_in_use(self):
|
||||||
#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)
|
|
||||||
|
|
||||||
# Test for portinuse
|
# Test for portinuse
|
||||||
#rv = self.port.create(req, tenant, network_id)
|
#rv = self.port.create(req, tenant, network_id)
|
||||||
#port_id = rv["ports"]["port"]["id"]
|
#port_id = rv["ports"]["port"]["id"]
|
||||||
@ -122,4 +114,39 @@ class APIPortsTest(unittest.TestCase):
|
|||||||
#self.assertEqual(rv.status_int, 202)
|
#self.assertEqual(rv.status_int, 202)
|
||||||
#rv = self.port.delete("", tenant, network_id, port_id)
|
#rv = self.port.delete("", tenant, network_id, port_id)
|
||||||
#self.assertEqual(rv.wrapped_exc.status_int, 432)
|
#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
|
req.body = body
|
||||||
return req
|
return req
|
||||||
|
|
||||||
def create_list_networks_request(tenant_id, format='xml'):
|
|
||||||
|
def create_network_list_request(tenant_id, format='xml'):
|
||||||
method = 'GET'
|
method = 'GET'
|
||||||
path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals()
|
path = "/tenants/%(tenant_id)s/networks.%(format)s" % locals()
|
||||||
content_type = "application/" + format
|
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)
|
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'):
|
def create_new_port_request(tenant_id, network_id, port_state, format='xml'):
|
||||||
method = 'POST'
|
method = 'POST'
|
||||||
path = "/tenants/%(tenant_id)s/networks/" \
|
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)
|
body = Serializer().serialize(data, content_type)
|
||||||
return create_request(path, body, content_type, method)
|
return create_request(path, body, content_type, method)
|
||||||
|
|
||||||
|
|
||||||
def create_port_delete_request(tenant_id, network_id, port_id, format='xml'):
|
def create_port_delete_request(tenant_id, network_id, port_id, format='xml'):
|
||||||
method = 'DELETE'
|
method = 'DELETE'
|
||||||
path = "/tenants/%(tenant_id)s/networks/" \
|
path = "/tenants/%(tenant_id)s/networks/" \
|
||||||
|
Loading…
Reference in New Issue
Block a user