Fix error when deleting the network in vPing test. 07/2907/3
authorjose.lausuch <jose.lausuch@ericsson.com>
Thu, 29 Oct 2015 13:38:40 +0000 (14:38 +0100)
committerjose.lausuch <jose.lausuch@ericsson.com>
Thu, 29 Oct 2015 13:43:25 +0000 (14:43 +0100)
JIRA: FUNCTEST-93

Change-Id: I9472c1183eea86b0c018059aa17b76bd2932ad8e
Signed-off-by: jose.lausuch <jose.lausuch@ericsson.com>
testcases/functest_utils.py
testcases/vPing/CI/libraries/vPing.py

index 262149b..323297f 100644 (file)
@@ -210,6 +210,13 @@ def create_neutron_port(neutron_client, name, network_id, ip):
         print "Error:", sys.exc_info()[0]
         return False
 
+def delete_neutron_port(neutron_client, port_id):
+    try:
+        neutron_client.delete_port(port_id)
+        return True
+    except:
+        print "Error:", sys.exc_info()[0]
+        return False
 
 def get_network_id(neutron_client, network_name):
     networks = neutron_client.list_networks()['networks']
index fbe134c..875ad6a 100644 (file)
@@ -202,7 +202,7 @@ def delete_glance_image(name):
     return True
 
 
-def cleanup(nova, neutron, network_dic):
+def cleanup(nova, neutron, network_dic, port_id1, port_id2):
 
     # delete both VMs
     logger.info("Cleaning up...")
@@ -241,6 +241,17 @@ def cleanup(nova, neutron, network_dic):
     subnet_id = network_dic["subnet_id"]
     router_id = network_dic["router_id"]
 
+
+    if not functest_utils.delete_neutron_port(neutron, port_id1):
+        logger.error("Unable to remove port '%s'" %port_id1)
+        return False
+    logger.debug("Port '%s' removed successfully" %port_id1)
+
+    if not functest_utils.delete_neutron_port(neutron, port_id2):
+        logger.error("Unable to remove port '%s'" %port_id2)
+        return False
+    logger.debug("Port '%s' removed successfully" %port_id2)
+
     if not functest_utils.remove_interface_router(neutron, router_id,
                                                   subnet_id):
         logger.error("Unable to remove subnet '%s' from router '%s'" % (
@@ -336,10 +347,10 @@ def main():
 
     # create VM
     logger.debug("Creating port 'vping-port-1' with IP %s..." % IP_1)
-    port_id = functest_utils.create_neutron_port(neutron_client,
+    port_id1 = functest_utils.create_neutron_port(neutron_client,
                                                  "vping-port-1", network_id,
                                                  IP_1)
-    if not port_id:
+    if not port_id1:
         logger.error("Unable to create port.")
         exit(-1)
 
@@ -352,7 +363,7 @@ def main():
         flavor=flavor,
         image=image,
         # nics = [{"net-id": network_id, "v4-fixed-ip": IP_1}]
-        nics=[{"port-id": port_id}]
+        nics=[{"port-id": port_id1}]
     )
 
     # wait until VM status is active
@@ -386,11 +397,11 @@ def main():
 
     # create VM
     logger.debug("Creating port 'vping-port-2' with IP %s..." % IP_2)
-    port_id = functest_utils.create_neutron_port(neutron_client,
+    port_id2 = functest_utils.create_neutron_port(neutron_client,
                                                  "vping-port-2", network_id,
                                                  IP_2)
 
-    if not port_id:
+    if not port_id2:
         logger.error("Unable to create port.")
         exit(-1)
     logger.info("Creating instance '%s' with IP %s..." % (NAME_VM_2, IP_2))
@@ -403,7 +414,7 @@ def main():
         flavor=flavor,
         image=image,
         # nics = [{"net-id": network_id, "v4-fixed-ip": IP_2}],
-        nics=[{"port-id": port_id}],
+        nics=[{"port-id": port_id2}],
         userdata=u
     )
 
@@ -440,7 +451,7 @@ def main():
             logger.debug("No vPing detected...")
         sec += 1
 
-    cleanup(nova_client, neutron_client, network_dic)
+    cleanup(nova_client, neutron_client, network_dic, port_id1, port_id2)
 
     test_status = "NOK"
     if EXIT_CODE == 0: