Пример #1
0
    def test_detect_package_manangers(self, is_file: Mock, is_dir: Mock):
        runtime = MagicMock(uuid="123456")
        runtime.group_config.cachito.enabled = True
        meta = ImageMetadata(
            runtime,
            model.Model({
                "key": "foo",
                'data': {
                    'name': 'openshift/foo',
                    'distgit': {
                        'branch': 'fake-branch-rhel-8'
                    },
                    "additional_tags": ["tag_a", "tag_b"]
                },
            }))
        dg = distgit.ImageDistGitRepo(meta, autoclone=False)
        dg.logger = logging.getLogger()
        dg.distgit_dir = "/path/to/distgit/containers/foo"
        dg.dg_path = Path(dg.distgit_dir)
        is_dir.return_value = True
        is_file.side_effect = lambda f: f.name in [
            "go.mod", "package-lock.json"
        ]

        actual = dg._detect_package_manangers()
        self.assertEqual(set(actual), {"gomod", "npm"})
Пример #2
0
    def test_generate_osbs_image_config_with_addtional_tags(self):
        runtime = MagicMock(uuid="123456")
        runtime.group_config.cachito.enabled = False
        meta = ImageMetadata(
            runtime,
            model.Model({
                "key": "foo",
                'data': {
                    'name': 'openshift/foo',
                    'distgit': {
                        'branch': 'fake-branch-rhel-8'
                    },
                    "additional_tags": ["tag_a", "tag_b"]
                },
            }))
        dg = distgit.ImageDistGitRepo(meta, autoclone=False)
        dg.logger = logging.getLogger()

        # assembly is not enabled
        runtime.assembly = None
        container_yaml = dg._generate_osbs_image_config("v4.10.0")
        self.assertEqual(
            sorted(container_yaml["tags"]),
            sorted(['v4.10.0.123456', 'v4.10', 'v4.10.0', 'tag_a', 'tag_b']))

        # assembly is enabled
        runtime.assembly = "art3109"
        container_yaml = dg._generate_osbs_image_config("v4.10.0")
        self.assertEqual(
            sorted(container_yaml["tags"]),
            sorted([
                'assembly.art3109', 'v4.10.0.123456', 'v4.10', 'v4.10.0',
                'tag_a', 'tag_b'
            ]))
Пример #3
0
    def test_generate_osbs_image_config_with_cachito_enabled(
            self, is_dir: Mock):
        runtime = MagicMock(uuid="123456",
                            assembly="test",
                            assembly_basis_event=None,
                            profile=None,
                            odcs_mode=False)
        runtime.group_config = model.Model()
        meta = ImageMetadata(
            runtime,
            model.Model({
                "key": "foo",
                'data': {
                    'name': 'openshift/foo',
                    'distgit': {
                        'branch': 'fake-branch-rhel-8'
                    },
                    "additional_tags": ["tag_a", "tag_b"],
                    "content": {
                        "source": {
                            "git": {
                                "url":
                                "[email protected]:openshift-priv/foo.git",
                                "branch": {
                                    "target": "release-4.10"
                                }
                            }
                        }
                    },
                    "cachito": {
                        "enabled": True,
                        "flags": ["gomod-vendor-check"]
                    }
                },
            }))
        dg = distgit.ImageDistGitRepo(meta, autoclone=False)
        dg.logger = logging.getLogger()
        dg.distgit_dir = "/path/to/distgit/containers/foo"
        dg.dg_path = Path(dg.distgit_dir)
        dg.actual_source_url = "[email protected]:openshift-priv/foo.git"
        dg.source_full_sha = "deadbeef"
        dg._detect_package_manangers = MagicMock(return_value=["gomod"])

        actual = dg._generate_osbs_image_config("v4.10.0")
        self.assertEqual(actual["remote_sources"][0]["remote_source"]["repo"],
                         "https://example.com/openshift-priv/foo")
        self.assertEqual(actual["remote_sources"][0]["remote_source"]["ref"],
                         "deadbeef")
        self.assertEqual(
            actual["remote_sources"][0]["remote_source"]["pkg_managers"],
            ["gomod"])
        self.assertEqual(actual["remote_sources"][0]["remote_source"]["flags"],
                         ["gomod-vendor-check"])
Пример #4
0
    def test_inject_yum_update_commands_without_repos(self):
        runtime = MagicMock()
        meta = ImageMetadata(
            runtime,
            model.Model({
                "key": "foo",
                'data': {
                    'name': 'openshift/foo',
                    'distgit': {
                        'branch': 'fake-branch-rhel-8'
                    },
                    "enabled_repos": []
                },
            }))
        dg = distgit.ImageDistGitRepo(meta, autoclone=False)
        dg.logger = logging.getLogger()
        dg.dg_path = MagicMock()
        dockerfile = """
FROM some-base-image:some-tag AS builder
# __doozer=yum-update
USER 0
# __doozer=yum-update
RUN yum update -y && yum clean all  # set final_stage_user in ART metadata if this fails
LABEL name=value
RUN some-command
FROM another-base-image:some-tag
# __doozer=yum-update
USER 0
# __doozer=yum-update
RUN yum update -y && yum clean all  # set final_stage_user in ART metadata if this fails
# __doozer=yum-update
USER 1001
COPY --from=builder /some/path/a /some/path/b
        """.strip()
        actual = dg._update_yum_update_commands(
            True, io.StringIO(dockerfile)).getvalue().strip().splitlines()
        expected = """
FROM some-base-image:some-tag AS builder
LABEL name=value
RUN some-command
FROM another-base-image:some-tag
COPY --from=builder /some/path/a /some/path/b
        """.strip().splitlines()
        self.assertListEqual(actual, expected)
Пример #5
0
    def test_detect_package_manangers_without_git_clone(self):
        runtime = MagicMock(uuid="123456")
        runtime.group_config.cachito.enabled = True
        meta = ImageMetadata(
            runtime,
            model.Model({
                "key": "foo",
                'data': {
                    'name': 'openshift/foo',
                    'distgit': {
                        'branch': 'fake-branch-rhel-8'
                    },
                    "additional_tags": ["tag_a", "tag_b"]
                },
            }))
        dg = distgit.ImageDistGitRepo(meta, autoclone=False)
        dg.logger = logging.getLogger()

        with self.assertRaises(FileNotFoundError):
            dg._detect_package_manangers()