aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sfc/lib/utils.py62
-rw-r--r--sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py8
-rw-r--r--sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py14
3 files changed, 41 insertions, 43 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index 67dbff22..c7247dbe 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -27,22 +27,23 @@ FUNCTEST_RESULTS_DIR = os.path.join("home", "opnfv",
def run_cmd(cmd):
- """run given command locally and return commands output if success"""
+ """
+ Run given command locally
+ Return a tuple with the return code, stdout, and stderr of the command
+ """
pipe = subprocess.Popen(cmd, shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- (output, errors) = pipe.communicate()
+ output, errors = pipe.communicate()
logger.debug("running [%s] returns: <%s> - %s "
"" % (cmd, pipe.returncode, output))
- if output:
- output = output.strip()
+
if pipe.returncode != 0 or len(errors) > 0:
logger.error('FAILED to execute {0}'.format(cmd))
logger.error(errors)
- return None
- return output
+ return pipe.returncode, output.strip(), errors.strip()
def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"):
@@ -181,7 +182,7 @@ def ping(remote, pkt_cnt=1, iface=None, retries=100, timeout=None):
cmd = ping_cmd + '|' + grep_cmd
while retries > 0:
- output = run_cmd(cmd)
+ _, output, _ = run_cmd(cmd)
if not output:
return False
@@ -231,7 +232,7 @@ def start_http_server(ip):
cmd = "\'python -m SimpleHTTPServer 80"
cmd = cmd + " > /dev/null 2>&1 &\'"
run_cmd_remote(ip, cmd)
- output = run_cmd_remote(ip, "ps aux|grep SimpleHTTPServer")
+ _, output, _ = run_cmd_remote(ip, "ps aux | grep SimpleHTTPServer")
if not output:
logger.error("Failed to start http server")
return False
@@ -255,32 +256,28 @@ def vxlan_tool_stop(sf):
run_cmd_remote(sf, cmd)
-def netcat(s_ip, c_ip, port="80", timeout=5):
- """Run netcat on a give machine, Can be VM"""
- cmd = "nc -zv "
- cmd = cmd + " -w %s %s %s" % (timeout, s_ip, port)
- cmd = cmd + " 2>&1"
- output = run_cmd_remote(c_ip, cmd)
+def netcat(source_ip, destination_ip, port, timeout=5):
+ """
+ SSH into source_ip, and check the connectivity from there to destination_ip
+ on the specified port, using the netcat command.
+ Returns 0 on successful execution, != 0 on failure
+ """
+ cmd = "nc -zv -w %s %s %s 2>&1" % (timeout, destination_ip, port)
+ rc, output, _ = run_cmd_remote(source_ip, cmd)
+ logger.info("Running netcat from [%s] - connecting to [%s] on port [%s]" %
+ (source_ip, destination_ip, port))
logger.info("%s" % output)
- return output
+ return rc
-def is_ssh_blocked(srv_prv_ip, client_ip):
- res = netcat(srv_prv_ip, client_ip, port="22")
- match = re.search("nc:.*timed out:.*", res, re.M)
- if match:
- return True
-
- return False
+def is_ssh_blocked(source_ip, destination_ip):
+ rc = netcat(source_ip, destination_ip, port="22")
+ return rc != 0
-def is_http_blocked(srv_prv_ip, client_ip):
- res = netcat(srv_prv_ip, client_ip, port="80")
- match = re.search(".* 80 port.* succeeded!", res, re.M)
- if match:
- return False
-
- return True
+def is_http_blocked(source_ip, destination_ip):
+ rc = netcat(source_ip, destination_ip, port="80")
+ return rc != 0
def capture_ovs_logs(ovs_logger, controller_clients, compute_clients, error):
@@ -301,7 +298,8 @@ def check_ssh(ips, retries=100):
logger.info("Checking SSH connectivity to the SFs with ips %s" % str(ips))
while retries and not all(check):
for index, ip in enumerate(ips):
- check[index] = run_cmd_remote(ip, "exit")
+ rc, _, _ = run_cmd_remote(ip, "exit")
+ check[index] = True if rc == 0 else False
if all(check):
logger.info("SSH connectivity to the SFs established")
@@ -367,7 +365,7 @@ def wait_for_classification_rules(ovs_logger, compute_clients, timeout=200):
def setup_compute_node(cidr, compute_nodes):
logger.info("bringing up br-int iface")
- grep_cidr_routes = ("ip route|grep -o {0} || true".format(cidr)).strip()
+ grep_cidr_routes = ("ip route | grep -o {0} || true".format(cidr)).strip()
add_cidr = "ip route add {0} br-int".format(cidr)
for compute in compute_nodes:
compute.run_cmd("ifconfig br-int up")
@@ -375,4 +373,4 @@ def setup_compute_node(cidr, compute_nodes):
logger.info("adding route %s in %s" % (cidr, compute.ip))
compute.run_cmd(add_cidr)
else:
- logger.info("route %s exists" % cidr)
+ logger.info("route %s already exists" % cidr)
diff --git a/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py b/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py
index 76c10126..8ec4dffb 100644
--- a/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py
+++ b/sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py
@@ -178,8 +178,8 @@ def main():
'protocol': 6
})
- logger.info(test_utils.run_cmd('tacker sfc-list'))
- logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+ logger.info(test_utils.run_cmd('tacker sfc-list')[1])
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list')[1])
server_ip, client_ip, sf1, sf2 = test_utils.get_floating_ips(
nova_client, neutron_client)
@@ -203,7 +203,7 @@ def main():
time.sleep(100)
logger.info("Test HTTP")
- if not test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ if not test_utils.is_http_blocked(client_ip, srv_prv_ip):
logger.info('\033[92mTEST 1 [PASSED] ==> HTTP WORKS\033[0m')
update_json_results("Test 1: HTTP works", "Passed")
else:
@@ -220,7 +220,7 @@ def main():
test_utils.vxlan_firewall(sf1, port="80")
logger.info("Test HTTP again")
- if test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ if test_utils.is_http_blocked(client_ip, srv_prv_ip):
logger.info('\033[92mTEST 2 [PASSED] ==> HTTP Blocked\033[0m')
update_json_results("Test 2: HTTP Blocked", "Passed")
else:
diff --git a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
index 58959530..4117b237 100644
--- a/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
+++ b/sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py
@@ -157,8 +157,8 @@ def main():
'protocol': 6
})
- logger.info(test_utils.run_cmd('tacker sfc-list'))
- logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+ logger.info(test_utils.run_cmd('tacker sfc-list')[1])
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list')[1])
# Start measuring the time it takes to implement the classification rules
t1 = threading.Thread(target=test_utils.wait_for_classification_rules,
@@ -190,7 +190,7 @@ def main():
t1.join()
logger.info("Test SSH")
- if test_utils.is_ssh_blocked(srv_prv_ip, client_ip):
+ if test_utils.is_ssh_blocked(client_ip, srv_prv_ip):
results.add_to_summary(2, "PASS", "SSH Blocked")
else:
error = ('\033[91mTEST 1 [FAILED] ==> SSH NOT BLOCKED\033[0m')
@@ -200,7 +200,7 @@ def main():
results.add_to_summary(2, "FAIL", "SSH Blocked")
logger.info("Test HTTP")
- if not test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ if not test_utils.is_http_blocked(client_ip, srv_prv_ip):
results.add_to_summary(2, "PASS", "HTTP works")
else:
error = ('\033[91mTEST 2 [FAILED] ==> HTTP BLOCKED\033[0m')
@@ -229,7 +229,7 @@ def main():
'protocol': 6
})
- logger.info(test_utils.run_cmd('tacker sfc-classifier-list'))
+ logger.info(test_utils.run_cmd('tacker sfc-classifier-list')[1])
# Start measuring the time it takes to implement the classification rules
t2 = threading.Thread(target=test_utils.wait_for_classification_rules,
@@ -243,7 +243,7 @@ def main():
t2.join()
logger.info("Test HTTP")
- if test_utils.is_http_blocked(srv_prv_ip, client_ip):
+ if test_utils.is_http_blocked(client_ip, srv_prv_ip):
results.add_to_summary(2, "PASS", "HTTP Blocked")
else:
error = ('\033[91mTEST 3 [FAILED] ==> HTTP WORKS\033[0m')
@@ -253,7 +253,7 @@ def main():
results.add_to_summary(2, "FAIL", "HTTP Blocked")
logger.info("Test SSH")
- if not test_utils.is_ssh_blocked(srv_prv_ip, client_ip):
+ if not test_utils.is_ssh_blocked(client_ip, srv_prv_ip):
results.add_to_summary(2, "PASS", "SSH works")
else:
error = ('\033[91mTEST 4 [FAILED] ==> SSH BLOCKED\033[0m')