summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2018-02-26 19:40:43 +0100
committerCédric Ollivier <cedric.ollivier@orange.com>2018-02-26 20:43:15 +0100
commitfe077e8bbd41907db20765174a2bff388a1321a3 (patch)
tree63c7902d57c5746ccabf14f61d432165f4cec8b9
parent016b6d88f287e5d709ef1e796b9d71a545d6c809 (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. The next functions will be considered as part of Functest framework (then it must be well covered and documented): - ft_utils.execute_command_raise() - ft_utils.execute_command() - ft_utils.get_parameter_from_yaml() Change-Id: I076c6ced430df8387de8eaeac6f3a94d93201b19 Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--sdnvpn/lib/openstack_utils.py25
-rw-r--r--sdnvpn/test/functest/testcase_3.py3
2 files changed, 22 insertions, 6 deletions
diff --git a/sdnvpn/lib/openstack_utils.py b/sdnvpn/lib/openstack_utils.py
index 98da48b..49771d5 100644
--- a/sdnvpn/lib/openstack_utils.py
+++ b/sdnvpn/lib/openstack_utils.py
@@ -10,8 +10,10 @@
import logging
import os.path
+import shutil
import sys
import time
+import urllib
from keystoneauth1 import loading
from keystoneauth1 import session
@@ -22,8 +24,8 @@ from novaclient import client as novaclient
from keystoneclient import client as keystoneclient
from neutronclient.neutron import client as neutronclient
+from functest.utils import config
from functest.utils import env
-import functest.utils.functest_utils as ft_utils
logger = logging.getLogger(__name__)
@@ -224,13 +226,29 @@ def get_heat_client(other_creds={}):
return heatclient.Client(get_heat_client_version(), session=sess)
+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_and_add_image_on_glance(glance, image_name, image_url, data_dir):
try:
dest_path = data_dir
if not os.path.exists(dest_path):
os.makedirs(dest_path)
file_name = image_url.rsplit('/')[-1]
- if not ft_utils.download_url(image_url, dest_path):
+ if not download_url(image_url, dest_path):
return False
except Exception:
raise Exception("Impossible to download image from {}".format(
@@ -343,8 +361,7 @@ def create_flavor(nova_client, flavor_name, ram, disk, vcpus, public=True):
flavor = nova_client.flavors.create(
flavor_name, ram, vcpus, disk, is_public=public)
try:
- extra_specs = ft_utils.get_functest_config(
- 'general.flavor_extra_specs')
+ extra_specs = getattr(config.CONF, 'flavor_extra_specs')
flavor.set_keys(extra_specs)
except ValueError:
# flavor extra specs are not configured, therefore skip the update
diff --git a/sdnvpn/test/functest/testcase_3.py b/sdnvpn/test/functest/testcase_3.py
index 6e7cbae..54ae122 100644
--- a/sdnvpn/test/functest/testcase_3.py
+++ b/sdnvpn/test/functest/testcase_3.py
@@ -16,7 +16,6 @@ import logging
import os
import sys
-from functest.utils import functest_utils as ft_utils
from sdnvpn.lib import quagga
from sdnvpn.lib import openstack_utils as os_utils
from sdnvpn.lib import utils as test_utils
@@ -139,7 +138,7 @@ def main():
# Taken from the sfc tests
if not os.path.isfile(COMMON_CONFIG.ubuntu_image_path):
logger.info("Downloading image")
- ft_utils.download_url(
+ os_utils.download_url(
"http://artifacts.opnfv.org/sdnvpn/"
"ubuntu-16.04-server-cloudimg-amd64-disk1.img",
"/home/opnfv/functest/data/")