]>
Commit | Line | Data |
---|---|---|
1a152698 CH |
1 | #!/usr/bin/env python |
2 | # | |
3 | # Shell-script style. | |
4 | ||
5 | import os | |
a1e51a8a | 6 | import requests |
02945d9a | 7 | import shutil |
1a152698 CH |
8 | import subprocess |
9 | import sys | |
10 | import tempfile | |
a1e51a8a | 11 | import time |
1a152698 CH |
12 | |
13 | SQLITE_DB = 'pdns.sqlite3' | |
14 | WEBPORT = '5556' | |
15 | WEBPASSWORD = '12345' | |
16 | ||
17 | NAMED_CONF_TPL = """ | |
18 | # Generated by runtests.py | |
19 | options { directory "../regression-tests/zones/"; }; | |
20 | zone "example.com" { type master; file "example.com"; }; | |
21 | """ | |
22 | ||
41942bb3 CH |
23 | ACL_LIST_TPL = """ |
24 | # Generated by runtests.py | |
25 | # local host | |
26 | 127.0.0.1 | |
27 | ::1 | |
28 | """ | |
29 | ||
02945d9a CH |
30 | REC_EXAMPLE_COM_CONF_TPL = """ |
31 | # Generated by runtests.py | |
32 | auth-zones+=example.com=../regression-tests/zones/example.com | |
33 | """ | |
34 | ||
35 | REC_CONF_TPL = """ | |
36 | # Generated by runtests.py | |
37 | auth-zones= | |
38 | forward-zones= | |
39 | forward-zones-recurse= | |
40 | experimental-api-config-dir=%(conf_dir)s | |
41 | include-dir=%(conf_dir)s | |
42 | """ | |
43 | ||
44 | def ensure_empty_dir(name): | |
45 | if os.path.exists(name): | |
46 | shutil.rmtree(name) | |
47 | os.mkdir(name) | |
48 | ||
49 | ||
5f8fa6d4 CH |
50 | wait = ('--wait' in sys.argv) |
51 | if wait: | |
52 | sys.argv.remove('--wait') | |
53 | ||
7c876c30 CH |
54 | daemon = (len(sys.argv) == 2) and sys.argv[1] or None |
55 | if daemon not in ('authoritative', 'recursor'): | |
56 | print "Usage: ./runtests (authoritative|recursor)" | |
57 | sys.exit(2) | |
58 | ||
59 | daemon = sys.argv[1] | |
60 | ||
61 | if 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 | ||
84 | else: | |
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 |
98 | print "Launching pdns..." |
99 | print ' '.join(pdnscmd) | |
100 | pdns = subprocess.Popen(pdnscmd, close_fds=True) | |
1a152698 | 101 | |
a1e51a8a CH |
102 | print "Waiting for webserver port to become available..." |
103 | available = False | |
104 | for 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 | ||
112 | if 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 | 118 | print "Running tests..." |
1a152698 CH |
119 | rc = 0 |
120 | test_env = {} | |
121 | test_env.update(os.environ) | |
7c876c30 | 122 | test_env.update({'WEBPORT': WEBPORT, 'WEBPASSWORD': WEBPASSWORD, 'DAEMON': daemon}) |
1a152698 CH |
123 | |
124 | try: | |
125 | print "" | |
126 | p = subprocess.check_call(["nosetests", "--with-xunit"], env=test_env) | |
127 | except subprocess.CalledProcessError as ex: | |
128 | rc = ex.returncode | |
129 | finally: | |
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 | ||
136 | sys.exit(rc) |