Exemple #1
0
def test_config_exceptions_orderable(env):
    env.configure()
    c = env.get_root("zeo", env.hosts['localhost']).component

    import sys

    try:
        raise ValueError("Test")
    except Exception:
        exc_type, ex, tb = sys.exc_info()

    exceptions = [
        batou.ConfigurationError("test", None),
        batou.ConfigurationError("test", c),
        batou.ConversionError(c, "key", 123, int, "invalid int"),
        batou.MissingOverrideAttributes(c, ["sadf"]),
        batou.DuplicateComponent(c.root, c.root),
        batou.UnknownComponentConfigurationError(c.root, ex, tb),
        batou.UnusedResources({"asdf": [(c.root, 1)]}),
        batou.UnsatisfiedResources({"asdf": [c.root]}),
        batou.MissingEnvironment(env),
        batou.MissingComponent("asdf", "localhost"),
        batou.SuperfluousSection("asdf"),
        batou.SuperfluousComponentSection("asdf"),
        batou.SuperfluousSecretsSection("asdf"),
        batou.CycleErrorDetected(ValueError()),
        batou.NonConvergingWorkingSet([c]),
        batou.DeploymentError(),
        batou.DuplicateHostMapping("host", "map1", "map2"),
        batou.RepositoryDifferentError("asdf", "bsdf"),
        batou.DuplicateHostError("localhost"),
        batou.InvalidIPAddressError("asdf"), ]

    # Ensure all exceptions can be compared
    for x in exceptions:
        for y in exceptions:
            x.sort_key < y.sort_key
Exemple #2
0
    def configure(self):
        super().configure()

        if isinstance(self.mode, str):
            try:
                self.mode = int(self.mode, 8)
            except ValueError:
                try:
                    self.mode = convert_mode(self.mode)
                except Exception as e:
                    raise batou.ConversionError(self, 'mode', self.mode,
                                                convert_mode, e)

        elif isinstance(self.mode, int):
            pass
        else:
            raise batou.ConfigurationError(
                f'`mode` is required and `{self.mode!r}` is not a valid value.`'
            )
Exemple #3
0
    def __init__(self,
                 conversion=None,
                 *,
                 default=ATTRIBUTE_NODEFAULT,
                 default_conf_string=ATTRIBUTE_NODEFAULT,
                 expand=True,
                 map=False):
        if isinstance(conversion, str):
            conversion = getattr(self, "convert_{}".format(conversion))
        self.conversion = conversion

        if (default is not ATTRIBUTE_NODEFAULT
                and default_conf_string is not ATTRIBUTE_NODEFAULT):
            raise batou.ConfigurationError(
                'Attributes only support one of those parameters:'
                ' either `default` or `default_conf_string`.', self)
        self.default = default
        self.default_conf_string = default_conf_string
        self.expand = expand
        self.map = map
        self.instances = weakref.WeakKeyDictionary()