Пример #1
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Пример #2
0
    def test_simple_update(self):
        c = Config()
        c.load("""
            foo: 1
            bar: 2
            baz: 3
            """)

        self.failUnless('foo' in c.get().keys())
Пример #3
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Пример #4
0
    def test_list(self):
        c = Config()
        c.load("""
            foo:
                - 1
                - 2
                - 3
            """)

        self.failUnlessEqual(c.get()['foo'], [1, 2, 3])
Пример #5
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])
Пример #6
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])
Пример #7
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'], [])
Пример #8
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)
Пример #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'], [])
Пример #10
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)
Пример #11
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
Пример #12
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
Пример #13
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)
Пример #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)
Пример #15
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'])
Пример #16
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"], [])
Пример #17
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()
Пример #18
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'])
Пример #19
0
    def test_override_literal(self):
        config = Config()
        config.load(test_yay)
        config.add(dict(injected_data="xyz"))

        self.failUnlessEqual(config.get()["result"], "xyz")
Пример #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")