Ejemplo n.º 1
0
 def main(self):
     keys = self.config.keys()
     if 'docker_save_path' in keys:
         save_path = self.config['docker_save_path']
     else:
         save_path = self.curr_path
     if 'docker_images' in keys:
         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 = 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
Ejemplo n.º 2
0
def clean_results_dir():
    result_path = dt_cfg.dovetail_config['result_dir']
    if os.path.exists(result_path):
        if os.path.isdir(result_path):
            cmd = 'rm -rf %s/*' % (result_path)
            dt_utils.exec_cmd(cmd, exit_on_error=False, exec_msg_on=False)
        else:
            print('result_dir in dovetail_config.yml is not a directory.')
            raise SystemExit(EXIT_RUN_FAILED)
Ejemplo n.º 3
0
    def run(args_str):
        options = ''
        if args_str:
            options = options + args_str

        repo_dir = os.path.abspath(
            os.path.join(os.path.dirname(__file__),
                         os.pardir, os.pardir))

        cmd = ("python3 %s/run.py"
               " %s" % (repo_dir, options))
        dt_utils.exec_cmd(cmd, exit_on_error=True,
                          exec_msg_on=False, info=True)
Ejemplo n.º 4
0
    def main(self):
        keys = self.config.keys()
        if 'docker_save_path' in keys:
            save_path = self.config['docker_save_path']
        else:
            save_path = self.curr_path
        print "save files to path %s" % save_path
        if 'docker_images' in keys:
            for key, value in self.config['docker_images'].items():
                if value is not None:
                    tag = str(self.config['docker_images'][key]['tag'])
                    if 'domain' in self.config['docker_images'][key]:
                        domain = self.config['docker_images'][key]['domain']
                        image_name = ''.join([domain, '/', key, ':', tag])
                    else:
                        image_name = ''.join([key, ':', tag])
                    cmd = 'sudo docker pull %s' % image_name
                    dt_utils.exec_cmd(cmd)
                    if not os.path.exists(save_path):
                        os.makedirs(save_path)
                    StoreName = self.config['docker_images'][key]['store_name']
                    image_save_path = ''.join([save_path, StoreName])
                    cmd = 'sudo docker save -o %s %s' % \
                        (image_save_path, image_name)
                    dt_utils.exec_cmd(cmd)
                    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)
Ejemplo n.º 5
0
    def run(self):
        testcase_passed = 'PASS'
        result = {'pass': '******', 'results': []}
        cmds = self.testcase.pre_condition()
        for cmd in cmds:
            ret, msg = dt_utils.exec_cmd(cmd, self.logger)
            result['results'].append((cmd, ret, msg))
            if ret != 0:
                self.logger.error('Failed to execute all pre_condition cmds.')
                break

        if not self.testcase.prepare_cmd(self.type):
            self.logger.error('Failed to prepare cmd: {}'.format(
                self.testcase.name()))
        else:
            for cmd in self.testcase.cmds:
                ret, msg = dt_utils.exec_cmd(cmd, self.logger)
                result['results'].append((cmd, ret, msg))
                if ret != 0:
                    testcase_passed = 'FAIL'

        result['pass'] = testcase_passed

        cmds = self.testcase.post_condition()
        for cmd in cmds:
            ret, msg = dt_utils.exec_cmd(cmd, self.logger)
            result['results'].append((cmd, ret, msg))

        result_filename = os.path.join(dt_cfg.dovetail_config['result_dir'],
                                       self.testcase.name()) + '.out'
        self.logger.debug('Save result: {}'.format(result_filename))
        try:
            with open(result_filename, 'w') as f:
                f.write(json.dumps(result))
        except Exception as e:
            self.logger.exception('Failed to write result into file: {}, '
                                  'exception: {}'.format(result_filename, e))
Ejemplo n.º 6
0
def copy_patch_files(logger):
    patch_set_path = dt_cfg.dovetail_config['patch_dir']
    if not os.path.isdir(patch_set_path):
        os.makedirs(patch_set_path)
    cmd = 'cp -a -r %s/* %s' % (constants.PATCH_PATH, patch_set_path)
    dt_utils.exec_cmd(cmd, logger, exit_on_error=False)
Ejemplo n.º 7
0
def copy_userconfig_files(logger):
    userconfig_path = dt_cfg.dovetail_config['userconfig_dir']
    if not os.path.isdir(userconfig_path):
        os.makedirs(userconfig_path)
    cmd = 'cp -r %s/* %s' % (constants.USERCONF_PATH, userconfig_path)
    dt_utils.exec_cmd(cmd, logger, exit_on_error=False)