Added some more plugin agnostic tests (attachment and negative tests) and some
pep8 fixes.
This commit is contained in:
@@ -299,7 +299,8 @@ def api_plug_iface(client, *args):
|
|||||||
LOG.error("Failed to plug iface \"%s\" to port \"%s\": %s" % (vid,
|
LOG.error("Failed to plug iface \"%s\" to port \"%s\": %s" % (vid,
|
||||||
pid, output))
|
pid, output))
|
||||||
return
|
return
|
||||||
print "Plugged interface \"%s\" to port:%s on network:%s" % (vid, pid, nid)
|
print "Plugged interface \"%s\" to port:%s on network:%s" % (vid, pid,
|
||||||
|
nid)
|
||||||
|
|
||||||
|
|
||||||
def unplug_iface(manager, *args):
|
def unplug_iface(manager, *args):
|
||||||
@@ -318,7 +319,8 @@ def api_unplug_iface(client, *args):
|
|||||||
output = res.read()
|
output = res.read()
|
||||||
LOG.debug(output)
|
LOG.debug(output)
|
||||||
if res.status != 202:
|
if res.status != 202:
|
||||||
LOG.error("Failed to unplug iface from port \"%s\": %s" % (pid, output))
|
LOG.error("Failed to unplug iface from port \"%s\": %s" % (pid,
|
||||||
|
output))
|
||||||
return
|
return
|
||||||
print "Unplugged interface from port:%s on network:%s" % (pid, nid)
|
print "Unplugged interface from port:%s on network:%s" % (pid, nid)
|
||||||
|
|
||||||
|
|||||||
@@ -374,6 +374,9 @@ class FakePlugin(object):
|
|||||||
# TODO(salvatore-orlando): Validate port state in API?
|
# TODO(salvatore-orlando): Validate port state in API?
|
||||||
self._validate_port_state(port_state)
|
self._validate_port_state(port_state)
|
||||||
ports = net['net-ports']
|
ports = net['net-ports']
|
||||||
|
if len(ports.keys()) == 0:
|
||||||
|
new_port_id = 1
|
||||||
|
else:
|
||||||
new_port_id = max(ports.keys()) + 1
|
new_port_id = max(ports.keys()) + 1
|
||||||
new_port_dict = {'port-id': new_port_id,
|
new_port_dict = {'port-id': new_port_id,
|
||||||
'port-state': port_state,
|
'port-state': port_state,
|
||||||
@@ -434,3 +437,11 @@ class FakePlugin(object):
|
|||||||
# TODO(salvatore-orlando):
|
# TODO(salvatore-orlando):
|
||||||
# Should unplug on port without attachment raise an Error?
|
# Should unplug on port without attachment raise an Error?
|
||||||
port['attachment'] = None
|
port['attachment'] = None
|
||||||
|
|
||||||
|
def get_interface_details(self, tenant_id, net_id, port_id):
|
||||||
|
"""
|
||||||
|
Get Attachment details
|
||||||
|
"""
|
||||||
|
print("get_interface_details() called\n")
|
||||||
|
port = self._get_port(tenant_id, net_id, port_id)
|
||||||
|
return port["attachment"]
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
import simplejson
|
import json
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
@@ -50,10 +50,10 @@ class QuantumTest(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = MiniClient(HOST, PORT, USE_SSL)
|
self.client = MiniClient(HOST, PORT, USE_SSL)
|
||||||
|
|
||||||
def create_network(self, data):
|
def create_network(self, data, tenant_id=TENANT_ID):
|
||||||
content_type = "application/" + FORMAT
|
content_type = "application/" + FORMAT
|
||||||
body = Serializer().serialize(data, content_type)
|
body = Serializer().serialize(data, content_type)
|
||||||
res = self.client.do_request(TENANT_ID, 'POST', "/networks." + FORMAT,
|
res = self.client.do_request(tenant_id, 'POST', "/networks." + FORMAT,
|
||||||
body=body)
|
body=body)
|
||||||
self.assertEqual(res.status, 200, "bad response: %s" % res.read())
|
self.assertEqual(res.status, 200, "bad response: %s" % res.read())
|
||||||
|
|
||||||
@@ -63,21 +63,44 @@ class QuantumTest(unittest.TestCase):
|
|||||||
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
||||||
self.assertEqual(res.status, 200, "bad response: %s" % res.read())
|
self.assertEqual(res.status, 200, "bad response: %s" % res.read())
|
||||||
|
|
||||||
|
def test_getNonexistentNetwork(self):
|
||||||
|
# TODO(bgh): parse exception and make sure it is NetworkNotFound
|
||||||
|
try:
|
||||||
|
res = self.client.do_request(TENANT_ID, 'GET',
|
||||||
|
"/networks/%s.%s" % ("8675309", "xml"))
|
||||||
|
self.assertEqual(res.status, 400)
|
||||||
|
except Exception, e:
|
||||||
|
print "Caught exception: %s" % (str(e))
|
||||||
|
|
||||||
|
def test_deleteNonexistentNetwork(self):
|
||||||
|
# TODO(bgh): parse exception and make sure it is NetworkNotFound
|
||||||
|
try:
|
||||||
|
res = self.client.do_request(TENANT_ID, 'DELETE',
|
||||||
|
"/networks/%s.%s" % ("8675309", "xml"))
|
||||||
|
self.assertEqual(res.status, 400)
|
||||||
|
except Exception, e:
|
||||||
|
print "Caught exception: %s" % (str(e))
|
||||||
|
|
||||||
def test_createNetwork(self):
|
def test_createNetwork(self):
|
||||||
self.create_network(test_network1_data)
|
self.create_network(test_network1_data)
|
||||||
|
|
||||||
def test_createPort(self):
|
def test_createPort(self):
|
||||||
self.create_network(test_network1_data)
|
self.create_network(test_network1_data)
|
||||||
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
||||||
resdict = simplejson.loads(res.read())
|
resdict = json.loads(res.read())
|
||||||
for n in resdict["networks"]:
|
for n in resdict["networks"]:
|
||||||
net_id = n["id"]
|
net_id = n["id"]
|
||||||
|
|
||||||
# Step 1 - List Ports for network (should not find any)
|
# Step 1 - List Ports for network (should not find any)
|
||||||
res = self.client.do_request(TENANT_ID, 'GET',
|
res = self.client.do_request(TENANT_ID, 'GET',
|
||||||
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
||||||
self.assertEqual(res.status, 200, "Bad response: %s" % res.read())
|
|
||||||
output = res.read()
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
|
if len(output) > 0:
|
||||||
|
resdict = json.loads(output)
|
||||||
|
self.assertTrue(len(resdict["ports"]) == 0,
|
||||||
|
"Found unexpected ports: %s" % output)
|
||||||
|
else:
|
||||||
self.assertTrue(len(output) == 0,
|
self.assertTrue(len(output) == 0,
|
||||||
"Found unexpected ports: %s" % output)
|
"Found unexpected ports: %s" % output)
|
||||||
|
|
||||||
@@ -91,17 +114,59 @@ class QuantumTest(unittest.TestCase):
|
|||||||
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
||||||
output = res.read()
|
output = res.read()
|
||||||
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
resdict = simplejson.loads(output)
|
resdict = json.loads(output)
|
||||||
ids = []
|
ids = []
|
||||||
for p in resdict["ports"]:
|
for p in resdict["ports"]:
|
||||||
ids.append(p["id"])
|
ids.append(p["id"])
|
||||||
self.assertTrue(len(ids) == 1,
|
self.assertTrue(len(ids) == 1,
|
||||||
"Didn't find expected # of ports (1): %s" % ids)
|
"Didn't find expected # of ports (1): %s" % ids)
|
||||||
|
|
||||||
|
def test_getAttachment(self):
|
||||||
|
self.create_network(test_network1_data)
|
||||||
|
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
||||||
|
resdict = json.loads(res.read())
|
||||||
|
for n in resdict["networks"]:
|
||||||
|
net_id = n["id"]
|
||||||
|
|
||||||
|
# Step 1 - Create Port for network and attempt to get the
|
||||||
|
# attachment (even though there isn't one)
|
||||||
|
res = self.client.do_request(TENANT_ID, 'POST',
|
||||||
|
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
||||||
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
|
resdict = json.loads(output)
|
||||||
|
port_id = resdict["ports"]["port"]["id"]
|
||||||
|
|
||||||
|
res = self.client.do_request(TENANT_ID, 'GET',
|
||||||
|
"/networks/%s/ports/%s/attachment.%s" % (net_id, port_id,
|
||||||
|
FORMAT))
|
||||||
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
|
|
||||||
|
# Step 2 - Add an attachment
|
||||||
|
data = {'port': {'attachment-id': 'fudd'}}
|
||||||
|
content_type = "application/" + FORMAT
|
||||||
|
body = Serializer().serialize(data, content_type)
|
||||||
|
res = self.client.do_request(TENANT_ID, 'PUT',
|
||||||
|
"/networks/%s/ports/%s/attachment.%s" % (net_id, port_id,
|
||||||
|
FORMAT), body=body)
|
||||||
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 202, "Bad response: %s" % output)
|
||||||
|
|
||||||
|
# Step 3 - Fetch the attachment
|
||||||
|
res = self.client.do_request(TENANT_ID, 'GET',
|
||||||
|
"/networks/%s/ports/%s/attachment.%s" % (net_id, port_id,
|
||||||
|
FORMAT))
|
||||||
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
|
resdict = json.loads(output)
|
||||||
|
attachment = resdict["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)
|
||||||
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
||||||
resdict = simplejson.loads(res.read())
|
resdict = json.loads(res.read())
|
||||||
net_id = resdict["networks"][0]["id"]
|
net_id = resdict["networks"][0]["id"]
|
||||||
|
|
||||||
data = test_network1_data.copy()
|
data = test_network1_data.copy()
|
||||||
@@ -110,20 +175,41 @@ class QuantumTest(unittest.TestCase):
|
|||||||
body = Serializer().serialize(data, content_type)
|
body = Serializer().serialize(data, content_type)
|
||||||
res = self.client.do_request(TENANT_ID, 'PUT',
|
res = self.client.do_request(TENANT_ID, 'PUT',
|
||||||
"/networks/%s.%s" % (net_id, FORMAT), body=body)
|
"/networks/%s.%s" % (net_id, FORMAT), body=body)
|
||||||
resdict = simplejson.loads(res.read())
|
resdict = json.loads(res.read())
|
||||||
self.assertTrue(resdict["networks"]["network"]["id"] == net_id,
|
self.assertTrue(resdict["networks"]["network"]["id"] == net_id,
|
||||||
"Network_rename: renamed network has a different uuid")
|
"Network_rename: renamed network has a different uuid")
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
resdict["networks"]["network"]["name"] == "test_renamed",
|
resdict["networks"]["network"]["name"] == "test_renamed",
|
||||||
"Network rename didn't take effect")
|
"Network rename didn't take effect")
|
||||||
|
|
||||||
def delete_networks(self):
|
def test_createNetworkOnMultipleTenants(self):
|
||||||
# Remove all the networks created on the tenant
|
# Create the same network on multiple tenants
|
||||||
res = self.client.do_request(TENANT_ID, 'GET', "/networks." + FORMAT)
|
self.create_network(test_network1_data, "tenant1")
|
||||||
resdict = simplejson.loads(res.read())
|
self.create_network(test_network1_data, "tenant2")
|
||||||
|
|
||||||
|
def delete_networks(self, tenant_id=TENANT_ID):
|
||||||
|
# Remove all the networks created on the tenant (including ports and
|
||||||
|
# attachments)
|
||||||
|
res = self.client.do_request(tenant_id, 'GET',
|
||||||
|
"/networks." + FORMAT)
|
||||||
|
resdict = json.loads(res.read())
|
||||||
for n in resdict["networks"]:
|
for n in resdict["networks"]:
|
||||||
net_id = n["id"]
|
net_id = n["id"]
|
||||||
res = self.client.do_request(TENANT_ID, 'DELETE',
|
# Delete all the ports
|
||||||
|
res = self.client.do_request(tenant_id, 'GET',
|
||||||
|
"/networks/%s/ports.%s" % (net_id, FORMAT))
|
||||||
|
output = res.read()
|
||||||
|
self.assertEqual(res.status, 200, "Bad response: %s" % output)
|
||||||
|
resdict = json.loads(output)
|
||||||
|
ids = []
|
||||||
|
for p in resdict["ports"]:
|
||||||
|
res = self.client.do_request(tenant_id, 'DELETE',
|
||||||
|
"/networks/%s/ports/%s/attachment.%s" % (net_id, p["id"],
|
||||||
|
FORMAT))
|
||||||
|
res = self.client.do_request(tenant_id, 'DELETE',
|
||||||
|
"/networks/%s/ports/%s.%s" % (net_id, p["id"], FORMAT))
|
||||||
|
# Now, remove the network
|
||||||
|
res = self.client.do_request(tenant_id, 'DELETE',
|
||||||
"/networks/" + net_id + "." + FORMAT)
|
"/networks/" + net_id + "." + FORMAT)
|
||||||
self.assertEqual(res.status, 202)
|
self.assertEqual(res.status, 202)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user