From 41135da626fe2c2813e58f52928b4e5ba4e47bf7 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Mon, 26 Feb 2018 19:13:41 +0100 Subject: Stop relying on internal Functest utils MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It switches from functest_utils.get_functest_config() to config.CONF(). download_url is now hosted in sfc as it's unused by Functest. ft_utils.get_parameter_from_yaml() will be considered as part of Functest framework (then it must be well covered and documented). Change-Id: I3014d90dba53422020ae85a2815c5bf8c0dcf34c Signed-off-by: Cédric Ollivier --- sfc/lib/config.py | 3 +-- sfc/lib/test_utils.py | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/sfc/lib/config.py b/sfc/lib/config.py index 28541ce3..6ced2763 100644 --- a/sfc/lib/config.py +++ b/sfc/lib/config.py @@ -89,8 +89,7 @@ class CommonConfig(object): "defaults.image_format", self.config_file) self.image_url = ft_utils.get_parameter_from_yaml( "defaults.image_url", self.config_file) - self.dir_functest_data = ft_utils.get_functest_config( - "general.dir.functest_data") + self.dir_functest_data = getattr(config.CONF, 'dir_functest_data') class TestcaseConfig(object): diff --git a/sfc/lib/test_utils.py b/sfc/lib/test_utils.py index a04f1e24..c495aa11 100644 --- a/sfc/lib/test_utils.py +++ b/sfc/lib/test_utils.py @@ -10,9 +10,10 @@ import os import subprocess import time +import shutil +import urllib import logging -import functest.utils.functest_utils as ft_utils logger = logging.getLogger(__name__) @@ -51,13 +52,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") -- cgit 1.2.3-korg