Пример #1
0
    def test_user_params_bad_none_flatpak(self, missing_arg):
        kwargs = self.get_minimal_kwargs()
        kwargs['flatpak'] = False
        kwargs.pop(missing_arg)

        with pytest.raises(OsbsValidationException):
            BuildUserParams.make_params(**kwargs)
Пример #2
0
    def test_v2_compose_ids_and_signing_intent(self, signing_intent,
                                               compose_ids, yum_repourls, exc):
        kwargs = self.get_minimal_kwargs()
        if signing_intent:
            kwargs['signing_intent'] = signing_intent
        if compose_ids:
            kwargs['compose_ids'] = compose_ids
        if yum_repourls:
            kwargs['yum_repourls'] = yum_repourls

        kwargs.update({
            'git_uri': 'https://github.com/user/reponame.git',
            'git_branch': 'master',
        })

        if exc:
            with pytest.raises(exc):
                BuildUserParams.make_params(**kwargs)
        else:
            spec = BuildUserParams.make_params(**kwargs)

            if yum_repourls:
                assert spec.yum_repourls == yum_repourls
            if signing_intent:
                assert spec.signing_intent == signing_intent
            if compose_ids:
                assert spec.compose_ids == compose_ids
Пример #3
0
    def test_user_params_bad_build_from(self):
        # does not have an "image:" prefix:
        conf_args = {'build_from': 'registry.example.com/buildroot'}
        kwargs = self.get_minimal_kwargs(conf_args=conf_args)

        with pytest.raises(OsbsValidationException) as e:
            BuildUserParams.make_params(**kwargs)
        assert 'build_from must be "source_type:source_value"' in str(e.value)
Пример #4
0
    def test_missing_build_opts(self):
        conf_args = {
            'build_from': None,
            'build_image': None,
            'build_imagestream': None,
        }
        kwargs = self.get_minimal_kwargs(conf_args=conf_args)

        with pytest.raises(OsbsValidationException):
            BuildUserParams.make_params(**kwargs)
Пример #5
0
    def test_validate_missing_required(self):
        kwargs = self.get_minimal_kwargs()
        kwargs['user'] = None
        spec = BuildUserParams.make_params(**kwargs)

        with pytest.raises(OsbsValidationException):
            spec.validate()
Пример #6
0
    def test_v2_spec_name2(self):
        git_args = {'git_branch': TEST_GIT_BRANCH}
        kwargs = self.get_minimal_kwargs(git_args=git_args)

        spec = BuildUserParams.make_params(**kwargs)

        assert spec.name.startswith('path-master')
