예제 #1
0
    def run_module(self, request, configs, source):
        json_config = JsonParser(source)
        if request.root.source.source_file.strip():
            folder_name = "task_%s_%s" % (self.config.tmp_id,
                                          request.root.source.test_name)

            tmp_sub_folder = os.path.join(self.config.tmp_folder, folder_name)
            os.makedirs(tmp_sub_folder, exist_ok=True)

            configs["report_path"] = tmp_sub_folder

            self.result = "%s.xml" % os.path.join(tmp_sub_folder, "report")

            module_path = os.path.dirname(source)
            file_list = get_config_value('py_file', json_config.get_driver(),
                                         is_list=True)
            if not file_list:
                file_list = get_file_list(module_path)
        else:
            folder_name = "task_%s_report" % self.config.tmp_id
            tmp_sub_folder = os.path.join(self.config.tmp_folder,
                                          folder_name)
            self.result = "%s.xml" % os.path.join(tmp_sub_folder, "report")

            json_config = JsonParser(source)
            file_list = get_config_value('py_file', json_config.get_driver(),
                                         is_list=True)
        configs["test_name"] = request.root.source.test_name
        configs["execute"] = get_config_value('execute',
                                              json_config.get_driver(), False)

        os.makedirs(tmp_sub_folder, exist_ok=True)
        self._run_devicetest(configs, file_list)
    def __execute__(self, request):
        kits = []
        try:
            self.config = request.config
            setattr(self.config, "command_result", "")
            self.config.device = request.config.environment.devices[0]
            self.__init_nfs_server__(request=request)
            config_file = request.root.source.config_file
            json_config = JsonParser(config_file)
            pre_cmd = get_config_value('pre_cmd', json_config.get_driver(),
                                       False)
            execute_dir = get_config_value('execute', json_config.get_driver(),
                                           False)
            kits = get_kit_instances(json_config,
                                     request.config.resource_path,
                                     request.config.testcases_path)
            from xdevice import Scheduler
            for kit in kits:
                if not Scheduler.is_execute:
                    raise ExecuteTerminate()
                copy_list = kit.__setup__(request.config.device,
                                          request=request)

            self.file_name = request.root.source.test_name
            self.set_file_name(request, request.root.source.test_name)
            self.config.device.execute_command_with_timeout(
                command=pre_cmd, timeout=0.5)
            self.config.device.execute_command_with_timeout(
                command="cd {}".format(execute_dir), timeout=1)
            for test_bin in copy_list:
                if not test_bin.endswith(".run-test"):
                    continue
                command, _, _ = get_execute_command(test_bin, False)
                self._do_test_run(command, request)
            device_log_file = get_device_log_file(
                request.config.report_path,
                request.config.device.__get_serial__())
            with open(device_log_file, "a", encoding="UTF-8") as file_name:
                file_name.write(self.config.command_result)

        except (LiteDeviceExecuteCommandError, Exception) as exception:
            LOG.error(exception)
            self.error_message = exception
        finally:
            LOG.info("-------------finally-----------------")
            # umount the dirs already mount
            for kit in kits:
                kit.__teardown__(request.config.device)
            close_error = self.config.device.close()
            self.error_message = close_error if close_error else\
                "case results are abnormal"
            report_name = "report" if request.root.source. \
                test_name.startswith("{") else get_filename_extension(
                    request.root.source.test_name)[0]
            self.result = check_result_report(
                request.config.report_path, self.result, self.error_message,
                report_name)
예제 #3
0
 def __check_config__(self, config):
     self.remote = get_config_value('server', config, is_list=False)
     self.paths = get_config_value('paths', config)
     self.mount_list = get_config_value('mount', config, is_list=True)
     self.server = get_config_value('server',
                                    config,
                                    is_list=False,
                                    default="NfsServer")
     if not self.mount_list:
         msg = "The config for mount kit is invalid with mount:{}" \
               .format(self.mount_list)
         LOG.error(msg)
         raise TypeError(msg)
예제 #4
0
    def __check_config__(self, config):
        setattr(self.mount_kit, "mount_list",
                get_config_value('mount', config))
        setattr(
            self.mount_kit, "server",
            get_config_value('server',
                             config,
                             is_list=False,
                             default="NfsServer"))
        self.query = get_config_value('query', config, is_list=False)

        if not self.query:
            msg = "The config for query kit is invalid with query:{}" \
                  .format(self.query)
            LOG.error(msg)
            raise TypeError(msg)
