test.py 1.96 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
#!/usr/bin/env python3

"""
Multi-master failover tests.
"""

from dnstest.test import Test

t = Test()

# testing zone
zone = t.zone_rnd(1, dnssec=False, records=1)[0]
zone.update_soa(serial=1, refresh=600, retry=600, expire=3600)

# +---------+       +---------+
# | master1 <-------+ master2 |
# +----^----+       +----^----+
#      |                 |    
#      |   +---------+   |    
#      +---+  slave  +---+    
#          +---------+   

master1 = t.server("knot")
master2 = t.server("bind")
slave = t.server("knot")

# flush zones immediatelly
for server in [master1, master2, slave]:
    slave.zonefile_sync = "0"

t.link([zone], master1, master2)
t.link([zone], master1, slave)
t.link([zone], master2, slave)

t.start()

# zone boostrap
for server in [master1, master2, slave]:
    server.zone_wait(zone)

# transfer with fully working topology
master1.zones[zone.name].zfile.update_soa(serial=10)
master1.reload()
for server in [master1, master2, slave]:
45
    server.zone_wait(zone, serial=10, equal=True, greater=False)
46 47 48 49 50 51

# stop slave, update masters
slave.stop()
master1.zones[zone.name].zfile.update_soa(serial=20)
master1.reload()
for server in [master1, master2]:
52
    server.zone_wait(zone, serial=20, equal=True, greater=False)
53 54 55

# failover to second master
master1.stop()
56
slave.clean(zone=False, timers=True)
57
slave.start()
58
slave.zone_wait(zone, serial=20, equal=True, greater=False)
59 60 61 62 63 64 65
master1.start()

# stop slave, update masters
slave.stop()
master1.zones[zone.name].zfile.update_soa(serial=30)
master1.reload()
for server in [master1, master2]:
66
    server.zone_wait(zone, serial=30, equal=True, greater=False)
67 68 69 70 71

# failover after notify
master1.stop()
master2.stop()
slave.start()
72
slave.zone_wait(zone, serial=20, equal=True, greater=False)
73
master2.start()
74
slave.zone_wait(zone, serial=30, equal=True, greater=False)
75 76

t.end()