Merge "Update rally version"
[functest.git] / testcases / features / sfc / sfc_colorado1.py
index ef3a489..d31541d 100755 (executable)
@@ -8,6 +8,8 @@ import paramiko
 import functest.utils.functest_logger as ft_logger
 import functest.utils.functest_utils as ft_utils
 import functest.utils.openstack_utils as os_utils
+import SSHUtils as ssh_utils
+import ovs_utils
 
 parser = argparse.ArgumentParser()
 
@@ -20,6 +22,7 @@ args = parser.parse_args()
 """ logging configuration """
 logger = ft_logger.Logger("ODL_SFC").getLogger()
 
+FUNCTEST_RESULTS_DIR = '/home/opnfv/functest/results/odl-sfc'
 FUNCTEST_REPO = ft_utils.FUNCTEST_REPO
 
 HOME = os.environ['HOME'] + "/"
@@ -53,6 +56,12 @@ TACKER_CHANGECLASSI = "sfc_change_classi.bash"
 
 ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
 
+PROXY = {
+    'ip': '10.20.0.2',
+    'username': 'root',
+    'password': 'r00tme'
+}
+
 
 def check_ssh(ip):
     cmd = "sshpass -p opnfv ssh " + ssh_options + " -q " + ip + " exit"
@@ -81,6 +90,15 @@ def main():
                                stderr=subprocess.PIPE)
     ip_server = process.stdout.readline().rstrip()
 
+    comp_cmd = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
+                " 'fuel node'|grep compute|awk '{print $10}'")
+    logger.info("Executing script to get compute IPs: '%s'" % comp_cmd)
+    process = subprocess.Popen(comp_cmd,
+                               shell=True,
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE)
+    ip_computes = [ip.strip() for ip in process.stdout.readlines()]
+
     iptable_cmd1 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                     " ssh " + ip_server + " iptables -P INPUT ACCEPT ")
     iptable_cmd2 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
@@ -105,6 +123,20 @@ def main():
     neutron_client = os_utils.get_neutron_client()
     glance_client = os_utils.get_glance_client()
 
+    ovs_logger = ovs_utils.OVSLogger(
+        os.path.join(os.getcwd(), 'ovs-logs'),
+        FUNCTEST_RESULTS_DIR)
+
+    controller_clients = [ssh_utils.get_ssh_client(ip_server,
+                                                   'root',
+                                                   proxy=PROXY)]
+    compute_clients = []
+    for c_ip in ip_computes:
+        c_client = ssh_utils.get_ssh_client(c_ip,
+                                            'root',
+                                            proxy=PROXY)
+        compute_clients.append(c_client)
+
 # Download the image
 
     if not os.path.isfile(IMAGE_PATH):
@@ -142,6 +174,14 @@ def main():
     secgroups = os_utils.get_security_groups(neutron_client)
 
     for sg in secgroups:
