示例#1
0
    def test_image_distgit_matches_source(self):
        """
        Check the logic for matching a commit from source repo
        """
        self.img_dg.config.content = model.Model()

        # no source, dist-git only; should go on to check if built/stale
        flexmock(self.img_dg).should_receive(
            "_built_or_recent").once().and_return(None)
        self.assertIsNone(self.img_dg.matches_source_commit({}))

        # source specified and matches Dockerfile in dist-git
        self.img_dg.config.content.source = model.Model()
        self.img_dg.config.content.source.git = dict()
        test_file = u"""
            from foo
            label "{}"="spam"
        """.format(distgit.ImageDistGitRepo.source_labels['now']['sha'])
        flexmock(
            self.md).should_receive("fetch_cgit_file").and_return(test_file)
        flexmock(self.img_dg).should_receive("_built_or_recent").and_return(
            None)  # hit this on match
        flexmock(self.img_dg.runtime).should_receive(
            "detect_remote_source_branch").and_return(("branch", "spam"))
        self.assertIsNone(self.img_dg.matches_source_commit(
            {}))  # matches, falls through

        # source specified and doesn't match Dockerfile in dist-git
        flexmock(self.img_dg.runtime).should_receive(
            "detect_remote_source_branch").and_return(("branch", "eggs"))
        self.assertFalse(self.img_dg.matches_source_commit({}))
示例#2
0
 def test_get_brew_image_name_short(self):
     image_model = model.Model({
         'name': 'openshift/test',
     })
     data_obj = model.Model({
         'key': 'my-distgit',
         'data': image_model,
         'filename': 'my-distgit.yaml',
     })
     rt = MockRuntime(self.logger)
     imeta = image.ImageMetadata(rt, data_obj)
     self.assertEqual(imeta.get_brew_image_name_short(), 'openshift-test')
示例#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_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"})
示例#5
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'
            ]))
示例#6
0
def stub_runtime():
    rt = runtime.Runtime(
        latest_parent_version=False,
        logger=logutil.getLogger(__name__),
        stage=False,
        branch=None,
    )
    rt.group_config = model.Model()
    return rt
示例#7
0
    def test_distgit_is_recent(self):
        scan_freshness = self.dg.runtime.group_config.scan_freshness = model.Model(
        )
        self.assertFalse(
            self.dg.release_is_recent("201901020304"))  # not configured

        scan_freshness.release_regex = r'^(....)(..)(..)(..)'
        scan_freshness.threshold_hours = 24
        self.assertFalse(
            self.dg.release_is_recent("2019"))  # no match by regex

        too_soon = datetime.now() - timedelta(hours=4)
        self.assertTrue(
            self.dg.release_is_recent(too_soon.strftime('%Y%m%d%H')))
        too_stale = datetime.now() - timedelta(hours=25)
        self.assertFalse(
            self.dg.release_is_recent(too_stale.strftime('%Y%m%d%H')))
示例#8
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)
示例#9
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()
示例#10
0
 def __init__(self, *args, **kwargs):
     super(MockConfig, self).__init__(*args, **kwargs)
     self.distgit = MockDistgit()
     self.content = model.Model()
     self.content.source = model.Model()
     self.content.source.specfile = "test-dummy.spec"
示例#11
0
 def setUp(self):
     super(TestImageDistGit, self).setUp()
     self.img_dg = distgit.ImageDistGitRepo(self.md, autoclone=False)
     self.img_dg.runtime.group_config = model.Model()
示例#12
0
def get_assembly_promotion_permits(releases_config: Dict, assembly_name: str):
    return assembly._assembly_config_struct(model.Model(releases_config),
                                            assembly_name, 'promotion_permits',
                                            [])
示例#13
0
def get_assmebly_basis(releases_config: Dict, assembly_name: str):
    return assembly.assembly_basis(model.Model(releases_config), assembly_name)
示例#14
0
def get_assembly_type(releases_config: Dict, assembly_name: str):
    return assembly.assembly_type(model.Model(releases_config), assembly_name)
示例#15
0
 def setUp(self):
     super(TestGenericDistGit, self).setUp()
     self.dg = distgit.DistGitRepo(self.md, autoclone=False)
     self.dg.runtime.group_config = model.Model()