]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
tests-extra: move maxminddb check into module check
authorDaniel Salzman <daniel.salzman@nic.cz>
Wed, 7 Nov 2018 09:54:03 +0000 (10:54 +0100)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 7 Nov 2018 09:58:42 +0000 (10:58 +0100)
tests-extra/tests/modules/geoip/test.py
tests-extra/tools/dnstest/module.py

index 47b80f35027ba6e55d53b98fe63352857116770b..a9642decfa3ae2a8f567088af14027c53e3678f9 100644 (file)
@@ -5,22 +5,7 @@
 from dnstest.test import Test
 from dnstest.module import ModGeoip
 from dnstest.utils import *
-from subprocess import Popen, PIPE
 import random
-import re
-
-def check_mmdb():
-    '''Checks the server binary for the MMDB_open function'''
-
-    try:
-        proc = Popen(ModGeoip._check_cmd(), stdout=PIPE, stderr=PIPE,
-                     universal_newlines=True)
-        (out, err) = proc.communicate()
-        if re.search("MMDB_open", out):
-            return
-        raise Skip()
-    except:
-        raise Skip("libmaxminddb not detected")
 
 t = Test(address=4, stress=False)
 knot = t.server("knot")
@@ -29,9 +14,9 @@ zone = t.zone("example.com.", storage=".")
 t.link(zone, knot)
 
 ModGeoip.check()
-check_mmdb()
 
-mod_geoip = ModGeoip(t.data_dir + "geo.conf", "geodb", t.data_dir + "db.mmdb", ["country/iso_code", "(id)city/geoname_id"])
+mod_geoip = ModGeoip(t.data_dir + "geo.conf", "geodb", t.data_dir + "db.mmdb",
+                     ["country/iso_code", "(id)city/geoname_id"])
 knot.add_module(zone, mod_geoip);
 
 t.start()
index 2923c4a0c530721bf6d90b5dbd3e00f891d4e85c..5a4c45b65af2c48c3062d09739b4a7c56246bec7 100644 (file)
@@ -292,7 +292,7 @@ class ModCookies(KnotModule):
 
 class ModQueryacl(KnotModule):
     '''Query ACL module'''
-    
+
     mod_name = "queryacl"
 
     def __init__(self, address=None, interface=None):
@@ -303,7 +303,7 @@ class ModQueryacl(KnotModule):
     def get_conf(self, conf=None):
         if not conf:
             conf = dnstest.config.KnotConf()
-        
+
         conf.begin(self.conf_name)
         conf.id_item("id", self.conf_id)
         if self.address:
@@ -332,6 +332,21 @@ class ModGeoip(KnotModule):
         self.geodb_file = geodb_file
         self.geodb_key = geodb_key
 
+    @classmethod
+    def check(self):
+        '''Extended module check by libmaxminddb dependency check'''
+        super().check()
+
+        try:
+            proc = Popen(self._check_cmd(), stdout=PIPE, stderr=PIPE,
+                         universal_newlines=True)
+            (out, err) = proc.communicate()
+            if re.search("MMDB_open", out):
+                return
+            raise Skip()
+        except:
+            raise Skip("Library 'maxminddb' not detected")
+
     def get_conf(self, conf=None):
         if not conf:
             conf = dnstest.config.KnotConf()