+        os_utils.create_secgroup_rule(neutron_client, sg['id'],
+                                      'ingress', 'udp',
+                                      port_range_min=67,
+                                      port_range_max=68)
+        os_utils.create_secgroup_rule(neutron_client, sg['id'],
+                                      'egress', 'udp',
+                                      port_range_min=67,
+                                      port_range_max=68)
         os_utils.create_secgroup_rule(neutron_client, sg['id'],
                                       'ingress', 'tcp',
                                       port_range_min=22,
@@ -215,7 +255,7 @@ def main():
     # STARTING SECOND VM (server) ###
 
         # boot INTANCE
-        logger.info("Creating instance '%s'..." % INSTANCE_NAME)
+        logger.info("Creating instance '%s'..." % INSTANCE_NAME_2)
         logger.debug(
             "Configuration:\n name=%s \n flavor=%s \n image=%s \n "
             "network=%s \n" % (INSTANCE_NAME_2, FLAVOR, image_id, network_id))
@@ -391,6 +431,7 @@ def main():
 
         # SSH TO EXECUTE cmd_client
         logger.info("TEST STARTED")
+        time.sleep(70)
         try:
             ssh.connect(floatip_client, username="root",
                         password="opnfv", timeout=2)
@@ -404,8 +445,14 @@ def main():
                 i = i + 1
                 json_results.update({"Test 1: SSH Blocked": "Passed"})
             else:
-                logger.error('\033[91m' + "TEST 1 [FAILED] "
-                             "==> SSH NOT BLOCKED" + '\033[0m')
+                timestamp = time.strftime("%Y%m%d-%H%M%S")
+                error = ('\033[91m' + "TEST 1 [FAILED] "
+                         "==> SSH NOT BLOCKED" + '\033[0m')
+                logger.error(error)
+                ovs_logger.dump_ovs_logs(controller_clients,
+                                         compute_clients,
+                                         related_error=error,
+                                         timestamp=timestamp)
                 status = "FAIL"
                 json_results.update({"Test 1: SSH Blocked": "Failed"})
                 failures += 1
@@ -427,8 +474,14 @@ def main():
                 i = i + 1
                 json_results.update({"Test 2: HTTP works": "Passed"})
             else:
-                logger.error('\033[91m' + "TEST 2 [FAILED] "
-                             "==> HTTP BLOCKED" + '\033[0m')
+                timestamp = time.strftime("%Y%m%d-%H%M%S")
+                error = ('\033[91m' + "TEST 2 [FAILED] "
+                         "==> HTTP BLOCKED" + '\033[0m')
+                logger.error(error)
+                ovs_logger.dump_ovs_logs(controller_clients,
+                                         compute_clients,
+                                         related_error=error,
+                                         timestamp=timestamp)
                 status = "FAIL"
                 json_results.update({"Test 2: HTTP works": "Failed"})
                 failures += 1
@@ -460,8 +513,14 @@ def main():
                 i = i + 1
                 json_results.update({"Test 3: HTTP Blocked": "Passed"})
             else:
-                logger.error('\033[91m' + "TEST 3 [FAILED] "
-                             "==> HTTP NOT BLOCKED" + '\033[0m')
+                timestamp = time.strftime("%Y%m%d-%H%M%S")
+                error = ('\033[91m' + "TEST 3 [FAILED] "
+                         "==> HTTP NOT BLOCKED" + '\033[0m')
+                logger.error(error)
+                ovs_logger.dump_ovs_logs(controller_clients,
+                                         compute_clients,
+                                         related_error=error,
+                                         timestamp=timestamp)
                 status = "FAIL"
                 json_results.update({"Test 3: HTTP Blocked": "Failed"})
                 failures += 1
@@ -483,8 +542,14 @@ def main():
                 i = i + 1
                 json_results.update({"Test 4: SSH works": "Passed"})
             else:
-                logger.error('\033[91m' + "TEST 4 [FAILED] "
-                             "==> SSH BLOCKED" + '\033[0m')
+                timestamp = time.strftime("%Y%m%d-%H%M%S")
+                error = ('\033[91m' + "TEST 4 [FAILED] "
+                         "==> SSH BLOCKED" + '\033[0m')
+                logger.error(error)
+                ovs_logger.dump_ovs_logs(controller_clients,
+                                         compute_clients,
+                                         related_error=error,
+                                         timestamp=timestamp)
                 status = "FAIL"
                 json_results.update({"Test 4: SSH works": "Failed"})
                 failures += 1
@@ -493,6 +558,8 @@ def main():
             time.sleep(6)
             # timeout -= 1
 
+        ovs_logger.create_artifact_archive()
+
         iterator += 1
         if i == 4:
             for x in range(0, 5):
@@ -500,10 +567,15 @@ def main():
                             " :) \n" + '\033[0m')
             break
         else:
-            logger.debug("Iterating again!")
-            delete = ("bash delete.sh")
-            subprocess.call(delete, shell=True, stderr=subprocess.PIPE)
-            time.sleep(10)
+            logger.info("Iterating again!")
+            delete = "bash %s/testcases/features/sfc/delete.sh" % \
+                     (FUNCTEST_REPO)
+            try:
+                subprocess.call(delete, shell=True, stderr=subprocess.PIPE)
+                time.sleep(10)
+            except Exception, e:
+                logger.error("Problem when executing the delete.sh")
+                logger.error("Problem %s" % e)
 
     if args.report:
         stop_time = time.time()