Exemplo n.º 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
Exemplo n.º 2
0
 def test_read_binary_file(self):
     mopen = mock.mock_open(read_data='fifayfofum')
     with mock.patch('builtins.open', mopen, create=True):
         content = FileUtils.read_file('/tmp/file', file_mode='rb')
         mopen.assert_called_once_with('/tmp/file',
                                       mode='rb',
                                       encoding=None)
         self.assertEqual(content, 'fifayfofum')