]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/runtests.py
5 from __future__
import print_function
19 SQLITE_DB
= 'pdns.sqlite3'
22 APIKEY
= '1234567890abcdefghijklmnopq-key'
23 WEBPASSWORD
= 'something'
24 PDNSUTIL_CMD
= [os
.environ
.get("PDNSUTIL", "../pdns/pdnsutil"), "--config-dir=."]
27 # Generated by runtests.py
28 options { directory "../regression-tests/zones/"; };
29 zone "example.com" { type master; file "example.com"; };
30 zone "powerdnssec.org" { type master; file "powerdnssec.org"; };
31 zone "cryptokeys.org" { type master; file "cryptokeys.org"; };
35 # Generated by runtests.py
38 gsqlite3-database="""+SQLITE_DB
+"""
39 module-dir=../regression-tests/modules
40 bind-config=bindbackend.conf
41 default-soa-edit=INCEPTION-INCREMENT
44 BINDBACKEND_CONF_TPL
= """
45 # Generated by runtests.py
49 # Generated by runtests.py
55 REC_EXAMPLE_COM_CONF_TPL
= """
56 # Generated by runtests.py
57 auth-zones+=example.com=../regression-tests/zones/example.com
61 # Generated by runtests.py
64 forward-zones-recurse=
65 allow-from-file=acl.list
66 api-config-dir=%(conf_dir)s
67 include-dir=%(conf_dir)s
71 def ensure_empty_dir(name
):
72 if os
.path
.exists(name
):
77 def format_call_args(cmd
):
78 return "$ '%s'" % ("' '".join(cmd
))
81 def run_check_call(cmd
, *args
, **kwargs
):
82 print(format_call_args(cmd
))
83 subprocess
.check_call(cmd
, *args
, **kwargs
)
86 wait
= ('--wait' in sys
.argv
)
88 sys
.argv
.remove('--wait')
90 tests
= [opt
for opt
in sys
.argv
if opt
.startswith('--tests=')]
94 tests
= [opt
.split('=', 1)[1] for opt
in tests
]
96 daemon
= (len(sys
.argv
) == 2) and sys
.argv
[1] or None
97 if daemon
not in ('authoritative', 'recursor'):
98 print("Usage: ./runtests (authoritative|recursor)")
103 pdns_server
= os
.environ
.get("PDNSSERVER", "../pdns/pdns_server")
104 pdns_recursor
= os
.environ
.get("PDNSRECURSOR", "../pdns/recursordist/pdns_recursor")
106 "--daemon=no", "--socket-dir=.", "--config-dir=.",
107 "--local-address=127.0.0.1", "--local-port="+str(DNSPORT
),
108 "--webserver=yes", "--webserver-port="+str(WEBPORT
), "--webserver-address=127.0.0.1",
109 "--webserver-password="+WEBPASSWORD
,
113 # Take sdig if it exists (recursor in travis), otherwise build it from Authoritative source.
114 sdig
= os
.environ
.get("SDIG", "")
116 sdig
= os
.path
.abspath(sdig
)
117 if not sdig
or not os
.path
.exists(sdig
):
118 run_check_call(["make", "-C", "../pdns", "sdig"])
119 sdig
= "../pdns/sdig"
122 if daemon
== 'authoritative':
123 zone2sql
= os
.environ
.get("ZONE2SQL", "../pdns/zone2sql")
125 # Prepare sqlite DB with some zones.
126 run_check_call(["rm", "-f", SQLITE_DB
])
127 if zone2sql
== "../pdns/zone2sql":
128 run_check_call(["make", "-C", "../pdns", "zone2sql"])
130 with
open('../modules/gsqlite3backend/schema.sqlite3.sql', 'r') as schema_file
:
131 run_check_call(["sqlite3", SQLITE_DB
], stdin
=schema_file
)
133 with
open('named.conf', 'w') as named_conf
:
134 named_conf
.write(NAMED_CONF_TPL
)
135 with tempfile
.TemporaryFile() as tf
:
136 p
= subprocess
.Popen([zone2sql
, "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout
=tf
)
138 if p
.returncode
!= 0:
139 raise Exception("zone2sql failed")
140 tf
.seek(0, os
.SEEK_SET
) # rewind
141 run_check_call(["sqlite3", SQLITE_DB
], stdin
=tf
)
143 with
open('bindbackend.conf', 'w') as bindbackend_conf
:
144 bindbackend_conf
.write(BINDBACKEND_CONF_TPL
)
146 with
open('pdns.conf', 'w') as pdns_conf
:
147 pdns_conf
.write(AUTH_CONF_TPL
)
149 run_check_call(PDNSUTIL_CMD
+ ["secure-zone", "powerdnssec.org"])
150 servercmd
= [pdns_server
] + common_args
+ ["--local-ipv6=", "--no-shuffle", "--dnsupdate=yes", "--cache-ttl=0", "--api=yes"]
153 conf_dir
= 'rec-conf.d'
154 ensure_empty_dir(conf_dir
)
155 with
open('acl.list', 'w') as acl_list
:
156 acl_list
.write(ACL_LIST_TPL
)
157 with
open('recursor.conf', 'w') as recursor_conf
:
158 recursor_conf
.write(REC_CONF_TPL
% locals())
159 with
open(conf_dir
+'/example.com..conf', 'w') as conf_file
:
160 conf_file
.write(REC_EXAMPLE_COM_CONF_TPL
)
162 servercmd
= [pdns_recursor
] + common_args
165 # Now run pdns and the tests.
166 print("Launching server...")
167 print(format_call_args(servercmd
))
168 serverproc
= subprocess
.Popen(servercmd
, close_fds
=True)
170 print("Waiting for webserver port to become available...")
172 for try_number
in range(0, 10):
174 res
= requests
.get('http://127.0.0.1:%s/' % WEBPORT
)
181 print("Webserver port not reachable after 10 tries, giving up.")
182 serverproc
.terminate()
186 print("Query for example.com/A to create statistic data...")
187 run_check_call([sdig
, "127.0.0.1", str(DNSPORT
), "example.com", "A"])
189 print("Running tests...")
192 test_env
.update(os
.environ
)
194 'WEBPASSWORD': WEBPASSWORD
,
195 'WEBPORT': str(WEBPORT
),
198 'SQLITE_DB': SQLITE_DB
,
199 'PDNSUTIL_CMD': ' '.join(PDNSUTIL_CMD
),
201 'DNSPORT': str(DNSPORT
)
206 run_check_call(["nosetests", "--with-xunit", "-v"] + tests
, env
=test_env
)
207 except subprocess
.CalledProcessError
as ex
:
208 returncode
= ex
.returncode
211 print("Waiting as requested, press ENTER to stop.")
213 serverproc
.terminate()