Пример #7
0
    def test_v2_image_tag(self, rand, timestr, platform):
        kwargs = self.get_minimal_kwargs()
        kwargs.update({
            'component': 'foo',
            'koji_target': 'tothepoint',
        })
        if platform:
            kwargs['platform'] = platform

        (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(**kwargs)

        img_tag = '{user}/{component}:{koji_target}-{random_number}-{time_string}'
        if platform:
            img_tag += '-{platform}'
        img_tag = img_tag.format(random_number=rand,
                                 time_string=timestr,
                                 **kwargs)
        assert spec.image_tag == img_tag
Пример #8
0
    def test_render_tag_from_config(self, tmpdir, from_container_yaml, extra_args,
                                    has_platform_tag, extra_tags, primary_tags, floating_tags):
        kwargs = get_sample_prod_params(BUILD_TYPE_WORKER)
        kwargs.pop('platforms', None)
        kwargs.pop('platform', None)
        expected_primary = set(primary_tags)
        expected_floating = set(floating_tags)
        exclude_for_override = set(['latest', '{version}'])

        if from_container_yaml:
            expected_floating -= exclude_for_override

        extra_args['tags_from_yaml'] = from_container_yaml
        extra_args['additional_tags'] = extra_tags
        kwargs.update(extra_args)

        user_params = BuildUserParams.make_params(**kwargs)
        build_json = PluginsConfiguration(user_params).render()

        plugins = get_plugins_from_build_json(build_json)

        assert get_plugin(plugins, 'postbuild_plugins', 'tag_from_config')
        tag_suffixes = plugin_value_get(plugins, 'postbuild_plugins', 'tag_from_config',
                                        'args', 'tag_suffixes')
        assert len(tag_suffixes['unique']) == 1
        if has_platform_tag:
            unique_tag_suffix = tag_suffixes['unique'][0]
            assert unique_tag_suffix.endswith('-x86_64') == has_platform_tag
        assert len(tag_suffixes['primary']) == len(expected_primary)
        assert set(tag_suffixes['primary']) == expected_primary
        assert len(tag_suffixes['floating']) == len(expected_floating)
        assert set(tag_suffixes['floating']) == expected_floating
Пример #9
0
    def test_render_prod_custom_site_plugin_enable(self, tmpdir):
        # Test to make sure that when we attempt to enable a plugin, it is
        # actually enabled in the JSON for the build_request after running
        # build_request.render()
        self.mock_repo_info()
        sample_params = get_sample_prod_params()
        user_params = BuildUserParams.make_params(**sample_params)
        plugins_conf = PluginsConfiguration(user_params)

        plugin_type = "exit_plugins"
        plugin_name = "testing_exit_plugin"
        plugin_args = {"foo": "bar"}

        plugins_conf.pt.customize_conf['enable_plugins'].append({
            "plugin_type": plugin_type,
            "plugin_name": plugin_name,
            "plugin_args": plugin_args})

        build_json = plugins_conf.render()
        plugins = get_plugins_from_build_json(build_json)

        assert {
                "name": plugin_name,
                "args": plugin_args
        } in plugins[plugin_type]
Пример #10
0
 def get_user_params(self, component=None, req_labels=None, **kwargs):
     req_labels = req_labels or {}
     user_component = component or req_labels[Labels.LABEL_TYPE_COMPONENT]
     return BuildUserParams.make_params(
         build_conf=self.os_conf,
         component=user_component,
         name_label=req_labels[Labels.LABEL_TYPE_NAME],
         **kwargs)
Пример #11
0
    def test_make_params_keeps_defaults(self):
        kwargs = self.get_minimal_kwargs()
        params = BuildUserParams.make_params(**kwargs)

        assert params.arrangement_version == REACTOR_CONFIG_ARRANGEMENT_VERSION
        assert params.buildroot_is_imagestream is False
        assert params.customize_conf == DEFAULT_CUSTOMIZE_CONF
        # assert params.git_ref == 'master'  # set from repo_info
        assert params.include_koji_repo is False
Пример #12
0
    def test_render_prod_custom_site_plugin_override(self):
        # Test to make sure that when we attempt to override a plugin's args,
        # they are actually overridden in the JSON for the build_request
        # after running build_request.render()
        self.mock_repo_info()
        sample_params = get_sample_prod_params()
        base_user_params = BuildUserParams.make_params(**sample_params)
        base_plugins_conf = PluginsConfiguration(base_user_params)
        base_build_json = base_plugins_conf.render()
        base_plugins = get_plugins_from_build_json(base_build_json)

        plugin_type = "exit_plugins"
        plugin_name = "koji_import"
        plugin_args = {"foo": "bar"}

        for plugin_dict in base_plugins[plugin_type]:
            if plugin_dict['name'] == plugin_name:
                plugin_index = base_plugins[plugin_type].index(plugin_dict)

        user_params = BuildUserParams.make_params(**sample_params)
        plugins_conf = PluginsConfiguration(user_params)
        plugins_conf.pt.customize_conf['enable_plugins'].append({
            "plugin_type":
            plugin_type,
            "plugin_name":
            plugin_name,
            "plugin_args":
            plugin_args
        })
        build_json = plugins_conf.render()
        plugins = get_plugins_from_build_json(build_json)

        assert {
            "name": plugin_name,
            "args": plugin_args
        } in plugins[plugin_type]

        assert base_plugins[plugin_type][plugin_index]['name'] == \
            plugin_name
        assert plugins[plugin_type][plugin_index]['name'] == plugin_name
Пример #13
0
    def test_prod_custom_base_image(self, tmpdir):
        kwargs = get_sample_prod_params()
        kwargs['base_image'] = 'koji/image-build'
        kwargs['yum_repourls'] = ["http://example.com/my.repo"]

        self.mock_repo_info()
        user_params = BuildUserParams.make_params(**kwargs)
        build_json = PluginsConfiguration(user_params).render()
        plugins = get_plugins_from_build_json(build_json)

        get_plugin(plugins, 'prebuild_plugins', 'pull_base_image')

        add_filesystem_args = plugin_value_get(
            plugins, 'prebuild_plugins', 'add_filesystem', 'args')
        assert add_filesystem_args['repos'] == kwargs['yum_repourls']
        assert add_filesystem_args['from_task_id'] == kwargs['filesystem_koji_task_id']
        assert add_filesystem_args['koji_target'] == kwargs['koji_target']
Пример #14
0
 def get_plugins_from_buildrequest(self, build_request, template):
     conf_kwargs = {
        'build_from': 'image:test',
        'reactor_config_map': 'reactor-config-map',
     }
     kwargs = {
         'build_json_dir': INPUTS_PATH,
         'git_uri': TEST_GIT_URI,
         'git_ref': TEST_GIT_REF,
         'git_branch': TEST_GIT_BRANCH,
         'user': '******',
         'build_type': template.split('_')[0],
         'build_conf': Configuration(conf_file=None, **conf_kwargs),
         'base_image': 'test',
         'name_label': 'test',
     }
     user_params = BuildUserParams.make_params(**kwargs)
     build_request.set_params(user_params)
     return PluginsConfiguration(build_request.user_params).pt.template
Пример #15
0
    def test_worker_custom_base_image(self, tmpdir):
        self.mock_repo_info()
        kwargs = get_sample_prod_params(BUILD_TYPE_WORKER)
        kwargs['base_image'] = 'koji/image-build'
        kwargs['yum_repourls'] = ["http://example.com/my.repo"]
        kwargs.pop('platforms', None)
        kwargs['platform'] = 'ppc64le'

        user_params = BuildUserParams.make_params(**kwargs)
        build_json = PluginsConfiguration(user_params).render()
        plugins = get_plugins_from_build_json(build_json)

        get_plugin(plugins, 'prebuild_plugins', 'pull_base_image')

        add_filesystem_args = plugin_value_get(plugins, 'prebuild_plugins',
                                               'add_filesystem', 'args')
        assert add_filesystem_args['repos'] == kwargs['yum_repourls']
        assert add_filesystem_args['from_task_id'] == kwargs['filesystem_koji_task_id']
        assert add_filesystem_args['architecture'] == kwargs['platform']
        assert add_filesystem_args['koji_target'] == kwargs['koji_target']
Пример #16
0
    def test_render_all_code_paths(self, caplog):
        # Alter the plugins configuration so that all code paths are exercised
        sample_params = get_sample_prod_params()
        sample_params['scratch'] = True
        sample_params['parent_images_digests'] = True
        user_params = BuildUserParams.make_params(**sample_params)
        plugins_conf = PluginsConfiguration(user_params)

        plugins_conf.pt.customize_conf['disable_plugins'].append(
            {
                "plugin_type": "postbuild_plugins",
                "plugin_name": "tag_from_config"
            }
        )
        plugins_conf.pt.customize_conf['disable_plugins'].append(
            {
                "plugin_type": "prebuild_plugins",
                "plugin_name": "add_labels_in_dockerfile"
            }
        )
        plugins_conf.pt.customize_conf['disable_plugins'].append(
            {
                "bad_plugin_type": "postbuild_plugins",
                "bad_plugin_name": "tag_from_config"
            },
        )
        plugins_conf.pt.customize_conf['enable_plugins'].append(
            {
                "bad_plugin_type": "postbuild_plugins",
                "bad_plugin_name": "tag_from_config"
            },
        )
        build_json = plugins_conf.render()
        plugins = get_plugins_from_build_json(build_json)

        log_messages = [l.getMessage() for l in caplog.records]
        assert 'Invalid custom configuration found for disable_plugins' in log_messages
        assert 'Invalid custom configuration found for enable_plugins' in log_messages
        assert plugin_value_get(plugins, 'prebuild_plugins', 'pull_base_image', 'args',
                                'parent_images_digests')
Пример #17
0
    def test_render_prod_custom_site_plugin_disable(self):
        # Test to make sure that when we attempt to disable a plugin, it is
        # actually disabled in the JSON for the build_request after running
        # build_request.render()
        sample_params = get_sample_prod_params()
        user_params = BuildUserParams.make_params(**sample_params)
        plugins_conf = PluginsConfiguration(user_params)

        plugin_type = "postbuild_plugins"
        plugin_name = "tag_from_config"

        plugins_conf.pt.customize_conf['disable_plugins'].append(
            {
                "plugin_type": plugin_type,
                "plugin_name": plugin_name
            }
        )
        build_json = plugins_conf.render()
        plugins = get_plugins_from_build_json(build_json)

        for plugin in plugins[plugin_type]:
            if plugin['name'] == plugin_name:
                assert False
Пример #18
0
    def test_make_params_keeps_defaults(self):
        kwargs = self.get_minimal_kwargs()
        params = BuildUserParams.make_params(**kwargs)

        assert params.include_koji_repo is False
Пример #19
0
    def test_user_params_bad_compose_ids(self):
        kwargs = self.get_minimal_kwargs()
        kwargs['compose_ids'] = True

        with pytest.raises(OsbsValidationException):
            BuildUserParams.make_params(**kwargs)
Пример #20
0
    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)
Пример #21
0
def get_sample_user_params(build_type=BUILD_TYPE_ORCHESTRATOR, conf_args=None, extra_args=None):
    sample_params = get_sample_prod_params(build_type, conf_args, extra_args)
    user_params = BuildUserParams.make_params(**sample_params)
    return user_params
Пример #22
0
 def test_incomplete_set_params(self, skip_param, message):
     kwargs = self.get_minimal_kwargs()
     kwargs[skip_param] = None
     with pytest.raises(OsbsValidationException) as exc:
         BuildUserParams.make_params(**kwargs)
         assert message in exc.message