コード例 #1
0
ファイル: test_pulp.py プロジェクト: fr34k8/atomic-reactor
def test_pulp(tmpdir, check_repo_retval, should_raise):
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)
    setattr(workflow, 'tag_conf', X())
    setattr(workflow.tag_conf, 'images', [
        ImageName(repo="image-name1"),
        ImageName(namespace="prefix", repo="image-name2"),
        ImageName(repo="image-name3", tag="asd")
    ])

    # Mock dockpulp and docker
    dockpulp.Pulp = flexmock(dockpulp.Pulp)
    dockpulp.Pulp.registry = 'registry.example.com'
    (flexmock(dockpulp.imgutils).should_receive('get_metadata').with_args(
        object).and_return([{
            'id': 'foo'
        }]))
    (flexmock(dockpulp.imgutils).should_receive('get_versions').with_args(
        object).and_return({'id': '1.6.0'}))
    (flexmock(dockpulp.imgutils).should_receive('check_repo').and_return(
        check_repo_retval))
    (flexmock(dockpulp.Pulp).should_receive('set_certs').with_args(
        object, object))
    (flexmock(dockpulp.Pulp).should_receive('push_tar_to_pulp').with_args(
        object, object).and_return([1, 2, 3]))
    (flexmock(dockpulp.Pulp).should_receive('watch_tasks').with_args(list))
    mock_docker()

    os.environ['SOURCE_SECRET_PATH'] = str(tmpdir)
    with open(os.path.join(str(tmpdir), "pulp.cer"), "wt") as cer:
        cer.write("pulp certificate\n")
    with open(os.path.join(str(tmpdir), "pulp.key"), "wt") as key:
        key.write("pulp key\n")

    runner = PostBuildPluginsRunner(tasker, workflow, [{
        'name': PulpPushPlugin.key,
        'args': {
            'pulp_registry_name': 'test'
        }
    }])

    if should_raise:
        with pytest.raises(Exception) as exc:
            runner.run()

        return

    runner.run()
    assert PulpPushPlugin.key is not None
    images = [
        i.to_str() for i in workflow.postbuild_results[PulpPushPlugin.key]
    ]
    assert "registry.example.com/image-name1" in images
    assert "registry.example.com/prefix/image-name2" in images
    assert "registry.example.com/image-name3:asd" in images
コード例 #2
0
 def __init__(self):
     self.tasker = DockerTasker()
     self.base_image = ImageName(repo='fedora', tag='26')
     self.original_base_image = ImageName(repo='fedora', tag='26')
     self.base_from_scratch = False
     self.custom_base_image = False
     self.image_id = 'image_id'
     self.image = 'image'
     self.df_path = 'df_path'
     self.df_dir = 'df_dir'
コード例 #3
0
 def __init__(self):
     self.tasker = flexmock()
     self.base_image = ImageName(repo='Fedora', tag='22')
     self.original_base_image = ImageName(repo='Fedora', tag='22')
     self.parent_images = {
     }  # don't want to handle inspections in most tests
     self.image_id = 'image_id'
     self.image = 'image'
     self._df_path = 'df_path'
     self.df_dir = 'df_dir'
コード例 #4
0
def test_image_name_comparison():
    # make sure that both "==" and "!=" are implemented right on both Python major releases
    i1 = ImageName(registry='foo.com', namespace='spam', repo='bar', tag='1')
    i2 = ImageName(registry='foo.com', namespace='spam', repo='bar', tag='1')
    assert i1 == i2
    assert not i1 != i2

    i2 = ImageName(registry='foo.com', namespace='spam', repo='bar', tag='2')
    assert not i1 == i2
    assert i1 != i2
コード例 #5
0
ファイル: test_pulp.py プロジェクト: twaugh/atomic-reactor
def prepare(check_repo_retval=0):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)
    setattr(workflow, 'tag_conf', X())
    setattr(workflow.tag_conf, 'images', [
        ImageName(repo="image-name1"),
        ImageName(namespace="prefix", repo="image-name2"),
        ImageName(repo="image-name3", tag="asd")
    ])

    # Mock dockpulp and docker
    dockpulp.Pulp = flexmock(dockpulp.Pulp)
    dockpulp.Pulp.registry = 'registry.example.com'
    (flexmock(dockpulp.imgutils).should_receive('get_metadata').with_args(
        object).and_return([{
            'id': 'foo'
        }]))
    (flexmock(dockpulp.imgutils).should_receive('get_versions').with_args(
        object).and_return({'id': '1.6.0'}))
    (flexmock(dockpulp.imgutils).should_receive('check_repo').and_return(
        check_repo_retval))
    (flexmock(dockpulp.Pulp).should_receive('set_certs').with_args(
        object, object))
    (flexmock(dockpulp.Pulp).should_receive('getRepos').with_args(
        list, fields=list).and_return([{
            "id": "redhat-image-name1"
        }, {
            "id": "redhat-prefix-image-name2"
        }]))
    (flexmock(dockpulp.Pulp).should_receive('createRepo'))
    (flexmock(dockpulp.Pulp).should_receive('upload').with_args(unicode))
    (flexmock(dockpulp.Pulp).should_receive('copy').with_args(
        unicode, unicode))
    (flexmock(dockpulp.Pulp).should_receive('updateRepo').with_args(
        unicode, dict))
    (flexmock(dockpulp.Pulp).should_receive('crane').with_args(
        list, wait=True).and_return([2, 3, 4]))
    (flexmock(dockpulp.Pulp).should_receive('').with_args(
        object, object).and_return([1, 2, 3]))
    (flexmock(dockpulp.Pulp).should_receive('watch_tasks').with_args(list))
    mock_docker()
    return tasker, workflow
コード例 #6
0
def test_privileged_build(caplog, source_params):
    if MOCK:
        mock_docker()

    image_name = ImageName(repo=TEST_IMAGE)
    remote_image = image_name.copy()
    remote_image.registry = LOCALHOST_REGISTRY
    m = PrivilegedBuildManager(
        "buildroot-fedora",
        {
            "source": source_params,
            "image": remote_image.to_str(),
            "parent_registry": LOCALHOST_REGISTRY,  # faster
            "target_registries_insecure": True,
            "parent_registry_insecure": True,
        })
    results = m.build()
    dt = DockerTasker()
    dt.pull_image(remote_image, insecure=True)

    if source_params['provider'] == 'path':
        assert_source_from_path_mounted_ok(caplog, m.temp_dir)

    assert len(results.build_logs) > 0
    # assert isinstance(results.built_img_inspect, dict)
    # assert len(results.built_img_inspect.items()) > 0
    # assert isinstance(results.built_img_info, dict)
    # assert len(results.built_img_info.items()) > 0
    # assert isinstance(results.base_img_info, dict)
    # assert len(results.base_img_info.items()) > 0
    # assert len(results.base_plugins_output) > 0
    # assert len(results.built_img_plugins_output) > 0
    dt.remove_container(results.container_id)
    dt.remove_image(remote_image)
コード例 #7
0
def test_rpmqa_plugin_skip(docker_tasker):  # noqa
    """
    Test skipping the plugin if workflow.image_components is already set
    """

    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', "asd123")
    setattr(workflow.builder, 'base_image', ImageName(repo='fedora', tag='21'))
    setattr(workflow.builder, "source", X())
    setattr(workflow.builder.source, 'dockerfile_path', "/non/existent")
    setattr(workflow.builder.source, 'path', "/non/existent")

    image_components = {
        'type': 'rpm',
        'name': 'something'
    }
    setattr(workflow, 'image_components', image_components)

    mock_docker()
    flexmock(docker.APIClient, logs=mock_logs_raise)
    runner = PostBuildPluginsRunner(docker_tasker, workflow,
                                    [{"name": PostBuildRPMqaPlugin.key,
                                      "args": {'image_id': TEST_IMAGE}}])
    results = runner.run()
    assert results[PostBuildRPMqaPlugin.key] is None
    assert workflow.image_components == image_components
コード例 #8
0
 def __init__(self, tmpdir):
     self.tasker = DockerTasker()
     self.base_image = ImageName(repo='Fedora', tag='22')
     self.base_from_scratch = False
     self.image_id = 'image_id'
     self.image = 'image'
     self.source = MockSource(tmpdir)
コード例 #9
0
def test_upload(unsupported, caplog):
    log = logging.getLogger("tests.test_pulp_util")
    pulp_registry_name = 'registry.example.com'
    testfile = 'foo'
    upload_file = 'test_file'
    repo_id = 'redhat-myproject-hello-world'

    _, workflow = prepare(testfile)
    image_names = [ImageName(repo="myproject-hello-world")]
    handler = PulpHandler(workflow, pulp_registry_name, log)
    handler.create_dockpulp_and_repos(image_names)

    if unsupported:
        (flexmock(dockpulp.Pulp).should_receive('upload').with_args(
            upload_file, repo_id).and_raise(TypeError).once().ordered())
        (flexmock(dockpulp.Pulp).should_receive('upload').with_args(
            upload_file).and_return(True).once().ordered())
    else:
        (flexmock(dockpulp.Pulp).should_receive('upload').with_args(
            upload_file, repo_id).and_return(False).once())

    handler.upload(upload_file, repo_id)

    assert "Uploading %s to %s" % (upload_file, repo_id) in caplog.text()

    if unsupported:
        assert "Falling back to uploading %s to redhat-everything repo" %\
               upload_file in caplog.text()
コード例 #10
0
def prepare(key, value, set_labels_args=None, set_labels_kwargs=None):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', 'asd123')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder.source, 'path', '/tmp')
    setattr(workflow.builder.source, 'dockerfile_path', None)
    expectation = flexmock(OSBS).should_receive('set_labels_on_build_config')
    if set_labels_args is not None:
        if set_labels_kwargs is None:
            set_labels_kwargs = {}

        expectation.with_args(*set_labels_args, **set_labels_kwargs)

    runner = PreBuildPluginsRunner(tasker, workflow,
                                   [{
                                       'name': CheckAndSetRebuildPlugin.key,
                                       'args': {
                                           'label_key': key,
                                           'label_value': value,
                                           'url': '',
                                       },
                                   }])
    return workflow, runner
コード例 #11
0
 def __init__(self):
     self.tasker = DockerTasker()
     self.base_image = ImageName(repo='Fedora', tag='22')
     self.image_id = 'image_id'
     self.image = 'image'
     self.df_path = 'df_path'
     self.df_dir = 'df_dir'
コード例 #12
0
ファイル: test_rpmqa.py プロジェクト: rcerven/atomic-reactor
def test_rpmqa_plugin(remove_container_error, ignore_autogenerated):
    if MOCK:
        should_raise_error = {}
        if remove_container_error:
            should_raise_error['remove_container'] = None
        mock_docker(should_raise_error=should_raise_error)

    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', "asd123")
    setattr(workflow.builder, 'base_image', ImageName(repo='fedora', tag='21'))
    setattr(workflow.builder, "source", X())
    setattr(workflow.builder.source, 'dockerfile_path', "/non/existent")
    setattr(workflow.builder.source, 'path', "/non/existent")

    flexmock(docker.Client, logs=mock_logs)
    runner = PostBuildPluginsRunner(
        tasker, workflow, [{
            "name": PostBuildRPMqaPlugin.key,
            "args": {
                'image_id': TEST_IMAGE,
                "ignore_autogenerated_gpg_keys": ignore_autogenerated["ignore"]
            }
        }])
    results = runner.run()
    assert results[
        PostBuildRPMqaPlugin.key] == ignore_autogenerated["package_list"]
コード例 #13
0
    def run(self):
        pulp = dockpulp.Pulp(env=self.pulp_registry_name)
        self.set_auth(pulp)

        # We only want the hostname[:port]
        pulp_registry = re.sub(r'^https?://([^/]*)/?.*',
                               lambda m: m.groups()[0],
                               pulp.registry)

        # Store the registry URI in the push configuration
        self.workflow.push_conf.add_pulp_registry(self.pulp_registry_name,
                                                  pulp_registry)

        self.log.info("syncing from docker V2 registry %s",
                      self.docker_registry)

        images = []
        repos = {}  # pulp repo -> repo id
        with dockpulp_config(docker_registry=self.docker_registry) as config:
            for image in self.workflow.tag_conf.primary_images:
                if image.pulp_repo not in repos:
                    self.log.info("syncing %s", image.pulp_repo)
                    repoinfo = pulp.syncRepo(config.env, image.pulp_repo,
                                             config_file=config.name)
                    repos[image.pulp_repo] = repoinfo[0]['id']


                images.append(ImageName(registry=pulp_registry,
                                        repo=image.repo))

        self.log.info("publishing to crane")
        pulp.crane(list(repos.values()), wait=True)

        # Return the set of qualitifed repo names for this image
        return images
コード例 #14
0
def mock_environment(tmpdir, primary_images=None, worker_annotations={}):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, "test-image")
    base_image_id = '123456parent-id'
    setattr(workflow, '_base_image_inspect', {'Id': base_image_id})
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', '123456imageid')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder, 'built_image_info', {'ParentId': base_image_id})
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)
    setattr(workflow, 'tag_conf', TagConf())
    if primary_images:
        workflow.tag_conf.add_primary_images(primary_images)
        workflow.tag_conf.add_unique_image(primary_images[0])

    annotations = deepcopy(BUILD_ANNOTATIONS)
    if not worker_annotations:
        worker_annotations = {'ppc64le': PPC_ANNOTATIONS}
    for worker in worker_annotations:
        annotations['worker-builds'][worker] = deepcopy(
            worker_annotations[worker])

    workflow.build_result = BuildResult(image_id='123456',
                                        annotations=annotations)

    return tasker, workflow
コード例 #15
0
class X(object):
    image_id = INPUT_IMAGE
    source = Y()
    source.dockerfile_path = None
    source.path = None
    base_image = ImageName(repo="qwe", tag="asd")
    image = ImageName.parse("test-image:unique_tag_123")
コード例 #16
0
def mock_environment(tmpdir, workflow, primary_images=None, floating_images=None,
                     manifest_results=None, annotations=None):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    base_image_id = '123456parent-id'
    setattr(workflow, '_base_image_inspect', {'Id': base_image_id})
    setattr(workflow, 'builder', StubInsideBuilder())
    setattr(workflow.builder, 'image_id', '123456imageid')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', StubInsideBuilder())
    setattr(workflow.builder, 'built_image_info', {'ParentId': base_image_id})
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)
    if primary_images:
        for image in primary_images:
            if '-' in ImageName.parse(image).tag:
                workflow.tag_conf.add_primary_image(image)
        workflow.tag_conf.add_unique_image(primary_images[0])

    if floating_images:
        workflow.tag_conf.add_floating_images(floating_images)

    workflow.build_result = BuildResult(image_id='123456', annotations=annotations or {})
    workflow.postbuild_results = {}
    if manifest_results:
        workflow.postbuild_results[PLUGIN_GROUP_MANIFESTS_KEY] = manifest_results

    return tasker, workflow
コード例 #17
0
    def check_manifest_list(self, build_image, orchestrator_platform, platforms,
                            current_buildimage):
        registry_name, image = build_image.split('/', 1)
        repo, tag = image.rsplit(':', 1)

        registry = ImageName(registry=registry_name, repo=repo, tag=tag)
        manifest_list = get_manifest_list(registry, registry_name, insecure=True)

        # we don't have manifest list, but we want to build on different platforms
        if not manifest_list:
            raise RuntimeError("Buildroot image isn't manifest list,"
                               " which is needed for specified arch")
        arch_digests = {}
        image_name = build_image.rsplit(':', 1)[0]

        manifest_list_dict = manifest_list.json()
        for manifest in manifest_list_dict['manifests']:
            arch = manifest['platform']['architecture']
            arch_digests[arch] = image_name + '@' + manifest['digest']

        arch_to_platform = get_goarch_to_platform_mapping(self.workflow, self.plat_des_fallback)
        for arch in arch_digests:
            self.build_image_digests[arch_to_platform[arch]] = arch_digests[arch]

        # orchestrator platform is in manifest list
        if orchestrator_platform not in self.build_image_digests:
            raise RuntimeError("Platform for orchestrator '%s' isn't in manifest list"
                               % orchestrator_platform)

        if ('@sha256:' in current_buildimage and
                self.build_image_digests[orchestrator_platform] != current_buildimage):
            raise RuntimeError("Orchestrator is using image digest '%s' which isn't"
                               " in manifest list" % current_buildimage)
