Esempio n. 1
0
    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        Base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()
Esempio n. 2
0
    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)
Esempio n. 3
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Esempio n. 4
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Esempio n. 5
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Esempio n. 6
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Esempio n. 7
0
    def test_list_append(self):
        c = Config()

        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.append:
                - 4
                - 5
                - 6
            """)
        self.failUnlessEqual(c.get()['foo'], [1,2,3,4,5,6])
Esempio n. 8
0
    def test_list_append(self):
        c = Config()

        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.append:
                - 4
                - 5
                - 6
            """)
        self.failUnlessEqual(c.get()['foo'], [1, 2, 3, 4, 5, 6])
Esempio n. 9
0
    def test_list_remove(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.remove:
                - 1
                - 2
                - 3
                - 5
            """)

        self.failUnlessEqual(c.get()['foo'], [])
Esempio n. 10
0
    def test_list_remove(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            foo.remove:
                - 1
                - 2
                - 3
                - 5
            """)

        self.failUnlessEqual(c.get()['foo'], [])
Esempio n. 11
0
    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        t.backend.base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()
Esempio n. 12
0
    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)
Esempio n. 13
0
    def test_simple_replace(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)
        c.load("""
            foo: 3
            qux: 1
            """)

        self.failUnlessEqual(c.get()['foo'], 3)
        self.failUnlessEqual(c.get()['bar'], 2)
        self.failUnlessEqual(c.get()['qux'], 1)
Esempio n. 14
0
    def test_nested_map_update(self):
        c = Config()
        c.load("""
            foo:
                foo: 1
                bar: 2
            bar: 2
            """)
        c.load("""
            foo:
                foo: 2
                baz: 3
            baz: 3
            """)

        self.failUnlessEqual(c.get()['foo']['foo'], 2)
        self.failUnlessEqual(c.get()['foo']['bar'], 2)
        self.failUnlessEqual(c.get()['foo']['baz'], 3)
        self.failUnlessEqual(c.get()['baz'], 3)
Esempio n. 15
0
    def provision(self, **kwargs):
        register_builtin_keys()

        self.bootstrap()

        conf = Config()

        sk = dict(
            sidekick={
                "host": {
                    "ips": dict(util.interfaces()),
                },
                "primaryip": self.machine.get_ip(),
            })
        conf.load(StringIO.StringIO(dump(sk)))

        if "recipe" in kwargs:
            conf.load_uri(kwargs['recipe'])

        if "conf" in kwargs:
            conf.load(StringIO.StringIO(kwargs['conf']))

        class opts:
            log_level = "info"
            logfile = "-"
            host = "%s@%s:%s" % self.machine.get_ssh_details()
            user = "******"
            ypath = kwargs.get("path", [])
            simulate = False
            verbose = False
            resume = True
            no_resume = False
            env_passthrough = []

        ctx = RunContext([], opts)
        ctx.set_config(conf)

        r = RemoteRunner()
        #r.load_host_keys(
        r.set_missing_host_key_policy("no")

        rv = r.run(ctx)

        return rv
Esempio n. 16
0
    def test_simple_replace(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)
        c.load("""
            foo: 3
            qux: 1
            """)

        self.failUnlessEqual(c.get()['foo'], 3)
        self.failUnlessEqual(c.get()['bar'], 2)
        self.failUnlessEqual(c.get()['qux'], 1)
Esempio n. 17
0
    def test_nested_map_update(self):
        c = Config()
        c.load("""
            foo:
                foo: 1
                bar: 2
            bar: 2
            """)
        c.load("""
            foo:
                foo: 2
                baz: 3
            baz: 3
            """)

        self.failUnlessEqual(c.get()['foo']['foo'], 2)
        self.failUnlessEqual(c.get()['foo']['bar'], 2)
        self.failUnlessEqual(c.get()['foo']['baz'], 3)
        self.failUnlessEqual(c.get()['baz'], 3)
Esempio n. 18
0
    def provision(self, **kwargs):
        register_builtin_keys()

        self.bootstrap()

        conf = Config()

        sk = dict(sidekick={
            "host": {
                "ips": dict(util.interfaces()),
                },
            "primaryip": self.machine.get_ip(),
            })
        conf.load(StringIO.StringIO(dump(sk)))

        if "recipe" in kwargs:
            conf.load_uri(kwargs['recipe'])

        if "conf" in kwargs:
            conf.load(StringIO.StringIO(kwargs['conf']))

        class opts:
            log_level = "info"
            logfile = "-"
            host = "%s@%s:%s" % self.machine.get_ssh_details()
            user = "******"
            ypath = kwargs.get("path", [])
            simulate = False
            verbose = False
            resume = True
            no_resume = False
            env_passthrough = []

        ctx = RunContext([], opts)
        ctx.set_config(conf)


        r = RemoteRunner()
        #r.load_host_keys(
        r.set_missing_host_key_policy("no")

        rv = r.run(ctx)

        return rv
Esempio n. 19
0
    def test_chaos(self):
        path = os.path.dirname(__file__)
        raw = open(os.path.join(path, "test_chaosmonkey.yay")).read()

        for i in range(1000):
            idx = random.randint(0, len(raw) - 1)
            ln = random.randint(1, 100)

            action = random.choice(["delete", "add"])

            if action == "delete":
                copy = self.delete(raw, idx, ln)
            elif action == "add":
                copy = self.add(raw, idx, ln)

            try:
                MemOpener.add("mem://test_chaosmonkey", copy)
                Config().load_uri("mem://test_chaosmonkey")
            except Error, e:
                pass
            except Exception, e:
                print type(e), idx, len, action
                raise
