]> git.ipfire.org Git - thirdparty/pdns.git/blame - regression-tests.api/runtests.py
remove old schema from doc
[thirdparty/pdns.git] / regression-tests.api / runtests.py
CommitLineData
1a152698
CH
1#!/usr/bin/env python
2#
3# Shell-script style.
4
5import os
a1e51a8a 6import requests
02945d9a 7import shutil
1a152698
CH
8import subprocess
9import sys
10import tempfile
a1e51a8a 11import time
1a152698
CH
12
13SQLITE_DB = 'pdns.sqlite3'
14WEBPORT = '5556'
15WEBPASSWORD = '12345'
16
17NAMED_CONF_TPL = """
18# Generated by runtests.py
19options { directory "../regression-tests/zones/"; };
20zone "example.com" { type master; file "example.com"; };
21"""
22
41942bb3
CH
23ACL_LIST_TPL = """
24# Generated by runtests.py
25# local host
26127.0.0.1
27::1
28"""
29
02945d9a
CH
30REC_EXAMPLE_COM_CONF_TPL = """
31# Generated by runtests.py
32auth-zones+=example.com=../regression-tests/zones/example.com
33"""
34
35REC_CONF_TPL = """
36# Generated by runtests.py
37auth-zones=
38forward-zones=
39forward-zones-recurse=
40experimental-api-config-dir=%(conf_dir)s
41include-dir=%(conf_dir)s
42"""
43
44def ensure_empty_dir(name):
45 if os.path.exists(name):
46 shutil.rmtree(name)
47 os.mkdir(name)
48
49
5f8fa6d4
CH
50wait = ('--wait' in sys.argv)
51if wait:
52 sys.argv.remove('--wait')
53
7c876c30
CH
54daemon = (len(sys.argv) == 2) and sys.argv[1] or None
55if daemon not in ('authoritative', 'recursor'):
56 print "Usage: ./runtests (authoritative|recursor)"
57 sys.exit(2)
58
59daemon = sys.argv[1]
60
61if daemon == 'authoritative':
62
63 # Prepare sqlite DB with a single zone.
64 subprocess.check_call(["rm", "-f", SQLITE_DB])
65 subprocess.check_call(["make", "-C", "../pdns", "zone2sql"])
66
67 with open('../modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql', 'r') as schema_file:
68 subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file)
69 with open('../modules/gsqlite3backend/dnssec.schema.sqlite3.sql', 'r') as schema_file:
70 subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file)
71
72 with open('named.conf', 'w') as named_conf:
73 named_conf.write(NAMED_CONF_TPL)
74 with tempfile.TemporaryFile() as tf:
75 p = subprocess.Popen(["../pdns/zone2sql", "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout=tf)
76 p.communicate()
77 if p.returncode != 0:
78 raise Exception("zone2sql failed")
79 tf.seek(0, os.SEEK_SET) # rewind
80 subprocess.check_call(["sqlite3", SQLITE_DB], stdin=tf)
81
82 pdnscmd = ("../pdns/pdns_server --daemon=no --local-port=5300 --socket-dir=./ --no-shuffle --launch=gsqlite3 --gsqlite3-dnssec --send-root-referral --allow-2136-from=127.0.0.0/8 --experimental-rfc2136=yes --cache-ttl=0 --no-config --gsqlite3-database="+SQLITE_DB+" --experimental-json-interface=yes --webserver=yes --webserver-port="+WEBPORT+" --webserver-address=127.0.0.1 --query-logging --webserver-password="+WEBPASSWORD).split()
83
84else:
02945d9a
CH
85 conf_dir = 'rec-conf.d'
86 ensure_empty_dir(conf_dir)
41942bb3
CH
87 with open('acl.list', 'w') as acl_list:
88 acl_list.write(ACL_LIST_TPL)
02945d9a
CH
89 with open('recursor.conf', 'w') as recursor_conf:
90 recursor_conf.write(REC_CONF_TPL % locals())
91 with open(conf_dir+'/example.com..conf', 'w') as conf_file:
92 conf_file.write(REC_EXAMPLE_COM_CONF_TPL)
7c876c30 93
41942bb3 94 pdnscmd = ("../pdns/pdns_recursor --daemon=no --socket-dir=. --config-dir=. --allow-from-file=acl.list --local-port=5555 --experimental-json-interface=yes --experimental-webserver=yes --experimental-webserver-port="+WEBPORT+" --experimental-webserver-address=127.0.0.1 --experimental-webserver-password="+WEBPASSWORD).split()
1a152698
CH
95
96
97# Now run pdns and the tests.
7c876c30
CH
98print "Launching pdns..."
99print ' '.join(pdnscmd)
100pdns = subprocess.Popen(pdnscmd, close_fds=True)
1a152698 101
a1e51a8a
CH
102print "Waiting for webserver port to become available..."
103available = False
104for try_number in range(0, 10):
105 try:
106 res = requests.get('http://127.0.0.1:%s/' % WEBPORT)
107 available = True
108 break
109 except:
110 time.sleep(0.5)
111
112if not available:
113 print "Webserver port not reachable after 10 tries, giving up."
114 pdns.terminate()
115 pdns.wait()
116 sys.exit(2)
117
7c876c30 118print "Running tests..."
1a152698
CH
119rc = 0
120test_env = {}
121test_env.update(os.environ)
7c876c30 122test_env.update({'WEBPORT': WEBPORT, 'WEBPASSWORD': WEBPASSWORD, 'DAEMON': daemon})
1a152698
CH
123
124try:
125 print ""
126 p = subprocess.check_call(["nosetests", "--with-xunit"], env=test_env)
127except subprocess.CalledProcessError as ex:
128 rc = ex.returncode
129finally:
5f8fa6d4
CH
130 if wait:
131 print "Waiting as requested, press ENTER to stop."
132 raw_input()
1a152698
CH
133 pdns.terminate()
134 pdns.wait()
135
136sys.exit(rc)