コード例 #18
0
class X(object):
    image_id = INPUT_IMAGE
    source = Y()
    source.dockerfile_path = None
    source.path = None
    base_image = ImageName(repo="qwe", tag="asd")
    original_base_image = base_image.copy()
コード例 #19
0
def mock_environment(tmpdir,
                     session=None,
                     build_process_failed=False,
                     koji_build_id=None,
                     use_import=False):
    if session is None:
        session = MockedClientSession('')

    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow(SOURCE, 'test-image')
    setattr(workflow, 'builder', X())
    setattr(workflow.builder, 'image_id', '123456imageid')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', X())
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)

    flexmock(koji, ClientSession=lambda hub, opts: session)

    if build_process_failed:
        workflow.build_result = BuildResult(fail_reason="not built")
    else:
        workflow.build_result = BuildResult(image_id="id1234")

    if koji_build_id:
        if use_import:
            workflow.exit_results[KojiImportPlugin.key] = koji_build_id
        else:
            workflow.exit_results[KojiPromotePlugin.key] = koji_build_id

    (flexmock(time).should_receive('sleep').and_return(None))

    return tasker, workflow
コード例 #20
0
def mock_environment(tmpdir, primary_images=None, annotations=None):
    if MOCK:
        mock_docker()
    tasker = DockerTasker()
    workflow = DockerBuildWorkflow("test-image", source=SOURCE)
    base_image_id = '123456parent-id'
    setattr(workflow, '_base_image_inspect', {'Id': base_image_id})
    setattr(workflow, 'builder', StubInsideBuilder())
    setattr(workflow.builder, 'image_id', '123456imageid')
    setattr(workflow.builder, 'base_image', ImageName(repo='Fedora', tag='22'))
    setattr(workflow.builder, 'source', StubInsideBuilder())
    setattr(workflow.builder, 'built_image_info', {'ParentId': base_image_id})
    setattr(workflow.builder.source, 'dockerfile_path', None)
    setattr(workflow.builder.source, 'path', None)
    setattr(workflow, 'tag_conf', TagConf())
    if primary_images:
        for image in primary_images:
            if '-' in ImageName.parse(image).tag:
                workflow.tag_conf.add_primary_image(image)
        workflow.tag_conf.add_unique_image(primary_images[0])

    workflow.tag_conf.add_floating_image('namespace/httpd:floating')
    workflow.build_result = BuildResult(image_id='123456',
                                        annotations=annotations or {})

    return tasker, workflow
コード例 #21
0
    def push_tar(self, filename, image_names=None, repo_prefix="redhat-"):
        # Find out how to tag this image.
        self.log.info("image names: %s", [str(image_name) for image_name in image_names])

        self.log.info("checking image before upload %s", filename)
        self.pulp_handler.check_file(filename)

        pulp_repos = self.pulp_handler.create_dockpulp_and_repos(image_names, repo_prefix)
        _, file_extension = os.path.splitext(filename)
        compressed_filename = None

        try:
            top_layer, layers = self.pulp_handler.get_tar_metadata(filename)
            compressed_filename = self._deduplicate_layers(layers, filename, file_extension)
        except Exception:
            self.log.debug("Error on creating deduplicated layers tar", exc_info=True)
            try:
                if file_extension != '.tar':
                    raise RuntimeError("tar is already compressed")
                compressed_filename = self._gzip_file(filename)
            except Exception:
                self.log.info("Falling back to full tar upload")

        in_rh_everything = False
        if compressed_filename:
            filename = compressed_filename
        for repo_id in pulp_repos:
            in_rh_everything = self.pulp_handler.upload(filename, repo_id)
            # Content was uploaded to shared redhat-everything repo. This should only be done
            # once regardless of how many pulp repos are in use.
            if in_rh_everything:
                break
        self._unlink_file(compressed_filename)

        for repo_id, pulp_repo in pulp_repos.items():
            if in_rh_everything:
                self.pulp_handler.copy_v1_layers(repo_id, layers)
            self.pulp_handler.update_repo(repo_id, {"tag": "%s:%s" % (",".join(pulp_repo.tags),
                                                                      top_layer)})

        # Only publish if we don't the pulp_sync plugin also configured
        if self.publish:
            self.pulp_handler.publish(pulp_repos.keys())
        else:
            self.log.info("publishing deferred until %s plugin runs", PLUGIN_PULP_SYNC_KEY)

        # Store the registry URI in the push configuration

        # We only want the hostname[:port]
        pulp_registry = self.pulp_handler.get_registry_hostname()

        self.workflow.push_conf.add_pulp_registry(self.pulp_handler.get_pulp_instance(),
                                                  pulp_registry,
                                                  server_side_sync=False)

        # Return the set of qualified repo names for this image
        return top_layer, [ImageName(registry=pulp_registry, repo=repodata.registry_id, tag=tag)
                for dummy_repo, repodata in pulp_repos.items()
                for tag in repodata.tags]  # noqa
