aboutsummaryrefslogtreecommitdiffstats
path: root/sfc/lib/test_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'sfc/lib/test_utils.py')
-rw-r--r--sfc/lib/test_utils.py34
1 files changed, 26 insertions, 8 deletions
diff --git a/sfc/lib/test_utils.py b/sfc/lib/test_utils.py
index 9cdc02b2..36b52755 100644
--- a/sfc/lib/test_utils.py
+++ b/sfc/lib/test_utils.py
@@ -10,10 +10,9 @@
import os
import subprocess
import time
-
+import shutil
+import urllib
import logging
-import functest.utils.functest_utils as ft_utils
-
logger = logging.getLogger(__name__)
SSH_OPTIONS = '-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
@@ -51,13 +50,29 @@ def run_cmd_remote(ip, cmd, username="root", passwd="opnfv"):
return run_cmd(ssh_cmd)
+def download_url(url, dest_path):
+ """
+ Download a file to a destination path given a URL
+ """
+ name = url.rsplit('/')[-1]
+ dest = dest_path + "/" + name
+ try:
+ response = urllib.urlopen(url)
+ except Exception:
+ return False
+
+ with open(dest, 'wb') as lfile:
+ shutil.copyfileobj(response, lfile)
+ return True
+
+
def download_image(url, image_path):
image_filename = os.path.basename(image_path)
image_url = "%s/%s" % (url, image_filename)
image_dir = os.path.dirname(image_path)
if not os.path.isfile(image_path):
logger.info("Downloading image")
- ft_utils.download_url(image_url, image_dir)
+ download_url(image_url, image_dir)
else:
logger.info("Using old image")
@@ -95,7 +110,7 @@ def start_http_server(ip, iterations_check=10):
logger.info(output)
while iterations_check > 0:
- _, output, _ = run_cmd_remote(ip, "ss -na | grep *:80")
+ _, output, _ = run_cmd_remote(ip, "netstat -pntl | grep :80")
if output:
return True
else:
@@ -107,17 +122,20 @@ def start_http_server(ip, iterations_check=10):
return False
-def start_vxlan_tool(remote_ip, interface="eth0", block=None):
+def start_vxlan_tool(remote_ip, interface="eth0", output=None, block=None):
"""
Starts vxlan_tool on a remote host.
vxlan_tool.py converts a regular Service Function into a NSH-aware SF
when the "--do forward" option is used, it decrements the NSI appropiately.
- 'block' parameters allows to specify a port where packets will be dropped.
+ 'output' allows to specify an interface through which to forward if
+ different than the input interface.
+ 'block' parameter allows to specify a port where packets will be dropped.
"""
command = "nohup python /root/vxlan_tool.py"
- options = "{do} {interface} {block_option}".format(
+ options = "{do} {interface} {output_option} {block_option}".format(
do="--do forward",
interface="--interface {}".format(interface),
+ output_option="--output {}".format(output) if output else "",
block_option="--block {}".format(block) if block is not None else "")
output_redirection = "> /dev/null 2>&1"