示例#1
0
    def test_output_as_generator(self):
        contents = 'this is the simulated file contents'

        session = flexmock()
        expectation = session.should_receive('downloadTaskOutput')

        for chunk in contents:
            expectation = expectation.and_return(chunk)
        # Empty content to simulate end of stream.
        expectation.and_return('')

        streamer = koji_util.stream_task_output(session, 123, 'file.ext')
        assert ''.join(list(streamer)) == contents
    def download_filesystem(self, task_id, filesystem_regex):
        found = self.find_filesystem(task_id, filesystem_regex)
        if found is None:
            raise RuntimeError('Filesystem not found as task output: {}'
                               .format(filesystem_regex.pattern))
        task_id, file_name = found

        self.log.info('Streaming filesystem: %s from task ID: %s',
                      file_name, task_id)

        contents = stream_task_output(self.session, task_id, file_name,
                                      self.blocksize)

        return contents
    def download_filesystem(self, task_id, filesystem_regex, build_dir: BuildDir):
        found = self.find_filesystem(task_id, filesystem_regex)
        if found is None:
            raise RuntimeError('Filesystem not found as task output: {}'
                               .format(filesystem_regex.pattern))
        task_id, file_name = found

        self.log.info('Downloading filesystem: %s from task ID: %s',
                      file_name, task_id)

        file_path = build_dir.path / file_name
        if file_path.exists():
            raise RuntimeError(f'Filesystem {file_name} already exists at {file_path}')

        with open(file_path, 'w') as f:
            for chunk in stream_task_output(self.session, task_id, file_name, self.blocksize):
                f.write(chunk)

        return file_name