Exemple #1
0
    def test_is_autorebuild_enabled(self, tmpdir, config_value,
                                    expected_value):

        with open(os.path.join(str(tmpdir), REPO_CONFIG_FILE), 'w') as f:
            if config_value is not None:
                f.write(
                    dedent("""\
                    [autorebuild]
                    enabled={}
                    """.format(config_value)))

        add_timestamp = ''
        if expected_value:
            add_timestamp = 'add_timestamp_to_release: true'
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            f.write(
                dedent("""\
                compose:
                    modules:
                    - mod_name:mod_stream:mod_version
                autorebuild:
                    {}
                """.format(add_timestamp)))

        conf = RepoConfiguration(dir_path=str(tmpdir))
        assert conf.is_autorebuild_enabled() is expected_value
        if add_timestamp:
            assert conf.autorebuild == {'add_timestamp_to_release': True}
        else:
            assert conf.autorebuild == {}
 def test_repo_files_extensions(self, tmpdir, files, error_msg):
     for repo_file in files:
         path = os.path.join(str(tmpdir), repo_file)
         os.mknod(path)
     if error_msg:
         with pytest.raises(OsbsException, match=error_msg):
             RepoConfiguration(dir_path=str(tmpdir))
     else:
         RepoConfiguration(dir_path=str(tmpdir))
    def test_is_autorebuild_enabled(self, tmpdir, config_value, expected_value):

        with open(os.path.join(str(tmpdir), REPO_CONFIG_FILE), 'w') as f:
            if config_value is not None:
                f.write(dedent("""\
                    [autorebuild]
                    enabled={0}
                    """.format(config_value)))

        conf = RepoConfiguration(dir_path=str(tmpdir))
        assert conf.is_autorebuild_enabled() is expected_value
Exemple #4
0
    def test_is_autorebuild_enabled(self, tmpdir, config_value,
                                    expected_value):

        with open(os.path.join(str(tmpdir), REPO_CONFIG_FILE), 'w') as f:
            if config_value is not None:
                f.write(
                    dedent("""\
                    [autorebuild]
                    enabled={0}
                    """.format(config_value)))

        conf = RepoConfiguration(dir_path=str(tmpdir))
        assert conf.is_autorebuild_enabled() is expected_value
Exemple #5
0
    def test_tags_type_validation(self, tmpdir, tag, should_fail):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            f.write(dedent("""\
                tags:
                - {}
                """.format(tag)))

        if should_fail:
            match_msg = r"{} is not of type u?'string'".format(tag)
            with pytest.raises(OsbsException, match=match_msg):
                RepoConfiguration(dir_path=str(tmpdir))
        else:
            config = RepoConfiguration(dir_path=str(tmpdir))
            # "1.14" is the format written in yaml to represent a string. In
            # parsed result, it will be 1.14 without the double-quotes.
            assert [tag.replace('"', '')] == config.container['tags']
Exemple #6
0
    def test_image_labels_flatpak(self, tmpdir, modules, name, component,
                                  expected_name, expected_component):
        config_yaml = {
            'compose': {
                'modules': modules
            },
            'flatpak': {
                'id': 'org.gnome.Eog'
            }
        }
        if name:
            config_yaml['flatpak']['name'] = name
        if component:
            config_yaml['flatpak']['component'] = component

        yaml_file = tmpdir.join(REPO_CONTAINER_CONFIG)
        yaml_file.write(yaml.dump(config_yaml))

        repo_info = RepoInfo(configuration=RepoConfiguration(str(tmpdir)))

        if modules:
            _, name_label = repo_info.labels.get_name_and_value(
                Labels.LABEL_TYPE_NAME)
            _, component_label = repo_info.labels.get_name_and_value(
                Labels.LABEL_TYPE_COMPONENT)

            assert name_label == expected_name
            assert component_label == expected_component
        else:
            with pytest.raises(OsbsValidationException) as exc_info:
                assert repo_info.labels is None  # .labels access raises

            assert '"compose" config is missing "modules", required for Flatpak' in \
                   exc_info.value.message
Exemple #7
0
    def test_modules_nsv_validation(self, tmpdir, module_a_nsv, module_b_nsv, should_raise):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            f.write(dedent("""\
                compose:
                    modules:
                    - %s
                    - %s
                """ % (module_a_nsv, module_b_nsv)))

        if should_raise:
            with pytest.raises(ValueError):
                conf = RepoConfiguration(dir_path=str(tmpdir))
        else:
            conf = RepoConfiguration(dir_path=str(tmpdir))
            assert conf.container['compose']['modules'][0] == module_a_nsv
            assert conf.container['compose']['modules'][1] == module_b_nsv
