]> granicus.if.org Git - pdns/commitdiff
Add API test suite for recursor
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Fri, 31 Jan 2014 00:42:25 +0000 (01:42 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Mon, 3 Feb 2014 14:06:19 +0000 (15:06 +0100)
.travis.yml
regression-tests.api/runtests
regression-tests.api/runtests.py
regression-tests.api/test_Servers.py
regression-tests.api/test_Zones.py
regression-tests.api/test_helper.py

index b4d71c28f8b87ec7dd1232d5824c9a71c0a702b5..8de51a4ec9faee6f2b0eadb35c6549adb1d6d252 100644 (file)
@@ -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
index 9680de884f47229529107e83ba1c5b79e10806e8..b585b84fcc06e411dee35a454614cc8142b3dc1a 100755 (executable)
@@ -9,4 +9,4 @@ pip install -r requirements.txt
 
 set -e
 set -x
-exec ./runtests.py
+exec ./runtests.py "$@"
index c17909d13c0847c40df867059dfb42c715c4a0a6..bfd8fd442b739a0d6f3913aa6fd7aa3f6d0f3cef 100755 (executable)
@@ -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 ""
index 3895d87b5995477b326e5d9fd8cc68d55347b456..be0579bca76ba639e8009f4edb32ee73098fb28a 100644 (file)
@@ -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"))
index 8d5e4f05ce441e74acba0c4fc6a3d0b9f169d72b..a0b33efe614c5de57a192a2a9590ab6883f40c15 100644 (file)
@@ -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):
index 376e17fe3a3b526173966d2aa7fab14ea965fcfd..efc16d18dbc8885a47446ac4ab5e2271c8af9d81 100644 (file)
@@ -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')