예제 #5
0
 def __check_config__(self, config):
     self.timeout = str(
         int(get_config_value('timeout', config, is_list=False)) * 1000)
     self.burn_file = get_config_value('burn_file', config, is_list=False)
     burn_command = get_config_value('burn_command',
                                     config,
                                     is_list=False,
                                     default=RESET_CMD)
     self.burn_command = burn_command.replace(" ", "").split(",")
     self.paths = get_config_value('paths', config)
     if not self.timeout or not self.burn_file or not self.burn_command:
         msg = "The config for deploy kit is invalid with timeout:{} " \
               "burn_file:{} burn_command:{}".format(self.timeout,
                                                     self.burn_file,
                                                     self.burn_command)
         LOG.error(msg)
         raise TypeError(msg)
    def __execute__(self, request):
        kits = []
        try:
            self.config = request.config
            self.init_cpp_config()
            self.config.device = request.config.environment.devices[0]
            self.__init_nfs_server__(request=request)
            config_file = request.root.source.config_file
            json_config = JsonParser(config_file)
            self._get_driver_config(json_config)

            bin_file = get_config_value('execute', json_config.get_driver(),
                                        False)
            kits = get_kit_instances(json_config,
                                     request.config.resource_path,
                                     request.config.testcases_path)
            from xdevice import Scheduler
            for kit in kits:
                if not Scheduler.is_execute:
                    raise ExecuteTerminate()
                kit.__setup__(request.config.device, request=request)

            execute_dir = "/".join(bin_file.split("/")[0:-1])
            execute_bin = bin_file.split("/")[-1]

            self.config.device.execute_command_with_timeout(
                command="cd {}".format(execute_dir), timeout=1)

            command, report_path, self.has_param = get_execute_command(
                execute_bin, self.config.xml_output, execute_dir)
            self.config.device_xml_path = (self.linux_directory +
                                           report_path).replace("//", "/")
            self.set_file_name(request, command)
            self.need_download = self.is_download(
                request.config.testcases_path)
            if self.need_download and self.has_param:
                self.delete_device_xml(request, self.config.device_xml_path)
            if os.path.exists(self.result):
                os.remove(self.result)
            if request.config.testargs.get("dry_run"):
                self.config.dry_run = request.config.testargs.get(
                    "dry_run")[0].lower()
                self.dry_run(command, request.listeners)
            else:
                self.run_cpp_test(command, request)
                self.generate_device_xml(request, execute_bin)
                device_log_file = get_device_log_file(
                    request.config.report_path,
                    request.config.device.__get_serial__())
                with open(device_log_file, "a", encoding="UTF-8") as file_name:
                    file_name.write(self.config.command_result)

        except (LiteDeviceExecuteCommandError, Exception) as exception:
            LOG.exception(exception)
            self.error_message = exception
        finally:
            LOG.info("-------------finally-----------------")
            self._after_command(kits, request)
예제 #7
0
 def __check_config__(self, config):
     self.checksum_command = get_config_value("command",
                                              config,
                                              is_list=False)
     self.hash_file_name = get_config_value("hash_file_name",
                                            config,
                                            is_list=False)
     self.device_label = get_config_value("device_label",
                                          config,
                                          is_list=False)
     if not self.checksum_command or not self.hash_file_name or \
             not self.device_label:
         msg = "The config for rootfs kit is invalid : checksum :{}" \
               " hash_file_name:{} device_label:{}" \
             .format(self.checksum_command, self.hash_file_name,
                     self.device_label)
         LOG.error(msg)
         return TypeError(msg)
    def _get_driver_config(self, json_config):
        xml_output = get_config_value('xml-output',
                                      json_config.get_driver(), False)

        if isinstance(xml_output, bool):
            self.config.xml_output = xml_output
        elif str(xml_output).lower() == "true":
            self.config.xml_output = True
        else:
            self.config.xml_output = False

        rerun = get_config_value('rerun', json_config.get_driver(), False)
        if isinstance(rerun, bool):
            self.rerun = rerun
        elif str(rerun).lower() == "false":
            self.rerun = False
        else:
            self.rerun = True
예제 #9
0
def set_up_env(request, source):
    if not source.endswith(".json"):
        source = "%s.json" % source
    json_config = JsonParser(source)
    test_args = get_config_value('xml-output', json_config.get_driver())

    kits = get_kit_instances(json_config, request.config.resource_path,
                             request.config.testcases_path)
    kits_copy = copy.deepcopy(kits)
    from xdevice import Scheduler
    for kit in kits:
        if not Scheduler.is_execute:
            raise ExecuteTerminate()
        kit.__setup__(request.config.device, request=request)
    return test_args, kits, kits_copy
 def _reset_device(self, request, source):
     json_config = JsonParser(source)
     reset_cmd = []
     kit_instances = get_kit_instances(json_config,
                                       request.config.resource_path,
                                       request.config.testcases_path)
     from xdevice import Scheduler
     for (kit_instance, kit_info) in zip(kit_instances,
                                         json_config.get_kits()):
         if not isinstance(kit_instance, DeployKit):
             continue
         if not self.file_name:
             self.file_name = get_config_value(
                 'burn_file', kit_info)[0].split("\\")[-1].split(".")[0]
         reset_cmd = kit_instance.burn_command
         if not Scheduler.is_execute:
             raise ExecuteTerminate()
         setup_result = kit_instance.__setup__(
             self.config.device.local_device)
         if not setup_result:
             raise DeviceError("set_up wifiiot failed")
     reset_cmd = [int(item, 16) for item in reset_cmd]
     return reset_cmd