Add SSH connectivity check 15/22215/1
authorGeorge Paraskevopoulos <geopar@intracom-telecom.com>
Fri, 16 Sep 2016 14:04:51 +0000 (17:04 +0300)
committerJose Lausuch <jose.lausuch@ericsson.com>
Wed, 21 Sep 2016 15:02:52 +0000 (15:02 +0000)
- Remove sleep after floating IP assignment
- Add ssh connection check
- Fix iptables instruction

Change-Id: I1a7aa7f928592f148ff4bcd20167e4684f7a7dbe
Signed-off-by: George Paraskevopoulos <geopar@intracom-telecom.com>
(cherry picked from commit b9e50a3e0869cef0ff6ac11355abc2387c86839c)

testcases/features/sfc/sfc.py

index e0bf4e8..3f46026 100755 (executable)
@@ -52,6 +52,16 @@ TACKER_SCRIPT = 'sfc_tacker.bash'
 TEARDOWN_SCRIPT = "sfc_teardown.bash"
 TACKER_CHANGECLASSI = "sfc_change_classi.bash"
 
+ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
+
+
+def check_ssh(ip):
+    cmd = "sshpass -p opnfv ssh " + ssh_options + " -q " + ip + " exit"
+    success = subprocess.call(cmd, shell=True) == 0
+    if not success:
+        logger.debug("Wating for SSH connectivity in SF with IP: %s" % ip)
+    return success
+
 
 def main():
 
@@ -63,7 +73,6 @@ def main():
     start_time = time.time()
     json_results = {}
 
-    ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
     contr_cmd = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                  " 'fuel node'|grep controller|awk '{print $10}'")
     logger.info("Executing script to get ip_server: '%s'" % contr_cmd)
@@ -98,7 +107,7 @@ def main():
     subprocess.call(iptable_cmd2, shell=True, stderr=subprocess.PIPE)
 
     logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd3)
-    subprocess.call(iptable_cmd2, shell=True, stderr=subprocess.PIPE)
+    subprocess.call(iptable_cmd3, shell=True, stderr=subprocess.PIPE)
 
 # Getting the different clients
 
@@ -263,13 +272,29 @@ def main():
         logger.error('Failed to obtain IPs, cant continue, exiting')
         return
 
-    logger.info("Waiting 60 seconds for floating IP assignment")
-    for j in range(0, 6):
-        logger.debug("Test starting in {0} seconds".format(str((6 - j) * 10)))
-        time.sleep(10)
-
     logger.debug("Floating IPs for SFs: %s..." % ips)
 
+    # Check SSH connectivity to VNFs
+    r = 0
+    retries = 100
+    check = [False, False]
+
+    logger.info("Checking SSH connectivity to the SFs with ips %s" % str(ips))
+    while r < retries and not all(check):
+        try:
+            check = [check_ssh(ips[0]), check_ssh(ips[1])]
+        except Exception:
+            logger.exception("SSH check failed")
+            check = [False, False]
+        time.sleep(3)
+        r += 1
+
+    logger.info("SSH connectivity to the SFs established")
+
+    if not all(check):
+        logger.error("Cannot establish SSH connection to the SFs")
+        sys.exit(1)
+
     # SSH TO START THE VXLAN_TOOL ON SF1
     logger.info("Configuring the SFs")
     try: