Beispiel #1
0
def get_latest_image_builds(brew_session: koji.ClientSession,
                            tags: Iterator[str],
                            image_metas: Iterator[ImageMetadata]):
    tag_component_tuples = [(tag, image.get_component_name()) for tag in tags
                            for image in image_metas()]
    builds = brew.get_latest_builds(tag_component_tuples, brew_session)
    return [b[0] for b in builds if b]
Beispiel #2
0
def _fetch_builds_by_kind_image(runtime, tag_pv_map, brew_event, brew_session, p, np):
    # filter out image like 'openshift-enterprise-base'
    image_metas = [i for i in runtime.image_metas() if not i.base_only]
    # Returns a list of (name, version, release, product_version) tuples of each build
    nvrps = []

    # type judge
    def tj(image, p, np):
        if not image.is_release:
            return False
        if p:
            return p == image.is_payload
        if np:
            # boolean xor.
            return np != image.is_payload
        else:
            return True

    tag_component_tuples = [(tag, image.get_component_name()) for tag in tag_pv_map for image in image_metas if tj(image, p, np)]

    pbar_header(
        'Generating list of images: ',
        f'Hold on a moment, fetching Brew builds for {len(image_metas)} components with tags {", ".join(tag_pv_map.keys())}...',
        tag_component_tuples)
    latest_builds = brew.get_latest_builds(tag_component_tuples, event=brew_event, session=brew_session)

    for i, build in enumerate(latest_builds):
        if not build:
            continue
        tag = tag_component_tuples[i][0]
        nvrps.append((build[0]['name'], build[0]['version'], build[0]['release'], tag_pv_map[tag]))

    return nvrps
Beispiel #3
0
    def test_get_latest_builds(self):
        tag_component_tuples = [
            ("faketag1", "component1"),
            ("faketag2", "component2"),
            ("faketag2", None),
            ("faketag1", "component4"),
            ("", "component5"),
            ("faketag2", "component6"),
        ]
        expected = [
            {
                "name": "component1",
                "nvr": "component1-v1.0.0-1.faketag1"
            },
            {
                "name": "component2",
                "nvr": "component2-v1.0.0-1.faketag2"
            },
            None,
            {
                "name": "component4",
                "nvr": "component4-v1.0.0-1.faketag1"
            },
            None,
            {
                "name": "component6",
                "nvr": "component6-v1.0.0-1.faketag2"
            },
        ]

        def fake_response(tag, package, event=None):
            return mock.MagicMock(result={
                "name": package,
                "nvr": f"{package}-v1.0.0-1.{tag}"
            })

        fake_session = mock.MagicMock()
        fake_context_manager = fake_session.multicall.return_value.__enter__.return_value
        fake_context_manager.getLatestBuilds.side_effect = fake_response
        actual = brew.get_latest_builds(tag_component_tuples, fake_session)
        self.assertListEqual(actual, expected)