Change the directories of results and some files to DOVETAIL_HOME 25/35325/3
authorxudan <xudan16@huawei.com>
Thu, 25 May 2017 08:35:18 +0000 (04:35 -0400)
committerxudan <xudan16@huawei.com>
Fri, 26 May 2017 02:51:50 +0000 (22:51 -0400)
JIRA: DOVETAIL-438

1. Need an env variable DOVETAIL_HOME in env_config.sh
2. env_config.sh, pod.yaml and id_rsa should be put in path DOVETAIL_HOME/pre_config
3. the results will also be put in this path
4. no need to give the path of openstack credential file while running a testsuite
5. if running with the code, source the env_config.sh file before running
      source $DOVETAIL_HOME/env_config.sh
      dovetail run --testsuite <testsuite_name>
6. if running with Dovetail docker image
      docker run -it --privileged=true -e DOVETAIL_HOME=<dovetail_home_path>
             -v <dovetail_home_path>:<dovetail_home_path>
             -v /var/run/docker.sock:/var/run/docker.sock
             opnfv/dovetail:latest /bin/bash

Change-Id: Ia23078f27a34e293d0075e49c673930f41069cb6
Signed-off-by: xudan <xudan16@huawei.com>
docker/Dockerfile
dovetail/conf/cmd_config.yml
dovetail/conf/dovetail_config.yml
dovetail/conf/yardstick_config.yml
dovetail/container.py
dovetail/run.py
dovetail/test_runner.py

index 499624f..0401af7 100644 (file)
@@ -28,8 +28,6 @@ RUN \
     git config --global http.sslVerify false \
 && \
     git clone https://git.opnfv.org/dovetail ${REPOS_DIR} \
-&& \
-    mkdir -p ${REPOS_DIR}/results \
 && \
     pip install -U pip \
 && \
index da8c473..aa27f29 100644 (file)
@@ -29,13 +29,6 @@ cli:
         path:
           - 'functest/docker_tag'
         help: 'Overwrite tag for functest docker container (e.g. stable or latest)'
-      openrc:
-        flags:
-          - '--openrc'
-          - '-o'
-        path:
-          - 'openrc'
-        help: 'Openstack Credential file location'
     control:
       testsuite:
         flags:
index 934ff6a..36b3140 100644 (file)
@@ -5,7 +5,17 @@ report_dest: 'file'
 result_file: 'results.json'
 
 # OPENSTACK Credential file
-openrc: '/home/opnfv/dovetail/openrc.sh'
+env_file: 'env_config.sh'
+
+# POD info file
+pod_file: 'pod.yaml'
+
+# JUMPSERVER private key used in pod_file to login hosts
+# If use password to login hosts, there's no need to provide the private key
+pri_key: 'id_rsa'
+
+# SDNVPN offline image
+sdnvpn_image: 'ubuntu-16.04-server-cloudimg-amd64-disk1.img'
 
 COMPLIANCE_PATH: compliance/
 TESTCASE_PATH: testcase/
index ae59a9e..bc207d7 100644 (file)
@@ -16,7 +16,7 @@ yardstick:
     - "cd /home/opnfv/repos/yardstick && source tests/ci/prepare_env.sh &&
          yardstick -d task start tests/opnfv/test_cases/{{validate_testcase}}.yaml
          --output-file /home/opnfv/yardstick/results/{{validate_testcase}}.out
-         --task-args '{'file': '/home/opnfv/userconfig/pod.yaml'}'"
+         --task-args '{'file': '/home/opnfv/userconfig/pre_config/pod.yaml'}'"
   post_condition:
     - ''
   result:
index d91c184..c0a925e 100644 (file)
@@ -49,7 +49,8 @@ class Container(object):
     @classmethod
     def openrc_volume(cls, type):
         dovetail_config = dt_cfg.dovetail_config
-        dovetail_config['openrc'] = os.path.abspath(dovetail_config['openrc'])
+        dovetail_config['openrc'] = os.path.join(dovetail_config['config_dir'],
+                                                 dovetail_config['env_file'])
         if os.path.isfile(dovetail_config['openrc']):
             openrc = ' -v %s:%s ' % (dovetail_config['openrc'],
                                      dovetail_config[type]['openrc'])
@@ -106,9 +107,22 @@ class Container(object):
 
         log_vol = '-v %s:%s ' % (dovetail_config['result_dir'],
                                  dovetail_config["yardstick"]['result']['log'])