Exemple #8
0
def get_repo_info(git_uri, git_ref, git_branch=None):
    with checkout_git_repo(git_uri, git_ref, git_branch) as code_dir:
        dfp = DockerfileParser(os.path.join(code_dir), cache_content=True)
        config = RepoConfiguration(dir_path=code_dir)
        tags_config = AdditionalTagsConfig(dir_path=code_dir,
                                           tags=config.container.get(
                                               'tags', set()))
    return RepoInfo(dfp, config, tags_config)
Exemple #9
0
    def test_explicit_params(self):
        df_parser = flexmock()
        configuration = RepoConfiguration()
        tags_config = AdditionalTagsConfig()

        repo_info = RepoInfo(df_parser, configuration, tags_config)
        assert repo_info.dockerfile_parser is df_parser
        assert repo_info.configuration is configuration
        assert repo_info.additional_tags is tags_config
Exemple #10
0
    def test_empty_yaml_compose(self, tmpdir):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            f.write(dedent("""\
                compose:
                """))

        conf = RepoConfiguration(dir_path=str(tmpdir))
        assert conf.container['compose'] is None
        assert conf.container_module_specs == []
 def test_deprecated_config(self, tmpdir, deprecated_key, deprecated_value,
                            deprecation_msg, caplog):
     with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
         f.write(
             dedent(f"""\
             {deprecated_key}: {deprecated_value}
             """))
     RepoConfiguration(dir_path=str(tmpdir))
     assert deprecation_msg in caplog.text
Exemple #12
0
    def test_invalid_yaml(self, tmpdir):
        yaml_file = tmpdir.join(REPO_CONTAINER_CONFIG)
        yaml_file.write('\n'.join(['hallo: 1', 'bye']))

        with pytest.raises(OsbsException) as exc_info:
            RepoConfiguration(dir_path=str(tmpdir))

        err_msg = str(exc_info.value)
        assert 'Failed to load or validate container file "{}"'.format(yaml_file) in err_msg
        assert "could not find expected ':'" in err_msg
        assert 'line 2, column 4:' in err_msg
Exemple #13
0
def get_repo_info(git_uri, git_ref, git_branch=None, depth=None):
    with checkout_git_repo(git_uri, commit=git_ref, branch=git_branch,
                           depth=depth) as code_dir_info:
        code_dir = code_dir_info.repo_path
        depth = code_dir_info.commit_depth
        dfp = DockerfileParser(os.path.join(code_dir), cache_content=True)
        config = RepoConfiguration(git_uri=git_uri, git_ref=git_ref, git_branch=git_branch,
                                   dir_path=code_dir, depth=depth)
        tags_config = AdditionalTagsConfig(dir_path=code_dir,
                                           tags=config.container.get('tags', set()))
    repo_info = RepoInfo(dfp, config, tags_config)
    return repo_info
Exemple #14
0
 def test_container_module_specs(self, tmpdir, module_nsv, should_raise, expected):
     with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
         f.write(dedent("""\
             compose:
                 modules:
                 - %s
             """ % module_nsv))
     if should_raise:
         with pytest.raises(ValueError):
             conf = RepoConfiguration(dir_path=str(tmpdir))
     else:
         conf = RepoConfiguration(dir_path=str(tmpdir))
         assert conf.container['compose']['modules'][0] == module_nsv
         spec = conf.container_module_specs[0]
         params = module_nsv.split(':')
         assert spec.name == expected[0]
         assert spec.stream == expected[1]
         if len(params) > 2:
             assert spec.version == expected[2]
             if len(params) > 3:
                 assert spec.context == expected[3]
         assert spec.profile == expected[4]
Exemple #15
0
    def test_flatpak_base_image(self, tmpdir, set_base_image):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            if set_base_image:
                f.write(dedent("""\
                    flatpak:
                        base_image: fedora:28
                    """))

        config = RepoConfiguration(dir_path=str(tmpdir))
        if set_base_image:
            assert config.flatpak_base_image == "fedora:28"
        else:
            assert config.flatpak_base_image is None
