Example #1
0
    def test_put_object_from_tree(self):
        """Test the `put_object_from_tree` method."""
        basepath = ''
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join('subdir', 'a.txt')
        content = self.get_file_content(key)
        self.assertEqual(node.get_object_content(key), content)

        basepath = 'base'
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join(basepath, 'subdir', 'a.txt')
        content = self.get_file_content(os.path.join('subdir', 'a.txt'))
        self.assertEqual(node.get_object_content(key), content)

        basepath = 'base/further/nested'
        node = Node()
        node.put_object_from_tree(self.tempdir, basepath)

        key = os.path.join(basepath, 'subdir', 'a.txt')
        content = self.get_file_content(os.path.join('subdir', 'a.txt'))
        self.assertEqual(node.get_object_content(key), content)
Example #2
0
    def test_put_object_from_file(self):
        """Test the `put_object_from_file` method."""
        key = os.path.join('subdir', 'a.txt')
        filepath = os.path.join(self.tempdir, key)
        content = self.get_file_content(key)

        node = Node()
        node.put_object_from_file(filepath, key)
        self.assertEqual(node.get_object_content(key), content)
Example #3
0
    def test_put_object_from_filelike(self):
        """Test the `put_object_from_filelike` method."""
        key = os.path.join('subdir', 'a.txt')
        filepath = os.path.join(self.tempdir, key)
        content = self.get_file_content(key)

        with io.open(filepath, 'r') as handle:
            node = Node()
            node.put_object_from_filelike(handle, key)
            self.assertEqual(node.get_object_content(key), content)

        key = os.path.join('subdir', 'nested', 'deep.txt')
        filepath = os.path.join(self.tempdir, key)
        content = self.get_file_content(key)

        with io.open(filepath, 'r') as handle:
            node = Node()
            node.put_object_from_filelike(handle, key)
            self.assertEqual(node.get_object_content(key), content)
Example #4
0
    def parse_scheduler_output(self,
                               retrieved: orm.Node) -> Optional[ExitCode]:
        """Parse the output of the scheduler if that functionality has been implemented for the plugin."""
        scheduler = self.node.computer.get_scheduler()
        filename_stderr = self.node.get_option('scheduler_stderr')
        filename_stdout = self.node.get_option('scheduler_stdout')

        detailed_job_info = self.node.get_detailed_job_info()

        if detailed_job_info is None:
            self.logger.info(
                'could not parse scheduler output: the `detailed_job_info` attribute is missing'
            )
        elif detailed_job_info.get('retval', 0) != 0:
            self.logger.info(
                'could not parse scheduler output: return value of `detailed_job_info` is non-zero'
            )
            detailed_job_info = None

        try:
            scheduler_stderr = retrieved.get_object_content(filename_stderr)
        except FileNotFoundError:
            scheduler_stderr = None
            self.logger.warning(
                f'could not parse scheduler output: the `{filename_stderr}` file is missing'
            )

        try:
            scheduler_stdout = retrieved.get_object_content(filename_stdout)
        except FileNotFoundError:
            scheduler_stdout = None
            self.logger.warning(
                f'could not parse scheduler output: the `{filename_stdout}` file is missing'
            )

        # Only attempt to call the scheduler parser if all three resources of information are available
        if any(entry is None for entry in
               [detailed_job_info, scheduler_stderr, scheduler_stdout]):
            return None

        try:
            exit_code = scheduler.parse_output(detailed_job_info,
                                               scheduler_stdout,
                                               scheduler_stderr)
        except exceptions.FeatureNotAvailable:
            self.logger.info(
                f'`{scheduler.__class__.__name__}` does not implement scheduler output parsing'
            )
            return None
        except Exception as exception:  # pylint: disable=broad-except
            self.logger.error(
                f'the `parse_output` method of the scheduler excepted: {exception}'
            )
            return None

        if exit_code is not None and not isinstance(exit_code, ExitCode):
            args = (scheduler.__class__.__name__, type(exit_code))
            raise ValueError(
                '`{}.parse_output` returned neither an `ExitCode` nor None, but: {}'
                .format(*args))

        return exit_code