]>
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 PDNSUTIL_CMD
= ["../pdns/pdnsutil", "--config-dir=."]
26 # Generated by runtests.py
27 options { directory "../regression-tests/zones/"; };
28 zone "example.com" { type master; file "example.com"; };
29 zone "powerdnssec.org" { type master; file "powerdnssec.org"; };
30 zone "cryptokeys.org" { type master; file "cryptokeys.org"; };
34 # Generated by runtests.py
37 gsqlite3-database="""+SQLITE_DB
+"""
38 module-dir=../regression-tests/modules
39 bind-config=bindbackend.conf
42 BINDBACKEND_CONF_TPL
= """
43 # Generated by runtests.py
47 # Generated by runtests.py
53 REC_EXAMPLE_COM_CONF_TPL
= """
54 # Generated by runtests.py
55 auth-zones+=example.com=../regression-tests/zones/example.com
59 # Generated by runtests.py
62 forward-zones-recurse=
63 allow-from-file=acl.list
64 api-config-dir=%(conf_dir)s
65 include-dir=%(conf_dir)s
69 def ensure_empty_dir(name
):
70 if os
.path
.exists(name
):
75 def format_call_args(cmd
):
76 return "$ '%s'" % ("' '".join(cmd
))
79 def run_check_call(cmd
, *args
, **kwargs
):
80 print(format_call_args(cmd
))
81 subprocess
.check_call(cmd
, *args
, **kwargs
)
84 wait
= ('--wait' in sys
.argv
)
86 sys
.argv
.remove('--wait')
88 tests
= [opt
for opt
in sys
.argv
if opt
.startswith('--tests=')]
92 tests
= [opt
.split('=', 1)[1] for opt
in tests
]
94 daemon
= (len(sys
.argv
) == 2) and sys
.argv
[1] or None
95 if daemon
not in ('authoritative', 'recursor'):
96 print("Usage: ./runtests (authoritative|recursor)")
101 pdns_server
= os
.environ
.get("PDNSSERVER", "../pdns/pdns_server")
102 pdns_recursor
= os
.environ
.get("PDNSRECURSOR", "../pdns/recursordist/pdns_recursor")
104 "--daemon=no", "--socket-dir=.", "--config-dir=.",
105 "--local-address=127.0.0.1", "--local-port="+str(DNSPORT
),
106 "--webserver=yes", "--webserver-port="+str(WEBPORT
), "--webserver-address=127.0.0.1", "--webserver-password=something",
110 # Take sdig if it exists (recursor in travis), otherwise build it from Authoritative source.
111 sdig
= os
.environ
.get("SDIG", "")
113 sdig
= os
.path
.abspath(sdig
)
114 if not sdig
or not os
.path
.exists(sdig
):
115 run_check_call(["make", "-C", "../pdns", "sdig"])
116 sdig
= "../pdns/sdig"
119 if daemon
== 'authoritative':
121 # Prepare sqlite DB with some zones.
122 run_check_call(["rm", "-f", SQLITE_DB
])
123 run_check_call(["make", "-C", "../pdns", "zone2sql"])
125 with
open('../modules/gsqlite3backend/schema.sqlite3.sql', 'r') as schema_file
:
126 run_check_call(["sqlite3", SQLITE_DB
], stdin
=schema_file
)
128 with
open('named.conf', 'w') as named_conf
:
129 named_conf
.write(NAMED_CONF_TPL
)
130 with tempfile
.TemporaryFile() as tf
:
131 p
= subprocess
.Popen(["../pdns/zone2sql", "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout
=tf
)
133 if p
.returncode
!= 0:
134 raise Exception("zone2sql failed")
135 tf
.seek(0, os
.SEEK_SET
) # rewind
136 run_check_call(["sqlite3", SQLITE_DB
], stdin
=tf
)
138 with
open('bindbackend.conf', 'w') as bindbackend_conf
:
139 bindbackend_conf
.write(BINDBACKEND_CONF_TPL
)
141 with
open('pdns.conf', 'w') as pdns_conf
:
142 pdns_conf
.write(AUTH_CONF_TPL
)
144 run_check_call(PDNSUTIL_CMD
+ ["secure-zone", "powerdnssec.org"])
145 servercmd
= [pdns_server
] + common_args
+ ["--local-ipv6=", "--no-shuffle", "--dnsupdate=yes", "--cache-ttl=0", "--api=yes"]
148 conf_dir
= 'rec-conf.d'
149 ensure_empty_dir(conf_dir
)
150 with
open('acl.list', 'w') as acl_list
:
151 acl_list
.write(ACL_LIST_TPL
)
152 with
open('recursor.conf', 'w') as recursor_conf
:
153 recursor_conf
.write(REC_CONF_TPL
% locals())
154 with
open(conf_dir
+'/example.com..conf', 'w') as conf_file
:
155 conf_file
.write(REC_EXAMPLE_COM_CONF_TPL
)
157 servercmd
= [pdns_recursor
] + common_args
160 # Now run pdns and the tests.
161 print("Launching server...")
162 print(format_call_args(servercmd
))
163 serverproc
= subprocess
.Popen(servercmd
, close_fds
=True)
165 print("Waiting for webserver port to become available...")
167 for try_number
in range(0, 10):
169 res
= requests
.get('http://127.0.0.1:%s/' % WEBPORT
)
176 print("Webserver port not reachable after 10 tries, giving up.")
177 serverproc
.terminate()
181 print("Query for example.com/A to create statistic data...")
182 run_check_call([sdig
, "127.0.0.1", str(DNSPORT
), "example.com", "A"])
184 print("Running tests...")
187 test_env
.update(os
.environ
)
189 'WEBPORT': str(WEBPORT
),
192 'SQLITE_DB': SQLITE_DB
,
193 'PDNSUTIL_CMD': ' '.join(PDNSUTIL_CMD
),
195 'DNSPORT': str(DNSPORT
)
200 run_check_call(["nosetests", "--with-xunit", "-v"] + tests
, env
=test_env
)
201 except subprocess
.CalledProcessError
as ex
:
202 returncode
= ex
.returncode
205 print("Waiting as requested, press ENTER to stop.")
207 serverproc
.terminate()