コード例 #22
0
def test_tag_by_labels_plugin(tmpdir, args):
    if MOCK:
        mock_docker()

    tasker = DockerTasker()
    workflow = DockerBuildWorkflow({
        "provider": "git",
        "uri": "asd"
    }, "test-image")
    version = "1.0"
    release = "1"
    workflow.built_image_inspect = {
        INSPECT_CONFIG: {
            "Labels": {
                "name": TEST_IMAGE,
                "version": version,
                "release": release
            }
        }
    }
    workflow.push_conf.add_docker_registry(LOCALHOST_REGISTRY, insecure=True)
    image = ImageName(repo=TEST_IMAGE,
                      tag="%s_%s" % (version, release),
                      registry=LOCALHOST_REGISTRY)

    setattr(workflow, 'builder', X)

    runner = PostBuildPluginsRunner(tasker, workflow,
                                    [{
                                        'name': TagByLabelsPlugin.key,
                                        'args': args,
                                    }])
    output = runner.run()
    assert TagByLabelsPlugin.key in output.keys()

    images = [i.to_str() for i in workflow.tag_conf.images]
    primary_images = [i.to_str() for i in workflow.tag_conf.primary_images]
    unique_images = [i.to_str() for i in workflow.tag_conf.unique_images]

    if args.get('unique_tag_only'):
        assert len(workflow.tag_conf.images) == 1
        assert len(primary_images) == 0

    else:
        assert len(workflow.tag_conf.images) == 4
        assert len(primary_images) == 3

        assert ("%s:%s-%s" % (TEST_IMAGE, version, release)) in images
        assert ("%s:%s" % (TEST_IMAGE, version)) in images
        assert ("%s:latest" % (TEST_IMAGE, )) in images

        assert ("%s:%s-%s" % (TEST_IMAGE, version, release)) in primary_images
        assert ("%s:%s" % (TEST_IMAGE, version)) in primary_images
        assert ("%s:latest" % (TEST_IMAGE, )) in primary_images

    assert len(unique_images) == 1
    assert ("%s:%s" % (TEST_IMAGE, "unique_tag_123")) in images
    assert ("%s:%s" % (TEST_IMAGE, "unique_tag_123")) in unique_images
    tasker.remove_image(image)
コード例 #23
0
 def __init__(self):
     self.tasker = DockerTasker(retry_times=0)
     self.base_image = ImageName(repo='Fedora', tag='22')
     self.base_from_scratch = False
     self.image_id = 'image_id'
     self.image = 'image'
     self.df_path = 'df_path'
     self.df_dir = 'df_dir'
コード例 #24
0
    def __init__(self, failed=False, is_base_image=False):
        if is_base_image:
            self.tasker = MockDockerTaskerBaseImage()
            self.base_image = ImageName(namespace='koji', repo='image-build')
        else:
            self.tasker = MockDockerTasker()
            self.base_image = ImageName(repo='Fedora', tag='22')
        self.image_id = 'asd'
        self.image = 'image'
        self.failed = failed
        self.df_path = 'some'
        self.df_dir = 'some'

        def simplegen(x, y):
            yield "some"

        flexmock(self.tasker, build_image_from_path=simplegen)
コード例 #25
0
 def __init__(self, failed=False, image_id=None):
     self.tasker = None
     self.base_image = ImageName(repo='Fedora', tag='29')
     self.image_id = image_id or 'asd'
     self.image = ImageName.parse('image')
     self.failed = failed
     self.df_path = 'some'
     self.df_dir = 'some'
