Пример #1
0
def test_config_invalidate():
    """ Make sure a bad validation breaks """
    obj = load_config('profiles', 'test_profile_bad')
    try:
        validate_object('config', obj, "profiles/test_profile_bad")
        assert True is False
    except InvalidConfigError as e:
        assert e.config_name == "profiles/test_profile_bad"
Пример #2
0
def test_config_load():
    """ Make sure we can cleanly load a config """
    obj = load_config('profiles', 'test_profile')
    comp = {
        "incoming": "/dev/null",
        "method": "local",
        "meta": "ubuntu"
    }
    for key in comp:
        assert obj[key] == comp[key]
Пример #3
0
def check_allowed_distribution(changes, profile, interface):
    """
    The ``allowed-distribution`` checker is a stock dput checker that checks
    packages intended for upload for a valid upload distribution.

    Profile key: none

    Example profile::

        {
            ...
            "allowed_distributions": "(?!UNRELEASED)",
            "distributions": ["unstable", "testing"],
            "disallowed_distributions": []
            ...
        }

    The allowed_distributions key is in Python ``re`` syntax.
    """
    allowed_block = profile.get("allowed-distribution", {})
    suite = changes["Distribution"]
    if "allowed_distributions" in profile:
        srgx = profile["allowed_distributions"]
        if re.match(srgx, suite) is None:
            logger.debug("Distribution does not %s match '%s'" % (suite, profile["allowed_distributions"]))
            raise BadDistributionError("'%s' doesn't match '%s'" % (suite, srgx))

    if "distributions" in profile:
        allowed_dists = profile["distributions"]
        if suite not in allowed_dists.split(","):
            raise BadDistributionError("'%s' doesn't contain distribution '%s'" % (suite, profile["distributions"]))

    if "disallowed_distributions" in profile:
        disallowed_dists = profile["disallowed_distributions"]
        if suite in disallowed_dists:
            raise BadDistributionError("'%s' is in '%s'" % (suite, disallowed_dists))

    if "codenames" in profile and profile["codenames"]:
        codenames = load_config("codenames", profile["codenames"])
        blocks = allowed_block.get("codename-groups", [])
        if blocks != []:
            failed = True
            for block in blocks:
                names = codenames.get(block, [])
                if suite in names:
                    failed = False

            if failed:
                raise BadDistributionError("`%s' not in the codename group" % (suite))
Пример #4
0
    def get_config(self, name):
        """
        See :meth:`dput.config.AbstractConfig.get_config`
        """
        kwargs = {
            "default": {}
        }

        configs = self.configs
        if configs is not None:
            kwargs['configs'] = configs

        kwargs['config_cleanup'] = False

        profile = load_config(
            'profiles',
            name,
            **kwargs
        )
        logger.trace("name: %s - %s / %s" % (name, profile, kwargs))
        repls = self.replacements
        for thing in profile:
            val = profile[thing]
            if not isinstance(val, _basestr_type):
                continue
            for repl in repls:
                if repl in val:
                    val = val.replace("%%(%s)s" % (repl), repls[repl])
            profile[thing] = val

        ret = {}
        ret.update(profile)
        ret['name'] = name

        for key in ret:
            val = ret[key]
            if isinstance(val, _basestr_type):
                if "%(" in val and ")s" in val:
                    raise DputConfigurationError(
                        "Half-converted block: %s --> %s" % (
                            key,
                            val
                        )
                    )
        return ret
Пример #5
0
def get_hooks(profile):
    for hook in profile['hooks']:
        conf = load_config('hooks', hook)
        validate_object('plugin', conf, 'hooks/%s' % (hook))
        yield (hook, conf)
Пример #6
0
def test_config_validate():
    """ Make sure we can validate a good config """
    obj = load_config('profiles', 'test_profile')
    validate_object('config', obj, "profiles/test_profile")