Ejemplo n.º 1
0
 def test_dict_path_without_dots(self):
     """
     The first path entry shouldn't have a dot as prefix.
     """
     schema = Dict(Int(), Dict(Int(), Int()))
     error = self.assertRaises(SchemaError, schema.coerce, {1: {
         2: "hi"
     }}, [])
     self.assertEquals(str(error), "1.2: expected int, got 'hi'")
Ejemplo n.º 2
0
 def test_dict_bad_value_unstringifiable(self):
     """
     If the path can't be stringified, it's repr()ed.
     """
     a = u"\N{HIRAGANA LETTER A}"
     schema = Dict(Unicode(), Int())
     error = self.assertRaises(SchemaError, schema.coerce, {a: "hi"}, PATH)
     self.assertEquals(str(error),
                       "<path>.u'\\u3042': expected int, got 'hi'")
Ejemplo n.º 3
0
        OneOf(
            Constant("string"),
            Constant("str"),  # Obsolete
            Constant("int"),
            Constant("float")),
        "default":
        OneOf(String(), Int(), Float()),
        "description":
        String(),
    },
    optional=["default", "description"],
)

# Schema used to validate ConfigOptions specifications
CONFIG_SCHEMA = KeyDict({
    "options": Dict(String(), OPTION_SCHEMA),
})

WARNED_STR_IS_OBSOLETE = False


class ConfigOptions(object):
    """Represents the configuration options exposed by a charm.

    The intended usage is that Charm provide access to these objects
    and then use them to `validate` inputs provided in the `juju
    set` and `juju deploy` code paths.
    """
    def __init__(self):
        self._data = {}
Ejemplo n.º 4
0
 def test_dict_bad_value(self):
     error = self.assertRaises(SchemaError,
                               Dict(Int(), Int()).coerce, {32: "hi"}, PATH)
     self.assertEquals(str(error), "<path>.32: expected int, got 'hi'")
Ejemplo n.º 5
0
 def test_dict_bad_key(self):
     error = self.assertRaises(SchemaError,
                               Dict(Int(), Int()).coerce, {"hi": 32}, PATH)
     self.assertEquals(str(error), "<path>: expected int, got 'hi'")
Ejemplo n.º 6
0
 def test_dict_coerces(self):
     self.assertEquals(
         Dict(DummySchema(), DummySchema()).coerce({32: object()}, PATH),
         {"hello!": "hello!"})
Ejemplo n.º 7
0
 def test_dict(self):
     self.assertEquals(
         Dict(Int(), String()).coerce({32: "hello."}, PATH), {32: "hello."})
Ejemplo n.º 8
0
            # readily support. So just do it here first, then
            # coerce.
            if "limit" not in value:
                value["limit"] = self.limit
            if "optional" not in value:
                value["optional"] = False
            return INTERFACE_SCHEMA.coerce(value, path)


SCHEMA = KeyDict(
    {
        "name": UTF8_SCHEMA,
        "revision": Int(),
        "summary": UTF8_SCHEMA,
        "description": UTF8_SCHEMA,
        "peers": Dict(UTF8_SCHEMA, InterfaceExpander(limit=1)),
        "provides": Dict(UTF8_SCHEMA, InterfaceExpander(limit=None)),
        "requires": Dict(UTF8_SCHEMA, InterfaceExpander(limit=1)),
    },
    optional=set(["provides", "requires", "peers", "revision"]))


class MetaData(object):
    """Represents the charm info file.

    The main metadata for a charm (name, revision, etc) is maintained
    in the charm's info file.  This class is able to parse,
    validate, and provide access to data in the info file.
    """
    def __init__(self, path=None):
        self._data = {}
Ejemplo n.º 9
0
 "environments": Dict(String(), SelectDict("type", {
     "ec2": KeyDict({"control-bucket": String(),
                     "admin-secret": String(),
                     "access-key": String(),
                     "secret-key": String(),
                     "region": OneOf(
                         Constant("us-east-1"),
                         Constant("us-west-1"),
                         Constant("us-west-2"),
                         Constant("eu-west-1"),
                         Constant("sa-east-1"),
                         Constant("ap-northeast-1"),
                         Constant("ap-southeast-1")),
                     "default-instance-type": String(),
                     "default-ami": String(),
                     "ec2-uri": String(),
                     "s3-uri": String(),
                     "placement": OneOf(
                             Constant("unassigned"),
                             Constant("local")),
                     "default-series": String()},
                    optional=["access-key", "secret-key",
                              "default-instance-type", "default-ami",
                              "region", "ec2-uri", "s3-uri", "placement"]),
     "orchestra": KeyDict({"orchestra-server": String(),
                           "orchestra-user": String(),
                           "orchestra-pass": String(),
                           "admin-secret": String(),
                           "acquired-mgmt-class": String(),
                           "available-mgmt-class": String(),
                           "storage-url": String(),
                           "storage-user": String(),
                           "storage-pass": String(),
                           "placement": String(),
                           "default-series": String()},
                          optional=["storage-url", "storage-user",
                                    "storage-pass", "placement"]),
     "local": KeyDict({"admin-secret": String(),
                     "data-dir": String(),
                     "placement": Constant("local"),
                     "default-series": String()},
                    optional=["placement"]),
     "dummy": KeyDict({})}))},