Exemple #16
0
    def test_flatpak_component(self, tmpdir, set_component):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            if set_component:
                f.write(dedent("""\
                    flatpak:
                        component: mycomponent
                    """))

        config = RepoConfiguration(dir_path=str(tmpdir))
        if set_component:
            assert config.flatpak_component == "mycomponent"
        else:
            assert config.flatpak_component is None
Exemple #17
0
    def test_flatpak_name(self, tmpdir, set_name):
        with open(os.path.join(str(tmpdir), REPO_CONTAINER_CONFIG), 'w') as f:
            if set_name:
                f.write(dedent("""\
                    flatpak:
                        name: myname
                    """))

        config = RepoConfiguration(dir_path=str(tmpdir))
        if set_name:
            assert config.flatpak_name == "myname"
        else:
            assert config.flatpak_name is None
    def test_invalid_yaml(self, tmpdir):
        yaml_file = tmpdir.join(REPO_CONTAINER_CONFIG)
        yaml_file.write('\n'.join(['hallo: 1', 'bye']))

        with pytest.raises(OsbsException) as exc_info:
            RepoConfiguration(dir_path=str(tmpdir))

        err_msg = (
            'Failed to parse YAML file "{file_basename}": while scanning a simple key\n'
            '  in "{file}", line 2, column 1\n'
            "could not find expected ':'\n"
            '  in "{file}", line 2, column 4').format(
                file=yaml_file, file_basename=REPO_CONTAINER_CONFIG)

        assert str(exc_info.value) == err_msg
 def get_minimal_kwargs(self, git_args=None, conf_args=None):
     if not git_args:
         git_args = {}
     git_args.setdefault('git_uri', TEST_GIT_URI)
     if not conf_args:
         conf_args = {'build_from': 'image:buildroot:latest'}
     repo_conf = RepoConfiguration(**git_args)
     return {
         # Params needed to avoid exceptions.
         'base_image': 'base_image',
         'build_conf': Configuration(**conf_args),
         'name_label': 'name_label',
         'repo_info': RepoInfo(configuration=repo_conf),
         'user': TEST_USER,
     }