コード例 #26
0
 def __init__(self):
     self.tasker = flexmock()
     self.base_image = ImageName(repo='Fedora', tag='22')
     self.original_base_image = ImageName(repo='Fedora', tag='22')
     self.base_from_scratch = False
     self.custom_base_image = False
     self.parent_images = {
         ImageName.parse('base'): ImageName.parse('base:stubDigest')
     }
     base_inspect = {INSPECT_CONFIG: {'Labels': BASE_IMAGE_LABELS.copy()}}
     self._parent_images_inspect = {
         ImageName.parse('base:stubDigest'): base_inspect
     }
     self.parent_images_digests = {'base:latest': {V2_LIST: 'stubDigest'}}
     self.image_id = 'image_id'
     self.image = 'image'
     self._df_path = 'df_path'
     self.df_dir = 'df_dir'
コード例 #27
0
    def _pull_and_tag_image(self, image, build_json, nonce):
        """Docker pull the image and tag it uniquely for use by this build"""
        image = image.copy()
        first_library_exc = None
        for _ in range(20):
            # retry until pull and tag is successful or definitively fails.
            # should never require 20 retries but there's a race condition at work.
            # just in case something goes wildly wrong, limit to 20 so it terminates.
            try:
                self.tasker.pull_image(
                    image,
                    insecure=self.parent_registry_insecure,
                    dockercfg_path=self.parent_registry_dockercfg_path)
                self.workflow.pulled_base_images.add(image.to_str())
            except RetryGeneratorException as exc:
                # getting here means the pull itself failed. we may want to retry if the
                # image being pulled lacks a namespace, like e.g. "rhel7". we cannot count
                # on the registry mapping this into the docker standard "library/rhel7" so
                # need to retry with that.
                if first_library_exc is not None:
                    # we already tried and failed; report the first failure.
                    raise first_library_exc  # pylint: disable=raising-bad-type
                if image.namespace:
                    # already namespaced, do not retry with "library/", just fail.
                    raise

                self.log.info("'%s' not found", image.to_str())
                image.namespace = 'library'
                self.log.info("trying '%s'", image.to_str())
                first_library_exc = exc  # report first failure if retry also fails
                continue

            # Attempt to tag it using a unique ID. We might have to retry
            # if another build with the same parent image is finishing up
            # and removing images it pulled.

            # Use the OpenShift build name as the unique ID
            unique_id = build_json['metadata']['name']
            new_image = ImageName(repo=unique_id, tag=nonce)

            try:
                self.log.info("tagging pulled image")
                response = self.tasker.tag_image(image, new_image)
                self.workflow.pulled_base_images.add(response)
                self.log.debug("image '%s' is available as '%s'", image,
                               new_image)
                return new_image
            except docker.errors.NotFound:
                # If we get here, some other build raced us to remove
                # the parent image, and that build won.
                # Retry the pull immediately.
                self.log.info("re-pulling removed image")
                continue

        # Failed to tag it after 20 tries
        self.log.error("giving up trying to pull image")
        raise RuntimeError("too many attempts to pull and tag image")
コード例 #28
0
    def workflow(docker_repos):
        primary_images = []
        for tag in ['1.0-1', '1.0', 'latest']:
            primary_images.extend(
                [ImageName(repo=repo, tag=tag) for repo in docker_repos])

        tag_conf = flexmock(primary_images=primary_images)
        push_conf = PushConf()
        return flexmock(tag_conf=tag_conf, push_conf=push_conf)
コード例 #29
0
    def workflow(docker_repos):
        primary_images = []
        for tag in ['1.0-1', '1.0', 'latest']:
            primary_images.extend(
                [ImageName(repo=repo, tag=tag) for repo in docker_repos])

        tag_conf = flexmock(primary_images=primary_images)
        push_conf = flexmock(add_pulp_registry=lambda env, registry: None)
        return flexmock(tag_conf=tag_conf, push_conf=push_conf)
コード例 #30
0
 def _replace(self, image, registry=_KEEP, namespace=_KEEP, repo=_KEEP, tag=_KEEP):
     """
     Replace specified parts of image pullspec, keep the rest
     """
     return ImageName(
         registry=image.registry if registry is _KEEP else registry,
         namespace=image.namespace if namespace is _KEEP else namespace,
         repo=image.repo if repo is _KEEP else repo,
         tag=image.tag if tag is _KEEP else tag,
     )