From ce776393dccaf31ad47f21b06dcf0a2ba56b4874 Mon Sep 17 00:00:00 2001 From: schillinge Date: Thu, 31 Jan 2019 08:53:39 +0100 Subject: [PATCH] Throw error if SFC ports are not found on servers This breaks the port chain creation and most likely reveals some kind of implementation error elsewhere. Change-Id: I907eb5e828f80ae5ab12de851a98f3c19c9c2d5b Signed-off-by: schillinge --- .../api/openstack/resources/port_chain.py | 11 +++----- src/emuvim/test/unittests/test_openstack.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/emuvim/api/openstack/resources/port_chain.py b/src/emuvim/api/openstack/resources/port_chain.py index 7c0a2b0..7dcd834 100644 --- a/src/emuvim/api/openstack/resources/port_chain.py +++ b/src/emuvim/api/openstack/resources/port_chain.py @@ -76,15 +76,12 @@ class PortChain(object): if port_pair.egress.name in server.port_names or port_pair.egress.id in server.port_names: server_egress = server - # TODO: Not sure, if this should throw an error if not server_ingress: - logging.warn("Neutron SFC: ingress port %s not connected." % str( - port_pair.ingress.name)) - continue + raise RuntimeError("Neutron SFC: ingress port %s not connected to any server." % + port_pair.ingress.name) if not server_egress: - logging.warn("Neutron SFC: egress port %s not connected." % str( - port_pair.egress.name)) - continue + raise RuntimeError("Neutron SFC: egress port %s not connected to any server." % + port_pair.egress.name) compute.dc.net.setChain( server_ingress.name, server_egress.name, diff --git a/src/emuvim/test/unittests/test_openstack.py b/src/emuvim/test/unittests/test_openstack.py index 7530f15..700def4 100755 --- a/src/emuvim/test/unittests/test_openstack.py +++ b/src/emuvim/test/unittests/test_openstack.py @@ -904,6 +904,34 @@ class testRestApi(ApiBaseOpenStack): p3_id = json.loads(p3_resp.content)["port"]["id"] p4_id = json.loads(p4_resp.content)["port"]["id"] + listflavorsresponse = requests.get("http://0.0.0.0:18774/v2.1/id_bla/flavors", headers=headers) + self.assertEqual(listflavorsresponse.status_code, 200) + flavors = json.loads(listflavorsresponse.content)["flavors"] + m1_tiny_flavor = filter(lambda flavor: flavor["name"] == "m1.tiny", flavors)[0] + + listimagesdetailsresponse = requests.get("http://0.0.0.0:18774/v2.1/id_bla/images/detail", headers=headers) + self.assertEqual(listimagesdetailsresponse.status_code, 200) + images = json.loads(listimagesdetailsresponse.content)["images"] + ubuntu_image = filter(lambda image: image["name"] == "ubuntu:trusty", images)[0] + + server_url = "http://0.0.0.0:18774/v2.1/id_bla/servers" + s1 = '{"server": {' \ + '"name": "s1",' \ + '"networks": [{"port": "p1"}, {"port": "p2"}],' \ + '"flavorRef": "%s",' \ + '"imageRef": "%s"' \ + '}}' % (m1_tiny_flavor["id"], ubuntu_image["id"]) + s2 = '{"server": {' \ + '"name": "s2",' \ + '"networks": [{"port": "p3"}, {"port": "p4"}],' \ + '"flavorRef": "%s",' \ + '"imageRef": "%s"' \ + '}}' % (m1_tiny_flavor["id"], ubuntu_image["id"]) + s1_response = requests.post(server_url, data=s1, headers=headers) + s2_response = requests.post(server_url, data=s2, headers=headers) + self.assertEqual(s1_response.status_code, 200) + self.assertEqual(s2_response.status_code, 200) + print('->>>>>>> test Neutron SFC Port Pair Create ->>>>>>>>>>>>>>>') print('->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>') url = "http://0.0.0.0:19696/v2.0/sfc/port_pairs" -- 2.25.1