Esempio n. 20
0
    def test_override_literal(self):
        config = Config()
        config.load(test_yay)
        config.add(dict(injected_data="xyz"))

        self.failUnlessEqual(config.get()["result"], "xyz")
Esempio n. 21
0
class TestDjangoYay(TestDjangoBase):

    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)

    def test_all_cars(self):
        self.config.load("""test: ${metadata.Car}""")
        l = self.config.get()["test"]

        self.failUnless(isinstance(l[0], dict))
        self.failUnlessEqual(l[0]["name"], "fred")

    def test_foreach_car(self):
        self.config.load("""
            test.foreach c in metadata.Car: ${c.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["fred", "bobby"])

    def test_foreach_car_parts(self):
        self.config.load("""
            test.foreach c in metadata.Car:
              .foreach p in c.parts: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel', 'brake', 'badger'])

    def test_foreach_car_parts_if(self):
        self.config.load("""
            x: badger
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["badger"])

    def test_foreach_car_parts_if_failing(self):
        self.config.load("""
            x: badge
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_model_callable(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_callable: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel','brake','badger'])

    def test_model_callable_generator(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_generator: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ['wheel','brake','badger'])
Esempio n. 22
0
def bind(foo):
    c = Config()
    c.add({"test": foo})
    return c.test
Esempio n. 23
0
class TestDb(unittest.TestCase):
    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        Base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()

    def tearDown(self):
        Base.metadata.drop_all(self.t.backend.engine)

    def test_foreach_host(self):
        self.config.load("""
            test.foreach h in metadata.host: ${h.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["wonderflonium"])

    def test_foreach_host_service(self):
        self.config.load("""
            test.foreach h in metadata.host:
              .foreach s in h.services: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if(self):
        self.config.load("""
            branch: /trunk
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if_failing(self):
        self.config.load("""
            branch: /trun
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])
Esempio n. 24
0
 def create_from_list(cls, specification):
     """ Given a list of types and parameters, build a resource bundle """
     c = Config()
     c.add({"resources": specification})
     return cls.create_from_yay_expression(c.resources)
Esempio n. 25
0
def load_config(uri):
    basedir = os.path.dirname(uri)
    c = Config(searchpath=[basedir])
    c.load_uri(uri)
    return ProxyConfig(c.get())
Esempio n. 26
0
class TestDjangoYay(TestDjangoBase):
    def setUp(self):
        TestDjangoBase.setUp(self)

        self.config = Config()
        self.config.load("""
            metadata.bind:
                type: djangostore
                model: yay.tests.dj.models
            """)

    def test_all_cars(self):
        self.config.load("""test: ${metadata.Car}""")
        l = self.config.get()["test"]

        self.failUnless(isinstance(l[0], dict))
        self.failUnlessEqual(l[0]["name"], "fred")

    def test_foreach_car(self):
        self.config.load("""
            test.foreach c in metadata.Car: ${c.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["fred", "bobby"])

    def test_foreach_car_parts(self):
        self.config.load("""
            test.foreach c in metadata.Car:
              .foreach p in c.parts: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])

    def test_foreach_car_parts_if(self):
        self.config.load("""
            x: badger
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["badger"])

    def test_foreach_car_parts_if_failing(self):
        self.config.load("""
            x: badge
            test.foreach c in metadata.Car:
              .foreach p in c.parts if p.name=x: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_model_callable(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_callable: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])

    def test_model_callable_generator(self):
        self.config.load("""
            test.foreach p in metadata.Car.some_generator: ${p.name}
            """)

        self.failUnlessEqual(self.config.get()["test"],
                             ['wheel', 'brake', 'badger'])
Esempio n. 27
0
 def create_from_list(cls, specification):
     """ Given a list of types and parameters, build a resource bundle """
     c = Config()
     c.add({"resources": specification})
     return cls.create_from_yay_expression(c.resources)
Esempio n. 28
0
class TestDb(unittest.TestCase):

    def setUp(self):
        self.config = Config()
        self.config.load(dbyay)

        self.t = t = self.config.mapping.get('metadata')

        User = t.get("user").value
        Service = t.get("service").value
        Host = t.get("host").value

        t.backend.engine = engine
        t.backend.base.metadata.create_all(engine)

        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))
        session.add(User(username='******', password='******'))

        h = Host(name="wonderflonium")
        session.add(h)

        s = Service(name="www.foo.com", branch="/trunk")
        h.services.append(s)
        session.add(s)

        session.commit()

    def tearDown(self):
        self.t.backend.base.metadata.drop_all(self.t.backend.engine)

    def test_foreach_host(self):
        self.config.load("""
            test.foreach h in metadata.host: ${h.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["wonderflonium"])

    def test_foreach_host_service(self):
        self.config.load("""
            test.foreach h in metadata.host:
              .foreach s in h.services: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if(self):
        self.config.load("""
            branch: /trunk
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], ["www.foo.com"])

    def test_foreach_host_service_if_failing(self):
        self.config.load("""
            branch: /trun
            test.foreach h in metadata.host:
              .foreach s in h.services if s.branch=branch: ${s.name}
            """)

        self.failUnlessEqual(self.config.get()["test"], [])

    def test_list_all(self):
        self.config.get()
def bind(foo):
    c = Config()
    c.add({"test": foo})
    return c.test
Esempio n. 30
0
    def test_override_literal(self):
        config = Config()
        config.load(test_yay)
        config.add(dict(injected_data="xyz"))

        self.failUnlessEqual(config.get()["result"], "xyz")