Fix onos sfc's block.
authorwuwenbin2 <wuwenbin2@huawei.com>
Fri, 8 Jul 2016 07:49:06 +0000 (15:49 +0800)
committerJose Lausuch <jose.lausuch@ericsson.com>
Fri, 8 Jul 2016 10:27:23 +0000 (10:27 +0000)
Add ping check before login.

Change-Id: If93809ddf727246db453208c79a8e4ecaa288c51
Signed-off-by: wuwenbin2 <wuwenbin2@huawei.com>
testcases/Controllers/ONOS/Sfc/Sfc.py
testcases/Controllers/ONOS/Sfc/Sfc_fun.py

index 94b24e6..dd012ed 100644 (file)
@@ -94,8 +94,8 @@ class Sfc:
         logger.error("\t\t  :   Floating Ip NOT attached to VM ")
     print ("\n###########################################################\n")
     ########################################################################
-    logger.info("TestCase 3 : Configure SFC [Portair,PortGroup,\
-                 Flow classifer")
+    logger.info(
+        "TestCase 3 : Configure SFC [Portair,PortGroup,Flow classifer]")
     #########################################################################
     logger.info("\t3.1 Creation of Port Pair")
     if (Sfc_obj.createPortPair() == 201):
@@ -133,8 +133,8 @@ class Sfc:
         logger.error("\t\t  :  Flow Classifier NOT successfully Created")
     print ("\n###########################################################\n")
     ########################################################################
-    logger.info("TestCase 4 : Configure Port Chain and verify the flows are\
-                 added.")
+    logger.info(
+        "TestCase 4 : Configure Port Chain and verify flows are added")
     #########################################################################
     logger.info("\t4.1 Creation of PortChain")
     if (Sfc_obj.createPortChain() == 201):
@@ -185,8 +185,8 @@ class Sfc:
         if (Sfc_obj.deleteFlowClassifier() == 204):
             if (Sfc_obj.deletePortGroup() == 204):
                 if (Sfc_obj.deletePortPair() == 204):
-                    logger.info("\t\tSFC configuration is deleted \
-                                successfully")
+                    logger.info(
+                        "\t\tSFC configuration is deleted successfully")
                 else:
                     logger.error("\t\t  :  Port pair configuration is NOT\
                                   deleted successfully")
index 6090e88..68929bf 100644 (file)
@@ -7,6 +7,7 @@ from pexpect import pxssh
 import re
 import requests
 import time
+import os
 
 
 class Sfc_fun:
@@ -14,7 +15,7 @@ class Sfc_fun:
 
     def __init__(self):
         """Initialization of variables."""
-        self.logger = ft_logger.Logger("sfc_fun_log").getLogger()
+        self.logger = ft_logger.Logger("sfc_fun").getLogger()
         self.osver = "v2.0"
         self.token_id = 0
         self.net_id = 0
@@ -303,7 +304,7 @@ class Sfc_fun:
             response = requests.post(url, headers=headers,  data=data)
             if (response.status_code == 201):
                 print ("\t\t\t\tCreation of Port Pair PP"+str(p) +
-                       "is successful")
+                       " is successful")
             else:
                 return(response.status_code)
 
@@ -617,8 +618,24 @@ class Sfc_fun:
                 self.logger.info("\tPacket not received in Instance")
                 queue1.put("0")
 
-        if (self.value == 0):
-            time.sleep(10)
+        def ping(ip, timeout=300):
+            while True:
+                time.sleep(1)
+                self.logger.debug("Pinging %s. Waiting for response..." % ip)
+                response = os.system("ping -c 1 " + ip + " >/dev/null 2>&1")
+                if response == 0:
+                    self.logger.info("Ping " + ip + " detected!")
+                    return 0
+
+                elif timeout == 0:
+                    self.logger.info("Ping " + ip + " timeout reached.")
+                    return 1
+                timeout -= 1
+
+        result0 = ping(self.vm_public_ip[0])
+        result1 = ping(self.vm_public_ip[1])
+        if result0 == 0 and result1 == 0:
+            time.sleep(300)
             queue1 = Queue()
             p1 = Process(target=vm1,  args=(queue1, ))
             p1.start()
@@ -797,7 +814,7 @@ class Sfc_fun:
         else:
             return(response.status_code)
 
-        print ("\n\t\t Deletion of Floating ip")
+        print ("\n\t\tDeletion of Floating ip")
         for ip_num in range(0, 2):
             url = 'http://'+self.os_hostname+':9696/'+self.osver + \
                   '/floatingips/'+self.vm_public_id[ip_num]