Stop relying on internal Functest utils 83/52683/2
authorCédric Ollivier <cedric.ollivier@orange.com>
Mon, 26 Feb 2018 18:40:43 +0000 (19:40 +0100)
committerCédric Ollivier <cedric.ollivier@orange.com>
Mon, 26 Feb 2018 19:43:15 +0000 (20:43 +0100)
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>
sdnvpn/lib/openstack_utils.py
sdnvpn/test/functest/testcase_3.py

index 98da48b..49771d5 100644 (file)
 
 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
index 6e7cbae..54ae122 100644 (file)
@@ -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/")