Beispiel #1
0
 def launch_udocker_container(self):
     """Launches the udocker container.
     If the execution time of the container exceeds the defined execution time,
     the container is killed and a warning is raised."""
     remaining_seconds = self.lambda_instance.get_remaining_time_in_seconds(
     )
     get_logger().info(
         "Executing udocker container. Timeout set to '%d' seconds",
         remaining_seconds)
     get_logger().debug("Udocker command: '%s'", self.cont_cmd)
     with open(self._CONTAINER_OUTPUT_FILE, "wb") as out:
         with subprocess.Popen(self.cont_cmd,
                               stderr=subprocess.STDOUT,
                               stdout=out,
                               start_new_session=True) as process:
             try:
                 process.wait(timeout=remaining_seconds)
             except subprocess.TimeoutExpired:
                 get_logger().info("Stopping process '%s'", process)
                 process.kill()
                 raise ContainerTimeoutExpiredWarning()
     udocker_output = b''
     if FileUtils.is_file(self._CONTAINER_OUTPUT_FILE):
         udocker_output = FileUtils.read_file(self._CONTAINER_OUTPUT_FILE,
                                              file_mode="rb")
     return udocker_output
 def _get_script_path(self):
     script_path = None
     if SysUtils.is_var_in_env('SCRIPT'):
         script_path = SysUtils.join_paths(
             SysUtils.get_env_var("TMP_INPUT_DIR"), self._SCRIPT_FILE_NAME)
         script_content = StrUtils.base64_to_str(
             SysUtils.get_env_var('SCRIPT'))
         FileUtils.create_file_with_content(script_path, script_content)
         get_logger().info("Script file created in '%s'", script_path)
     elif FileUtils.is_file(self._OSCAR_SCRIPT_PATH):
         script_path = self._OSCAR_SCRIPT_PATH
     return script_path
Beispiel #3
0
    def _parse_input(self):
        """Download input data from storage provider
        or save data from POST request.

        A function can have information from several storage providers
        but one event always represents only one file (so far), so only
        one provider is going to be used for each event received.
        """
        input_file_path = self.stg_config.download_input(self.parsed_event,
                                                         self.input_tmp_dir.name)
        if input_file_path and FileUtils.is_file(input_file_path):
            SysUtils.set_env_var('INPUT_FILE_PATH', input_file_path)
            get_logger().info('INPUT_FILE_PATH variable set to \'%s\'', input_file_path)
Beispiel #4
0
    def _parse_input(self):
        """Download input data from storage provider
        or save data from POST request.

        A function can have information from several storage providers
        but one event always represents only one file (so far), so only
        one provider is going to be used for each event received.
        """
        stg_prov = self._get_input_provider()
        get_logger().info("Found '%s' input provider", stg_prov.get_type())
        if stg_prov:
            get_logger().info("Downloading input file using '%s' event",
                              self.parsed_event.get_type())
            input_file_path = storage.download_input(
                stg_prov, self.parsed_event,
                SysUtils.get_env_var("TMP_INPUT_DIR"))
            if input_file_path and FileUtils.is_file(input_file_path):
                SysUtils.set_env_var("INPUT_FILE_PATH", input_file_path)
                get_logger().info("INPUT_FILE_PATH variable set to '%s'",
                                  input_file_path)
Beispiel #5
0
 def test_is_file(self, mock_os):
     FileUtils.is_file('/tmp/invented_file')
     mock_os.assert_called_with('/tmp/invented_file')