Exemple #20
0
    def test_base_image_flatpak(self, tmpdir, base_image):
        config_yaml = {
            'compose': {
                'modules': ['mod_name:mod_stream'],
            },
            'flatpak': {
                'id': 'org.gnome.Eog'
            }
        }
        if base_image:
            config_yaml['flatpak']['base_image'] = base_image

        yaml_file = tmpdir.join(REPO_CONTAINER_CONFIG)
        yaml_file.write(yaml.dump(config_yaml))

        repo_info = RepoInfo(configuration=RepoConfiguration(str(tmpdir)))

        assert repo_info.base_image == base_image
    def test_v2_all_values_and_json(self):
        repo_conf = RepoConfiguration(git_branch=TEST_GIT_BRANCH,
                                      git_ref=TEST_GIT_REF,
                                      git_uri=TEST_GIT_URI)
        repo_info = RepoInfo(configuration=repo_conf)
        build_conf = Configuration(conf_file=None,
                                   build_from='image:buildroot:latest',
                                   orchestrator_deadline=4,
                                   scratch=False,
                                   worker_deadline=3)

        # all values that BuildUserParams stores
        param_kwargs = {
            # 'arrangement_version': self.arrangement_version,  # calculated value
            'base_image': 'buildroot:old',
            # 'build_from': 'buildroot:old',  # only one of build_*
            'build_json_dir': INPUTS_PATH,
            # 'build_image': 'buildroot:latest',
            # 'build_imagestream': 'buildroot:name_label',
            'build_type': BUILD_TYPE_WORKER,
            'component': TEST_COMPONENT,
            'compose_ids': [1, 2],
            'filesystem_koji_task_id': TEST_FILESYSTEM_KOJI_TASK_ID,
            'flatpak': False,
            # 'flatpak_base_image': self.flatpak_base_image,  # not used with false flatpack
            # 'git_branch': TEST_GIT_BRANCH,
            # 'git_ref': TEST_GIT_REF,
            # 'git_uri': TEST_GIT_URI,
            'image_tag': 'user/None:none-0-0',
            # 'imagestream_name': TEST_IMAGESTREAM,
            'include_koji_repo': True,
            'isolated': False,
            'koji_parent_build': 'fedora-26-9',
            'koji_target': 'tothepoint',
            'operator_bundle_replacement_pullspecs': {
                'foo/fedora:30': 'bar/fedora@sha256:deadbeef'
            },
            # "orchestrator_deadline": 4,  # set in config
            'parent_images_digests': {
                'registry.fedorahosted.org/fedora:29': {
                    'x86_64':
                    'registry.fedorahosted.org/fedora@sha256:8b96f2f9f88179a065738b2b37'
                    '35e386efb2534438c2a2f45b74358c0f344c81'
                }
            },
            # 'name': self.name,  # calculated value
            'platform': 'x86_64',
            'platforms': [
                'x86_64',
            ],
            # 'reactor_config_map': 'reactor-config-map',  # set in config
            'reactor_config_override': 'reactor-config-override',
            'release': '29',
            # 'scratch': True,  # set in config
            'signing_intent': False,
            'task_id': TEST_KOJI_TASK_ID,
            # 'trigger_imagestreamtag': 'base_image:latest',  # generated from base_image
            'user': TEST_USER,
            # 'yum_repourls': ,  # not used with compose_ids
            # "worker_deadline": 3,  # set in config
        }
        # additional values that BuildUserParams requires but stores under different names
        param_kwargs.update({
            'build_conf': build_conf,
            'name_label': 'name_label',
            'repo_info': repo_info,
        })
        rand = '12345'
        timestr = '20170731111111'
        (flexmock(sys.modules['osbs.build.user_params']).should_receive(
            'utcnow').once().and_return(
                datetime.datetime.strptime(timestr, '%Y%m%d%H%M%S')))

        (flexmock(random).should_receive('randrange').once().with_args(
            10**(len(rand) - 1), 10**len(rand)).and_return(int(rand)))

        spec = BuildUserParams.make_params(**param_kwargs)
        expected_json = {
            "arrangement_version":
            REACTOR_CONFIG_ARRANGEMENT_VERSION,
            "base_image":
            "buildroot:old",
            "build_from":
            "image:buildroot:latest",
            "build_image":
            "buildroot:latest",
            "build_json_dir":
            INPUTS_PATH,
            "build_type":
            "worker",
            "component":
            TEST_COMPONENT,
            "compose_ids": [1, 2],
            "customize_conf":
            "worker_customize.json",
            "filesystem_koji_task_id":
            TEST_FILESYSTEM_KOJI_TASK_ID,
            "include_koji_repo":
            True,
            "git_branch":
            TEST_GIT_BRANCH,
            "git_ref":
            TEST_GIT_REF,
            "git_uri":
            TEST_GIT_URI,
            "image_tag":
            "{}/{}:tothepoint-{}-{}-x86_64".format(TEST_USER, TEST_COMPONENT,
                                                   rand, timestr),
            "imagestream_name":
            "name_label",
            "kind":
            "build_user_params",
            "koji_parent_build":
            "fedora-26-9",
            "koji_target":
            "tothepoint",
            "name":
            "path-master-cd1e4",
            'operator_bundle_replacement_pullspecs': {
                'foo/fedora:30': 'bar/fedora@sha256:deadbeef'
            },
            "orchestrator_deadline":
            4,
            'parent_images_digests': {
                'registry.fedorahosted.org/fedora:29': {
                    'x86_64':
                    'registry.fedorahosted.org/fedora@sha256:8b96f2f9f88179a065738b2b37'
                    '35e386efb2534438c2a2f45b74358c0f344c81'
                }
            },
            "platform":
            "x86_64",
            "platforms": ["x86_64"],
            "reactor_config_override":
            "reactor-config-override",
            "release":
            "29",
            "trigger_imagestreamtag":
            "buildroot:old",
            "user":
            TEST_USER,
            "worker_deadline":
            3,
        }
        assert spec.to_json() == json.dumps(expected_json, sort_keys=True)

        spec2 = BuildUserParams.from_json(spec.to_json())
        assert spec2.to_json() == json.dumps(expected_json, sort_keys=True)
Exemple #22
0
 def get_repo_info(*args, **kwargs):
     # will fail because of invalid yaml
     return RepoConfiguration(dir_path=str(tmpdir))
 def test_default_values(self):
     conf = RepoConfiguration()
     assert conf.is_autorebuild_enabled() is False
Exemple #24
0
 def test_default_values(self):
     conf = RepoConfiguration()
     assert conf.is_autorebuild_enabled() is False