-        key_path = os.path.join(dovetail_config['userconfig_dir'], 'id_rsa')
-        key_con_path = dovetail_config["yardstick"]['result']['key_path']
-        key_vol = '-v %s:%s ' % (key_path, key_con_path)
+
+        # for yardstick, support pod.yaml configuration
+        pod_file = os.path.join(dovetail_config['config_dir'],
+                                dovetail_config['pod_file'])
+        if not os.path.isfile(pod_file):
+            cls.logger.error("File %s doesn't exist.", pod_file)
+            return None
+        key_file = os.path.join(dovetail_config['config_dir'],
+                                dovetail_config['pri_key'])
+        key_container_path = dovetail_config["yardstick"]['result']['key_path']
+        if not os.path.isfile(key_file):
+            cls.logger.debug("Key file %s is not found, maybe can use passwd "
+                             "method in %s to do HA test.", key_file, pod_file)
+            key_vol = ''
+        else:
+            key_vol = '-v %s:%s ' % (key_file, key_container_path)
         return "%s %s %s" % (envs, log_vol, key_vol)
 
     @classmethod
@@ -137,17 +151,8 @@ class Container(object):
             return None
 
         # for refstack, support user self_defined configuration
-        # for yardstick, support pod.yaml configuration
-        pod_file = os.path.join(dovetail_config['userconfig_dir'], 'pod.yaml')
-        if type.lower() == "yardstick" and not os.path.exists(pod_file):
-            cls.logger.error("File %s doesn't exist.", pod_file)
-            return None
-        key_file = os.path.join(dovetail_config['userconfig_dir'], 'id_rsa')
-        if type.lower() == "yardstick" and not os.path.exists(key_file):
-            cls.logger.debug("File %s doesn't exist.", key_file)
-            cls.logger.debug("Can just use password in %s.", pod_file)
         config_volume = \
-            ' -v %s:%s ' % (dovetail_config['userconfig_dir'],
+            ' -v %s:%s ' % (os.getenv("DOVETAIL_HOME"),
                             dovetail_config[type]['config']['dir'])
 
         hosts_config = ""
index 5b4dca8..521379d 100755 (executable)
@@ -181,23 +181,36 @@ def clean_results_dir():
 
 
 def get_result_path():
-    dovetail_home = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+    try:
+        dovetail_home = os.environ["DOVETAIL_HOME"]
+    except Exception:
+        print("ERROR: mandatory env variable 'DOVETAIL_HOME' is not found, "
+              "please set in env_config.sh and source this file before "
+              "running.")
+        return None
     result_path = os.path.join(dovetail_home, 'results')
     dt_cfg.dovetail_config['result_dir'] = result_path
+    pre_config_path = os.path.join(dovetail_home, 'pre_config')
+    dt_cfg.dovetail_config['config_dir'] = pre_config_path
+    return dovetail_home
 
 
-def get_userconfig_path():
+def copy_userconfig_files(logger):
     dovetail_home = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     userconfig_path = os.path.join(dovetail_home, 'userconfig')
-    dt_cfg.dovetail_config['userconfig_dir'] = userconfig_path
+    pre_config_path = dt_cfg.dovetail_config['config_dir']
+    if not os.path.isdir(pre_config_path):
+        os.makedirs(pre_config_path)
+    cmd = 'sudo cp -r %s/* %s' % (userconfig_path, pre_config_path)
+    dt_utils.exec_cmd(cmd, logger, exit_on_error=False)
 
 
 def main(*args, **kwargs):
     """Dovetail compliance test entry!"""
     build_tag = "daily-master-%s" % str(uuid.uuid4())
     dt_cfg.dovetail_config['build_tag'] = build_tag
-    get_result_path()
-    get_userconfig_path()
+    if not get_result_path():
+        return
     clean_results_dir()
     if kwargs['debug']:
         os.environ['DEBUG'] = 'true'
@@ -207,6 +220,7 @@ def main(*args, **kwargs):
     logger.info('Dovetail compliance: %s!', (kwargs['testsuite']))
     logger.info('================================================')
     logger.info('Build tag: %s', dt_cfg.dovetail_config['build_tag'])
+    copy_userconfig_files(logger)
     dt_utils.check_docker_version(logger)
     validate_input(kwargs, dt_cfg.dovetail_config['validate_input'], logger)
     configs = filter_config(kwargs, logger)
index 0482c2c..cbc7e2d 100644 (file)
@@ -40,7 +40,7 @@ class DockerRunner(object):
             src_path = os.path.join(file_path, src_file)
         if exist_file:
             file_path = dt_cfg.dovetail_config[self.type]['config']['dir']
-            src_path = os.path.join(file_path, exist_file)
+            src_path = os.path.join(file_path, 'pre_config', exist_file)
 
         Container.pre_copy(container_id, src_path, dest_path)
         return dest_path