]>
git.ipfire.org Git - thirdparty/pdns.git/blob - regression-tests.api/runtests.py
5 from __future__
import print_function
14 SQLITE_DB
= 'pdns.sqlite3'
17 APIKEY
= '1234567890abcdefghijklmnopq-key'
18 PDNSUTIL_CMD
= ["../pdns/pdnsutil", "--config-dir=."]
21 # Generated by runtests.py
22 options { directory "../regression-tests/zones/"; };
23 zone "example.com" { type master; file "example.com"; };
24 zone "powerdnssec.org" { type master; file "powerdnssec.org"; };
25 zone "cryptokeys.org" { type master; file "cryptokeys.org"; };
29 # Generated by runtests.py
32 gsqlite3-database="""+SQLITE_DB
+"""
33 module-dir=../regression-tests/modules
34 bind-config=bindbackend.conf
37 BINDBACKEND_CONF_TPL
= """
38 # Generated by runtests.py
42 # Generated by runtests.py
48 REC_EXAMPLE_COM_CONF_TPL
= """
49 # Generated by runtests.py
50 auth-zones+=example.com=../regression-tests/zones/example.com
54 # Generated by runtests.py
57 forward-zones-recurse=
58 allow-from-file=acl.list
59 api-config-dir=%(conf_dir)s
60 include-dir=%(conf_dir)s
64 def ensure_empty_dir(name
):
65 if os
.path
.exists(name
):
70 def format_call_args(cmd
):
71 return "$ '%s'" % ("' '".join(cmd
))
74 def run_check_call(cmd
, *args
, **kwargs
):
75 print(format_call_args(cmd
))
76 subprocess
.check_call(cmd
, *args
, **kwargs
)
79 wait
= ('--wait' in sys
.argv
)
81 sys
.argv
.remove('--wait')
83 tests
= [opt
for opt
in sys
.argv
if opt
.startswith('--tests=')]
87 tests
= [opt
.split('=', 1)[1] for opt
in tests
]
89 daemon
= (len(sys
.argv
) == 2) and sys
.argv
[1] or None
90 if daemon
not in ('authoritative', 'recursor'):
91 print("Usage: ./runtests (authoritative|recursor)")
96 pdns_server
= os
.environ
.get("PDNSSERVER", "../pdns/pdns_server")
97 pdns_recursor
= os
.environ
.get("PDNSRECURSOR", "../pdns/recursordist/pdns_recursor")
99 "--daemon=no", "--socket-dir=.", "--config-dir=.",
100 "--local-address=127.0.0.1", "--local-port="+str(DNSPORT
),
101 "--webserver=yes", "--webserver-port="+str(WEBPORT
), "--webserver-address=127.0.0.1", "--webserver-password=something",
105 # Take sdig if it exists (recursor in travis), otherwise build it from Authoritative source.
106 sdig
= os
.environ
.get("SDIG", "")
108 sdig
= os
.path
.abspath(sdig
)
109 if not sdig
or not os
.path
.exists(sdig
):
110 run_check_call(["make", "-C", "../pdns", "sdig"])
111 sdig
= "../pdns/sdig"
114 if daemon
== 'authoritative':
116 # Prepare sqlite DB with some zones.
117 run_check_call(["rm", "-f", SQLITE_DB
])
118 run_check_call(["make", "-C", "../pdns", "zone2sql"])
120 with
open('../modules/gsqlite3backend/schema.sqlite3.sql', 'r') as schema_file
:
121 run_check_call(["sqlite3", SQLITE_DB
], stdin
=schema_file
)
123 with
open('named.conf', 'w') as named_conf
:
124 named_conf
.write(NAMED_CONF_TPL
)
125 with tempfile
.TemporaryFile() as tf
:
126 p
= subprocess
.Popen(["../pdns/zone2sql", "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout
=tf
)
128 if p
.returncode
!= 0:
129 raise Exception("zone2sql failed")
130 tf
.seek(0, os
.SEEK_SET
) # rewind
131 run_check_call(["sqlite3", SQLITE_DB
], stdin
=tf
)
133 with
open('bindbackend.conf', 'w') as bindbackend_conf
:
134 bindbackend_conf
.write(BINDBACKEND_CONF_TPL
)
136 with
open('pdns.conf', 'w') as pdns_conf
:
137 pdns_conf
.write(AUTH_CONF_TPL
)
139 run_check_call(PDNSUTIL_CMD
+ ["secure-zone", "powerdnssec.org"])
140 servercmd
= [pdns_server
] + common_args
+ ["--local-ipv6=", "--no-shuffle", "--dnsupdate=yes", "--cache-ttl=0", "--api=yes"]
143 conf_dir
= 'rec-conf.d'
144 ensure_empty_dir(conf_dir
)
145 with
open('acl.list', 'w') as acl_list
:
146 acl_list
.write(ACL_LIST_TPL
)
147 with
open('recursor.conf', 'w') as recursor_conf
:
148 recursor_conf
.write(REC_CONF_TPL
% locals())
149 with
open(conf_dir
+'/example.com..conf', 'w') as conf_file
:
150 conf_file
.write(REC_EXAMPLE_COM_CONF_TPL
)
152 servercmd
= [pdns_recursor
] + common_args
155 # Now run pdns and the tests.
156 print("Launching server...")
157 print(format_call_args(servercmd
))
158 serverproc
= subprocess
.Popen(servercmd
, close_fds
=True)
160 print("Waiting for webserver port to become available...")
162 for try_number
in range(0, 10):
164 res
= requests
.get('http://127.0.0.1:%s/' % WEBPORT
)
171 print("Webserver port not reachable after 10 tries, giving up.")
172 serverproc
.terminate()
176 print("Query for example.com/A to create statistic data...")
177 run_check_call([sdig
, "127.0.0.1", str(DNSPORT
), "example.com", "A"])
179 print("Running tests...")
182 test_env
.update(os
.environ
)
184 'WEBPORT': str(WEBPORT
),
187 'SQLITE_DB': SQLITE_DB
,
188 'PDNSUTIL_CMD': ' '.join(PDNSUTIL_CMD
),
190 'DNSPORT': str(DNSPORT
)
195 run_check_call(["nosetests", "--with-xunit", "-v"] + tests
, env
=test_env
)
196 except subprocess
.CalledProcessError
as ex
:
197 returncode
= ex
.returncode
200 print("Waiting as requested, press ENTER to stop.")
202 serverproc
.terminate()