def export_container(self, container, release_image_name: str, temp_directory: str):
     generator = container.export(chunk_size=humanfriendly.parse_size("10mb"))
     export_file = temp_directory + "/export.tar"
     with open(export_file, "wb") as file:
         still_running_logger = StillRunningLogger(
             self.logger, self.__repr__(), "Export image %s" % release_image_name)
         for chunk in generator:
             still_running_logger.log()
             file.write(chunk)
     return export_file
 def _handle_output(self, output_generator,
                    image_info: ImageInfo,
                    log_file_path: luigi.LocalTarget):
     log_file_path = log_file_path.joinpath("docker-build.log")
     with BuildLogHandler(log_file_path, self.logger, self._task_id, image_info) as log_hanlder:
         still_running_logger = StillRunningLogger(
             self.logger, self._task_id, "build image %s" % image_info.get_target_complete_name())
         for log_line in output_generator:
             still_running_logger.log()
             log_hanlder.handle_log_line(log_line)
 def _handle_output(self, output_generator, image_info: ImageInfo):
     log_file_path = self.prepate_log_file_path(image_info)
     with PushLogHandler(log_file_path, self.logger, self.__repr__(),
                         image_info) as log_hanlder:
         still_running_logger = StillRunningLogger(
             self.logger, self.__repr__(),
             "push image %s" % image_info.get_target_complete_name())
         for log_line in output_generator:
             still_running_logger.log()
             log_hanlder.handle_log_line(log_line)
 def write_image_to_file(self,
                         save_file_path: pathlib.Path,
                         image_info: ImageInfo,
                         output_generator: Generator):
     self.logger.info(
         f"Task {self.__repr__()}: Saving image {image_info.get_target_complete_name()} to file {save_file_path}")
     with save_file_path.open("wb") as file:
         still_running_logger = StillRunningLogger(
             self.logger, self.__repr__(), "save image %s" % image_info.get_target_complete_name())
         for chunk in output_generator:
             still_running_logger.log()
             file.write(chunk)
 def run_command(self, command: str, description: str, log_file_path: pathlib.Path):
     with subprocess.Popen(shlex.split(command), stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT) as process:
         with CommandLogHandler(log_file_path, self.logger, self.__repr__(), description) as log_handler:
             still_running_logger = StillRunningLogger(
                 self.logger, self.__repr__(), description)
             log_handler.handle_log_line((command + "\n").encode("utf-8"))
             for line in iter(process.stdout.readline, b''):
                 still_running_logger.log()
                 log_handler.handle_log_line(line)
             process.wait(timeout=60 * 2)
             return_code_log_line = "return code %s" % process.returncode
             log_handler.handle_log_line(return_code_log_line.encode("utf-8"), process.returncode != 0)
Beispiel #6
0
 def start_still_running_logger(self):
     # TODO use larger delay for this StillRunningLogger
     still_running_logger = StillRunningLogger(self.logger, self.__repr__(),
                                               "task")
     still_running_logger_thread = StillRunningLoggerThread(
         still_running_logger)
     still_running_logger_thread.start()
     return still_running_logger_thread
    def run_task(self):
        self.logger.info("Task %s: Running db tests of flavor %s and release %s in %s"
                         % (self.__repr__(), self.flavor_name, self.release_type, self.test_file))
        test_container = self._client.containers.get(self._test_container_info.container_name)
        log_level = "--loglevel=%s" % self.log_level
        server = "--server '%s:%s'" % (self._database_info.host, self._database_info.db_port)
        environment = "--driver=/downloads/ODBC/lib/linux/x86_64/libexaodbc-uo2214lv2.so  " \
                      "--jdbc-path /downloads/JDBC/exajdbc.jar"
        language_definition = "--script-languages '%s'" % self.language_definition
        language = ""
        if self.language is not None:
            language = "--lang %s" % self.language
        args = '"{test_file}" {server} {language_definition} {log_level} {environment} {language} {tests}' \
            .format(
            test_file=self.test_file,
            server=server,
            language_definition=language_definition,
            log_level=log_level,
            environment=environment,
            language=language,
            tests=" ".join(self.test_restrictions)
        )
        cmd = 'cd /tests/test/; python -tt %s' % args
        bash_cmd = f"""bash -c "{cmd}" """
        still_running_logger = StillRunningLogger(self.logger, self.__repr__(),
                                                  "db tests of flavor %s and release %s in %s"
                                                  % (self.flavor_name, self.release_type, self.test_file))
        thread = StillRunningLoggerThread(still_running_logger)
        thread.start()
        environment = FrozenDictToDict().convert(self.test_environment_vars)
        exit_code, output = test_container.exec_run(cmd=bash_cmd,
                                                    environment=environment)
        thread.stop()
        thread.join()
        self._log_target.parent.mkdir(parents=True, exist_ok=True)
        log_output = "command: " + bash_cmd + "\n" + \
                     "environment: " + str(environment) + "\n" + \
                     output.decode("utf-8")
        if log_config().write_log_files_to_console == WriteLogFilesToConsole.all:
            self.logger.info("Task %s: Test results for db tests of flavor %s and release %s in %s\n%s"
                             % (self.__repr__(), self.flavor_name, self.release_type, self.test_file, log_output))
        if log_config().write_log_files_to_console == WriteLogFilesToConsole.only_error and exit_code != 0:
            self.logger.error("Task %s: db tests of flavor %s and release %s in %s failed\nTest results:\n%s"
                              % (self.__repr__(), self.flavor_name, self.release_type, self.test_file, log_output))

        with self._log_target.open("w") as file:
            file.write(log_output)
        with self.output().open("w") as file:
            if exit_code == 0:
                file.write("OK")
            else:
                file.write("FAILED")
Beispiel #8
0
 def run(self):
     with ContainerLogHandler(self.log_file, self.logger, self.task_id,
                              self.description) as log_handler:
         still_running_logger = StillRunningLogger(self.logger,
                                                   self.task_id,
                                                   self.description)
         while not self.finish:
             self.current_timestamp = math.floor(time.time())
             log = self.container.logs(since=self.previous_timestamp,
                                       until=self.current_timestamp)
             if len(log) != 0:
                 still_running_logger.log()
                 log_handler.handle_log_line(log)
             log_line = log.decode("utf-8").lower()
             if "error" in log_line or "exception" in log_line or "returned with state 1" in log_line:
                 self.logger.info(
                     "Task %s: ContainerLogHandler error message, %s",
                     self.task_id, log_line)
                 self.error_message = log_line
                 self.finish = True
             self.previous_timestamp = self.current_timestamp
             self.complete_log = log_handler.get_complete_log().copy()
             time.sleep(1)
 def upload_and_wait(self, database_container: Container,
                     file_to_upload: str, log_file: str,
                     pattern_to_wait_for: str, upload_target: str):
     still_running_logger = StillRunningLogger(
         self.logger, self.__repr__(),
         "file upload of %s to %s" % (file_to_upload, upload_target))
     thread = StillRunningLoggerThread(still_running_logger)
     thread.start()
     utc_now = datetime.utcnow()
     start_exit_code, start_output = \
         self.find_pattern_in_logfile(
             database_container, log_file, pattern_to_wait_for)
     output = self.upload_file(file_to_upload=file_to_upload,
                               upload_target=upload_target)
     self.wait_for_upload(database_container=database_container,
                          pattern_to_wait_for=pattern_to_wait_for,
                          log_file=log_file,
                          start_time=utc_now,
                          start_exit_code=start_exit_code,
                          start_output=start_output)
     thread.stop()
     thread.join()
     return output