sdnvpn offline support in dovetail 87/35387/4
authorMatthewLi <matthew.lijun@huawei.com>
Fri, 26 May 2017 06:35:03 +0000 (02:35 -0400)
committerMatthewLi <matthew.lijun@huawei.com>
Wed, 31 May 2017 03:02:30 +0000 (23:02 -0400)
JIRA: DOVETAIL-441

Change-Id: I709c62a36c65ef0b4da69c5508f7a8273e68dc2b
Signed-off-by: MatthewLi <matthew.lijun@huawei.com>
.gitignore
dovetail/container.py
dovetail/test_runner.py
dovetail/utils/offline/config.yaml
dovetail/utils/offline/download.py
dovetail/utils/offline/load.py

index 82b83ef..9ae58f1 100644 (file)
@@ -34,3 +34,4 @@ unittest_results.log
 docs_build/
 docs_output/
 results/
+pre_config/
index c0a925e..2d8a9e2 100644 (file)
@@ -181,6 +181,13 @@ class Container(object):
             dt_utils.exec_cmd("sudo docker ps | grep " + docker_image +
                               " | awk '{print $1}' | head -1", cls.logger)
         cls.container_list[type] = container_id
+
+        if 'sdnvpn' in str(testcase_name):
+            prefix_path = dt_cfg.dovetail_config[type]['config']['dir']
+            file_name = dt_cfg.dovetail_config['sdnvpn_image']
+            src_path = os.path.join(prefix_path, 'pre_config', file_name)
+            dest_path = '/home/opnfv/functest/images'
+            Container.pre_copy(container_id, src_path, dest_path)
         return container_id
 
     @classmethod
index cbc7e2d..6ae410c 100644 (file)
@@ -49,13 +49,22 @@ class DockerRunner(object):
         if dt_cfg.dovetail_config['offline']:
             exist = Container.check_image_exist(self.testcase.validate_type())
             if not exist:
-                self.logger.error('%s image not exist offline running',
+                self.logger.error('%s image not exist when running offline',
                                   self.testcase.validate_type())
                 return
         else:
             if not Container.pull_image(self.testcase.validate_type()):
                 self.logger.error("Failed to pull the image.")
                 return
+        # for sdnvpn, there is a need to download needed images to config_dir
+        # in dovetail_config.yml first.
+        if 'sdnvpn' in str(self.testcase.name()):
+            img_name = dt_cfg.dovetail_config['sdnvpn_image']
+            img_file = os.path.join(dt_cfg.dovetail_config['config_dir'],
+                                    img_name)
+            if not os.path.isfile(img_file):
+                self.logger.error('image %s not found', img_name)
+                return
         container_id = Container.create(self.testcase.validate_type(),
                                         self.testcase.name())
         if not container_id:
index ced4229..185686a 100644 (file)
@@ -20,3 +20,9 @@ docker_images:
     tag: 3.5
     store_name: image_mongo.docker
 docker_save_path: /home/opnfv/dovetail/results/
+
+wgets:
+    sdnvpn:
+      source_url: http://artifacts.opnfv.org/sdnvpn/ubuntu-16.04-server-cloudimg-amd64-disk1.img
+      save_path: /home/opnfv/dovetail/results/
+      file_name: ubuntu-16.04-server-cloudimg-amd64-disk1.img
index cda4ecc..3fb0cde 100755 (executable)
@@ -41,6 +41,14 @@ class download(object):
                     cmd = 'sudo chmod og+rw %s' % image_save_path
                     dt_utils.exec_cmd(cmd)
 
+        if 'wgets' in keys:
+            for key, value in self.config['wgets'].items():
+                if value is not None:
+                    wget_url = self.config['wgets'][key]['source_url']
+                    wget_path = self.config['wgets'][key]['save_path']
+                    cmd = 'sudo wget -nc %s -P %s' % (wget_url, wget_path)
+                    dt_utils.exec_cmd(cmd)
+
 
 if __name__ == '__main__':
     download = download()
index 9ddf659..c56868a 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env python
 
 import os
+import sys
 import yaml
 
 import dovetail.utils.dovetail_utils as dt_utils
@@ -22,12 +23,31 @@ class load(object):
             for key, value in self.config['docker_images'].items():
                 if value is not None:
                     name = self.config['docker_images'][key]['store_name']
-                    image_save_path = ''.join([save_path, name])
+                    image_save_path = os.path.join(save_path, name)
                     if os.path.isfile(image_save_path):
                         cmd = 'sudo docker load -i %s' % (image_save_path)
                         dt_utils.exec_cmd(cmd)
                     else:
                         print "file %s not exists" % image_save_path
+        if 'wgets' in keys:
+            for key, value in self.config['wgets'].items():
+                if value is not None:
+                    try:
+                        dovetail_home = os.environ["DOVETAIL_HOME"]
+                    except KeyError:
+                        print "env variable DOVETAIL_HOME not found"
+                        sys.exit(1)
+                    name = self.config['wgets'][key]['file_name']
+                    save_path = self.config['wgets'][key]['save_path']
+                    file_path = os.path.join(save_path, name)
+                    dest_path = os.path.join(dovetail_home, 'pre_config')
+                    if not os.path.isdir(dest_path):
+                        os.mkdir(dest_path)
+                    if os.path.isfile(file_path):
+                        cmd = 'sudo cp %s %s' % (file_path, dest_path)
+                        dt_utils.exec_cmd(cmd)
+                    else:
+                        print "file %s not exists" % file_path
 
 
 if __name__ == '__main__':