diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-02-26 19:13:41 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-02-26 19:17:40 +0100 |
commit | 41135da626fe2c2813e58f52928b4e5ba4e47bf7 (patch) | |
tree | e561ca5ce29b2719f78c16d55aaa88b65cc4ee5b | |
parent | f396d3993fca365a82272f3b48eca1bb9bbfc389 (diff) |
Stop relying on internal Functest utils
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 <cedric.ollivier@orange.com>
-rw-r--r-- | sfc/lib/config.py | 3 | ||||
-rw-r--r-- | 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") |