コード例 #1
0
 def add_manifest(self, name, ref, manifest):
     repo = self.get_repo(name)
     digest = sha256sum(manifest, abbrev_len=10, prefix=True)
     repo['manifests'][digest] = manifest
     if ref.startswith('sha256:'):
         assert ref == digest
     else:
         repo['tags'][ref] = digest
     return digest
コード例 #2
0
def test_inject_repos(configure_ca_bundle, inherited_user, repos,
                      dockerfile_content, expected_final_dockerfile, tmpdir):
    dockerfile = tmpdir.join('Dockerfile')
    dockerfile.write_text(dockerfile_content, encoding='utf8')

    tasker, workflow = prepare(str(dockerfile), inherited_user)

    config = {
        'version': 1,
        # Ensure the AddYumRepoByUrlPlugin plugin is able to run
        'yum_repo_allowed_domains': ['odcs.example.com', 'repos.host'],
    }
    if configure_ca_bundle:
        config['builder_ca_bundle'] = BUILDER_CA_BUNDLE
    workflow.plugin_workspace[ReactorConfigPlugin.key] = {
        WORKSPACE_CONF_KEY: ReactorConfig(config)
    }

    # Ensure the ca_bundle PEM file is copied into build context
    flexmock(shutil).should_receive('copyfile').with_args(
        BUILDER_CA_BUNDLE,
        str(tmpdir.join(CA_BUNDLE_PEM)),
    )

    for repofile_url, repofile_content, _ in repos:
        responses.add(responses.GET, repofile_url, body=repofile_content)

    PreBuildPluginsRunner(tasker, workflow, [
        {
            'name': AddYumRepoByUrlPlugin.key,
            'args': {
                'repourls': [url for url, _, _ in repos]
            },
        },
        {
            'name': InjectYumRepoPlugin.key,
            'args': {},
        },
    ]).run()

    # Ensure Dockerfile is update correctly
    hashes = [
        sha256sum(repofile_url, abbrev_len=5) for repofile_url, _, _ in repos
    ]
    expected = expected_final_dockerfile.format(*hashes)
    assert expected == df_parser(str(dockerfile)).content

    # Ensure the repofile is updated correctly as well
    for repofile_url, _, expected_final_repofile in repos:
        yum_repo = YumRepo(repofile_url)
        updated_repos = tmpdir.join(RELATIVE_REPOS_PATH,
                                    yum_repo.filename).read_text('utf-8')
        assert expected_final_repofile == updated_repos
コード例 #3
0
def test_inject_repos(configure_ca_bundle, inherited_user, include_koji_repo,
                      repos, dockerfile_content, expected_final_dockerfile,
                      workflow, build_dir):
    platforms = ['x86_64', 'ppc64le']
    yum_repourls = {}
    for platform in platforms:
        yum_repourls[platform] = [url for url, _, _ in repos]
    workflow = prepare(workflow,
                       build_dir,
                       inherited_user,
                       dockerfile_content,
                       include_koji_repo=include_koji_repo,
                       platforms=platforms,
                       yum_repourls=yum_repourls)
    workflow.conf.conf['yum_repo_allowed_domains'] = [
        'odcs.example.com', 'repos.host'
    ]
    if configure_ca_bundle:
        workflow.conf.conf['builder_ca_bundle'] = BUILDER_CA_BUNDLE

    # Ensure the ca_bundle PEM file is copied into build context
    flexmock(shutil).should_receive('copyfile').with_args(
        BUILDER_CA_BUNDLE,
        (workflow.build_dir.any_platform.path / CA_BUNDLE_PEM))
    flexmock(shutil).should_receive('copyfile').with_args(
        BUILDER_CA_BUNDLE,
        (workflow.build_dir.path / 'x86_64' / CA_BUNDLE_PEM))

    for repofile_url, repofile_content, _ in repos:
        responses.add(responses.GET, repofile_url, body=repofile_content)

    PreBuildPluginsRunner(workflow, [
        {
            'name': InjectYumReposPlugin.key,
            'args': {
                'target': KOJI_TARGET
            },
        },
    ]).run()

    # Ensure Dockerfile is update correctly
    hashes = [
        sha256sum(repofile_url, abbrev_len=5) for repofile_url, _, _ in repos
    ]
    expected = expected_final_dockerfile.format(*hashes)
    assert expected == workflow.build_dir.any_platform.dockerfile.content

    # Ensure the repofile is updated correctly as well
    for repofile_url, _, expected_final_repofile in repos:
        yum_repo = YumRepo(repofile_url)
        repos_path = workflow.build_dir.any_platform.path / RELATIVE_REPOS_PATH / yum_repo.filename
        updated_repos = repos_path.read_text('utf-8')
        assert expected_final_repofile == updated_repos
コード例 #4
0
    def filename(self):
        '''Returns the filename to be used for saving the repo file.

        The filename is derived from the repo url by injecting a suffix
        after the name and before the file extension. This suffix is a
        partial sha256 checksum of the full repourl. This avoids multiple
        repos from being written to the same file.
        '''
        urlpath = unquote(urlsplit(self.repourl, allow_fragments=False).path)
        basename = os.path.basename(urlpath)
        if not basename.endswith(REPO_SUFFIX):
            basename += REPO_SUFFIX
        if self.add_hash:
            suffix = '-' + sha256sum(self.repourl, abbrev_len=5)
        else:
            suffix = ''
        final_name = suffix.join(os.path.splitext(basename))
        return final_name
コード例 #5
0
 def checksum(self):
     with open(self.path, 'r') as f:
         return sha256sum(f.read())