aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuan Vidal <juan.vidal.allende@ericsson.com>2017-02-14 09:48:53 +0000
committerJuan Vidal <juan.vidal.allende@ericsson.com>2017-02-15 10:50:13 +0000
commit0a71385549cb564b78cde66ecedc8064d7bfd8a0 (patch)
treefea29ebd9161d750bc6b09b3c96b008ff33dd571
parentf9a6e37b970ff3974ad9e3f0027354d04bbf3ce7 (diff)
Modify run_cmd to return exit codes as well as stdout and stderr
The old implementation of run_cmd returned different things in different situations, so the simplified new version broke some functions relying on boolean values instead of stdout. Change-Id: Ie94e529d2abfad171b9707df169925c6f5f47dfc Signed-off-by: Juan Vidal <juan.vidal.allende@ericsson.com>
-rw-r--r--sfc/lib/utils.py26
-rw-r--r--sfc/tests/functest/sfc_one_chain_two_service_functions_different_computes.py4
-rw-r--r--sfc/tests/functest/sfc_two_chains_SSH_and_HTTP.py6
3 files changed, 19 insertions, 17 deletions
diff --git a/sfc/lib/utils.py b/sfc/lib/utils.py
index 9c191462..8bd67e4f 100644
--- a/sfc/lib/utils.py
+++ b/sfc/lib/utils.py
@@ -25,22 +25,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"):
@@ -163,7 +164,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
@@ -213,7 +214,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
@@ -242,7 +243,7 @@ def netcat(s_ip, c_ip, port="80", timeout=5):
cmd = "nc -zv "
cmd = cmd + " -w %s %s %s" % (timeout, s_ip, port)
cmd = cmd + " 2>&1"
- output = run_cmd_remote(c_ip, cmd)
+ _, output, _ = run_cmd_remote(c_ip, cmd)
logger.info("%s" % output)
return output
@@ -283,7 +284,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")
@@ -349,7 +351,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")
@@ -357,4 +359,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 9661ee09..71b69dff 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
@@ -193,8 +193,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)
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..92ef9f16 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,
@@ -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,