From: Christian Hofstaedtler Date: Fri, 31 Jan 2014 00:42:25 +0000 (+0100) Subject: Add API test suite for recursor X-Git-Tag: rec-3.6.0-rc1~211^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7c876c3085855068b3eb78028d4d232376180a43;p=thirdparty%2Fpdns.git Add API test suite for recursor --- diff --git a/.travis.yml b/.travis.yml index b4d71c28f8..8de51a4ec9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -41,7 +41,8 @@ script: - sleep 3 - ./clean.sh - cd ../regression-tests.api - - ./runtests + - ./runtests authoritative + - ./runtests recursor - cd ../regression-tests - touch tests/verify-dnssec-zone/allow-missing - ./start-test-stop 5300 bind-both diff --git a/regression-tests.api/runtests b/regression-tests.api/runtests index 9680de884f..b585b84fcc 100755 --- a/regression-tests.api/runtests +++ b/regression-tests.api/runtests @@ -9,4 +9,4 @@ pip install -r requirements.txt set -e set -x -exec ./runtests.py +exec ./runtests.py "$@" diff --git a/regression-tests.api/runtests.py b/regression-tests.api/runtests.py index c17909d13c..bfd8fd442b 100755 --- a/regression-tests.api/runtests.py +++ b/regression-tests.api/runtests.py @@ -17,35 +17,52 @@ options { directory "../regression-tests/zones/"; }; zone "example.com" { type master; file "example.com"; }; """ -# Prepare sqlite DB with a single zone. -subprocess.check_call(["rm", "-f", SQLITE_DB]) -subprocess.check_call(["make", "-C", "../pdns", "zone2sql"]) - -with open('../modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql', 'r') as schema_file: - subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file) -with open('../modules/gsqlite3backend/dnssec.schema.sqlite3.sql', 'r') as schema_file: - subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file) - -with open('named.conf', 'w') as named_conf: - named_conf.write(NAMED_CONF_TPL) -with tempfile.TemporaryFile() as tf: - p = subprocess.Popen(["../pdns/zone2sql", "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout=tf) - p.communicate() - if p.returncode != 0: - raise Exception("zone2sql failed") - tf.seek(0, os.SEEK_SET) # rewind - subprocess.check_call(["sqlite3", SQLITE_DB], stdin=tf) +daemon = (len(sys.argv) == 2) and sys.argv[1] or None +if daemon not in ('authoritative', 'recursor'): + print "Usage: ./runtests (authoritative|recursor)" + sys.exit(2) + +daemon = sys.argv[1] + +if daemon == 'authoritative': + + # Prepare sqlite DB with a single zone. + subprocess.check_call(["rm", "-f", SQLITE_DB]) + subprocess.check_call(["make", "-C", "../pdns", "zone2sql"]) + + with open('../modules/gsqlite3backend/no-dnssec.schema.sqlite3.sql', 'r') as schema_file: + subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file) + with open('../modules/gsqlite3backend/dnssec.schema.sqlite3.sql', 'r') as schema_file: + subprocess.check_call(["sqlite3", SQLITE_DB], stdin=schema_file) + + with open('named.conf', 'w') as named_conf: + named_conf.write(NAMED_CONF_TPL) + with tempfile.TemporaryFile() as tf: + p = subprocess.Popen(["../pdns/zone2sql", "--transactions", "--gsqlite", "--named-conf=named.conf"], stdout=tf) + p.communicate() + if p.returncode != 0: + raise Exception("zone2sql failed") + tf.seek(0, os.SEEK_SET) # rewind + subprocess.check_call(["sqlite3", SQLITE_DB], stdin=tf) + + 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() + +else: + + # No preparations for recursor + pdnscmd = ("../pdns/pdns_recursor --daemon=no --socket-dir=. --local-port=5555 --experimental-json-interface=yes --webserver=yes --webserver-port="+WEBPORT+" --webserver-address=127.0.0.1 --webserver-password="+WEBPASSWORD).split() # Now run pdns and the tests. -print "Launching pdns_server and running tests..." -pdnsargs = ("--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() -pdns = subprocess.Popen(["../pdns/pdns_server"] + pdnsargs, close_fds=True) +print "Launching pdns..." +print ' '.join(pdnscmd) +pdns = subprocess.Popen(pdnscmd, close_fds=True) +print "Running tests..." rc = 0 test_env = {} test_env.update(os.environ) -test_env.update({'WEBPORT': WEBPORT, 'WEBPASSWORD': WEBPASSWORD}) +test_env.update({'WEBPORT': WEBPORT, 'WEBPASSWORD': WEBPASSWORD, 'DAEMON': daemon}) try: print "" diff --git a/regression-tests.api/test_Servers.py b/regression-tests.api/test_Servers.py index 3895d87b59..be0579bca7 100644 --- a/regression-tests.api/test_Servers.py +++ b/regression-tests.api/test_Servers.py @@ -1,6 +1,6 @@ import unittest import requests -from test_helper import ApiTestCase +from test_helper import ApiTestCase, isAuth, isRecursor class Servers(ApiTestCase): @@ -24,7 +24,11 @@ class Servers(ApiTestCase): self.assertEquals(data['id'], 'localhost') self.assertEquals(data['type'], 'Server') # or 'recursor' for recursors - self.assertEquals(data['daemon_type'], 'authoritative') + if isAuth(): + daemon_type = 'authoritative' + elif isRecursor(): + daemon_type = 'recursor' + self.assertEquals(data['daemon_type'], daemon_type) def test_ReadConfig(self): r = self.session.get(self.url("/servers/localhost/config")) diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 8d5e4f05ce..a0b33efe61 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -1,9 +1,10 @@ import json import requests import unittest -from test_helper import ApiTestCase, unique_zone_name +from test_helper import ApiTestCase, unique_zone_name, isRecursor +@unittest.skipIf(isRecursor(), "Not implemented yet") class Servers(ApiTestCase): def test_ListZones(self): diff --git a/regression-tests.api/test_helper.py b/regression-tests.api/test_helper.py index 376e17fe3a..efc16d18db 100644 --- a/regression-tests.api/test_helper.py +++ b/regression-tests.api/test_helper.py @@ -4,14 +4,16 @@ import requests import urlparse import unittest +DAEMON = os.environ.get('DAEMON', 'authoritative') + class ApiTestCase(unittest.TestCase): def setUp(self): # TODO: config - self.server_url = 'http://127.0.0.1:%s/' % (os.environ.get('WEBPORT','5580')) + self.server_url = 'http://127.0.0.1:%s/' % (os.environ.get('WEBPORT', '5580')) self.session = requests.Session() - self.session.auth = ('admin', os.environ.get('WEBPASSWORD','changeme')) + self.session.auth = ('admin', os.environ.get('WEBPASSWORD', 'changeme')) def url(self, relative_url): return urlparse.urljoin(self.server_url, relative_url) @@ -23,3 +25,11 @@ class ApiTestCase(unittest.TestCase): def unique_zone_name(): return 'test-' + datetime.now().strftime('%d%H%S%M%f') + '.org' + + +def isAuth(): + return (DAEMON == 'authoritative') + + +def isRecursor(): + return (DAEMON == 'recursor')