Example #1
0
    def run(self):
        docker_image = Container.get_docker_image(self.testcase)
        if dt_cfg.dovetail_config['offline']:
            exist = Container.get_image_id(docker_image)
            if not exist:
                self.logger.error(
                    "{} image doesn't exist, can't run offline.".format(
                        self.testcase.validate_type()))
                return
        else:
            if not Container.pull_image(docker_image):
                self.logger.error("Failed to pull the image.")
                return

        container_id = Container.create(self.testcase.validate_type(),
                                        self.testcase.name(), docker_image)
        if not container_id:
            self.logger.error('Failed to create container.')
            return

        self.logger.debug('container id: {}'.format(container_id))

        dest_path = self.testcase.pre_copy_path("dest_path")
        src_file_name = self.testcase.pre_copy_path("src_file")
        exist_file_name = self.testcase.pre_copy_path("exist_src_file")

        if src_file_name or exist_file_name:
            if not self.pre_copy(container_id, dest_path, src_file_name,
                                 exist_file_name):
                return

        cmds = self.testcase.pre_condition()
        if cmds:
            for cmd in cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
                if ret != 0:
                    self.logger.error("Failed to exec all pre_condition cmds.")
                    break

        if not self.testcase.prepare_cmd(self.type):
            self.logger.error('Failed to prepare test case: {}'.format(
                self.testcase.name()))
        else:
            for cmd in self.testcase.cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
                if ret != 0:
                    self.logger.error(
                        'Failed to exec {}, ret: {}, msg: {}'.format(
                            cmd, ret, msg))
                    break

        cmds = self.testcase.post_condition()
        if cmds:
            for cmd in cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
        self.testcase.cleaned(True)

        if not dt_cfg.dovetail_config['noclean']:
            Container.clean(container_id, self.type)
Example #2
0
    def run(self):
        docker_image = Container.get_docker_image(self.testcase)
        if dt_cfg.dovetail_config['offline']:
            exist = Container.get_image_id(docker_image)
            if not exist:
                self.logger.error(
                    "{} image doesn't exist, can't run offline.".format(
                        self.testcase.validate_type()))
                return
        else:
            if not Container.pull_image(docker_image):
                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['images_dir'],
                                    img_name)
            if not os.path.isfile(img_file):
                self.logger.error('Image {} not found.'.format(img_name))
                return
        container_id = Container.create(self.testcase.validate_type(),
                                        self.testcase.name(), docker_image)
        if not container_id:
            self.logger.error('Failed to create container.')
            return

        self.logger.debug('container id: {}'.format(container_id))

        dest_path = self.testcase.pre_copy_path("dest_path")
        src_file_name = self.testcase.pre_copy_path("src_file")
        exist_file_name = self.testcase.pre_copy_path("exist_src_file")

        if src_file_name or exist_file_name:
            if not self.pre_copy(container_id, dest_path, src_file_name,
                                 exist_file_name):
                return

        cmds = self.testcase.pre_condition()
        if cmds:
            for cmd in cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
                if ret != 0:
                    self.logger.error("Failed to exec all pre_condition cmds.")
                    break

        if not self.testcase.prepare_cmd(self.type):
            self.logger.error('Failed to prepare test case: {}'.format(
                self.testcase.name()))
        else:
            for cmd in self.testcase.cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
                if ret != 0:
                    self.logger.error(
                        'Failed to exec {}, ret: {}, msg: {}'.format(
                            cmd, ret, msg))
                    break

        cmds = self.testcase.post_condition()
        if cmds:
            for cmd in cmds:
                ret, msg = Container.exec_cmd(container_id, cmd)
        self.testcase.cleaned(True)

        if not dt_cfg.dovetail_config['noclean']:
            Container.clean(container_id, self.type)