Ejemplo n.º 1
0
class TestZoneWithCompute(TestCase):
    def setUp(self):
        MockDNSDriver.install(self)
        MockNodeDriver.install(self)
        self.driver = MockDNSDriver("", "")

    def test_dns_consumes_data_from_compute(self):
        self.up("""
            new Compute as mycompute:
                name: hello
                driver:
                    id: DUMMY
                    api_key: dummy
                    secret: dummy
                image: 1
                size: 2

            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records:
                      - name: www
                        data: {{ mycompute.public_ip }}
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        records = zones[0].list_records()
        self.assertEqual(len(records), 1)
        self.assertEqual(records[0].name, "www")
        self.assertEqual(records[0].data, "127.0.0.1")
Ejemplo n.º 2
0
class TestZoneWithCompute(TestCase):

    def setUp(self):
        MockDNSDriver.install(self)
        MockNodeDriver.install(self)
        self.driver = MockDNSDriver("", "")

    def test_dns_consumes_data_from_compute(self):
        self.up("""
            new Compute as mycompute:
                name: hello
                driver:
                    id: DUMMY
                    api_key: dummy
                    secret: dummy
                image: 1
                size: 2

            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records:
                      - name: www
                        data: {{ mycompute.public_ip }}
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        records = zones[0].list_records()
        self.assertEqual(len(records), 1)
        self.assertEqual(records[0].name, "www")
        self.assertEqual(records[0].data, "127.0.0.1")
Ejemplo n.º 3
0
 def setUp(self):
     MockDNSDriver.install(self)
     self.driver = MockDNSDriver("", "")
Ejemplo n.º 4
0
class TestZone(TestCase):

    def setUp(self):
        MockDNSDriver.install(self)
        self.driver = MockDNSDriver("", "")

    def test_validate_driver_id(self):
        self.assertRaises(error.ValueError, self.up, """
            new Zone as myzone:
                    driver:
                        id: DUMMYY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)

    def test_empty_records_list(self):
        self.assertEqual(len(self.driver.list_zones()), 0)
        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        # FIXME: Investigate rstrip...
        self.assertEqual(zones[0].domain.rstrip("."), "example.com")
        self.assertEqual(zones[0].list_records(), [])

    def test_add_records(self):
        self.assertEqual(len(self.driver.list_zones()), 0)
        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records:
                      - name: www
                        data: 127.0.0.1
            """)
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        records = zones[0].list_records()
        self.assertEqual(len(records), 1)

        self.assertEqual(records[0].name, "www")
        self.assertEqual(records[0].type, RecordType.A)
        self.assertEqual(records[0].data, "127.0.0.1")

    def test_cleans_up_existing_zone_not_shared(self):
        z = self.driver.create_zone("example.com.", "master", 0)
        z.create_record("www", type=RecordType.A, data='127.0.0.1')

        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
                    shared: 0
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        self.assertEqual(zones[0].list_records(), [])

    def test_cleans_up_existing_zone_shared(self):
        z = self.driver.create_zone("example.com.", "master", 0)
        z.create_record("www", type=RecordType.A, data='127.0.0.1')

        self.assertRaises(error.NothingChanged, self.up, """
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        self.assertEqual(len(zones[0].list_records()), 1)
Ejemplo n.º 5
0
 def setUp(self):
     MockDNSDriver.install(self)
     self.driver = MockDNSDriver("", "")
Ejemplo n.º 6
0
class TestZone(TestCase):
    def setUp(self):
        MockDNSDriver.install(self)
        self.driver = MockDNSDriver("", "")

    def test_validate_driver_id(self):
        self.assertRaises(
            error.ValueError, self.up, """
            new Zone as myzone:
                    driver:
                        id: DUMMYY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)

    def test_empty_records_list(self):
        self.assertEqual(len(self.driver.list_zones()), 0)
        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        # FIXME: Investigate rstrip...
        self.assertEqual(zones[0].domain.rstrip("."), "example.com")
        self.assertEqual(zones[0].list_records(), [])

    def test_add_records(self):
        self.assertEqual(len(self.driver.list_zones()), 0)
        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records:
                      - name: www
                        data: 127.0.0.1
            """)
        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)

        records = zones[0].list_records()
        self.assertEqual(len(records), 1)

        self.assertEqual(records[0].name, "www")
        self.assertEqual(records[0].type, RecordType.A)
        self.assertEqual(records[0].data, "127.0.0.1")

    def test_cleans_up_existing_zone_not_shared(self):
        z = self.driver.create_zone("example.com.", "master", 0)
        z.create_record("www", type=RecordType.A, data='127.0.0.1')

        self.up("""
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
                    shared: 0
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        self.assertEqual(zones[0].list_records(), [])

    def test_cleans_up_existing_zone_shared(self):
        z = self.driver.create_zone("example.com.", "master", 0)
        z.create_record("www", type=RecordType.A, data='127.0.0.1')

        self.assertRaises(
            error.NothingChanged, self.up, """
            new Zone as myzone:
                    driver:
                        id: DUMMY
                        api_key: dummykey
                        secret: dummysecret
                    domain: example.com
                    records: []
            """)

        zones = self.driver.list_zones()
        self.assertEqual(len(zones), 1)
        self.assertEqual(len(zones[0].list_records()), 1)