Repo structure modification
[functest.git] / functest / opnfv_tests / features / sfc / prepare_odl_sfc.py
1 #
2 # Author: George Paraskevopoulos (geopar@intracom-telecom.com)
3 #         Manuel Buil (manuel.buil@ericsson.com)
4 # Prepares the controller and the compute nodes for the odl-sfc testcase
5 #
6 #
7 # All rights reserved. This program and the accompanying materials
8 # are made available under the terms of the Apache License, Version 2.0
9 # which accompanies this distribution, and is available at
10 # http://www.apache.org/licenses/LICENSE-2.0
11 #
12
13 import os
14 import sys
15 import subprocess
16 import paramiko
17 import functest.utils.functest_logger as ft_logger
18
19 logger = ft_logger.Logger("ODL_SFC").getLogger()
20
21 try:
22     FUNCTEST_REPO_DIR = os.environ['FUNCTEST_REPO_DIR']
23 except:
24     logger.debug("FUNCTEST_REPO_DIR does not exist!!!!!")
25
26 FUNCTEST_REPO_DIR = "/home/opnfv/repos/functest"
27
28 try:
29     INSTALLER_IP = os.environ['INSTALLER_IP']
30
31 except:
32     logger.debug("INSTALLER_IP does not exist. We create 10.20.0.2")
33     INSTALLER_IP = "10.20.0.2"
34
35 os.environ['ODL_SFC_LOG'] = "/home/opnfv/functest/results/odl-sfc.log"
36 os.environ['ODL_SFC_DIR'] = FUNCTEST_REPO_DIR + "/opnfv_tests/features/sfc"
37
38 command = os.environ['ODL_SFC_DIR'] + ("/server_presetup_CI.bash | "
39                                        "tee -a ${ODL_SFC_LOG} "
40                                        "1>/dev/null 2>&1")
41
42 output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
43
44 # This code is for debugging purposes
45 # for line in iter(output.stdout.readline, ''):
46 #    i = line.rstrip()
47 #    print(i)
48
49 # Make sure the process is finished before checking the returncode
50 if not output.poll():
51     output.wait()
52
53 # Get return value
54 if output.returncode:
55     print("The presetup of the server did not work")
56     sys.exit(output.returncode)
57
58 logger.info("The presetup of the server worked ")
59
60 ssh_options = "-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
61 ssh = paramiko.SSHClient()
62 ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
63
64 try:
65     ssh.connect(INSTALLER_IP, username="root",
66                 password="r00tme", timeout=2)
67     command = "fuel node | grep compute | awk '{print $10}'"
68     logger.info("Executing ssh to collect the compute IPs")
69     (stdin, stdout, stderr) = ssh.exec_command(command)
70 except:
71     logger.debug("Something went wrong in the ssh to collect the computes IP")
72
73 output = stdout.readlines()
74 for ip in output:
75     command = os.environ['ODL_SFC_DIR'] + ("/compute_presetup_CI.bash "
76                                            "" + ip.rstrip() + "| tee -a "
77                                            "${ODL_SFC_LOG} 1>/dev/null 2>&1")
78
79     output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)
80
81 # This code is for debugging purposes
82 #    for line in iter(output.stdout.readline, ''):
83 #        print(line)
84 #        sys.stdout.flush()
85
86     output.stdout.close()
87
88     if not (output.poll()):
89         output.wait()
90
91     # Get return value
92     if output.returncode:
93         print("The compute config did not work on compute %s" % ip)
94         sys.exit(output.returncode)
95
96 sys.exit(0)