]> granicus.if.org Git - pdns/commitdiff
auth: lua records - remove "none" selector, add test for "all" backup selector
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 30 Nov 2018 10:40:35 +0000 (11:40 +0100)
committerCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Fri, 30 Nov 2018 10:40:35 +0000 (11:40 +0100)
docs/lua-records/functions.rst
pdns/lua-record.cc
regression-tests.auth-py/test_LuaRecords.py

index ab125acd67a78d7c2174ac9cd600ed4df0b9bfca..b655cb144974aca2a4e341ecebbc43cc42c0f06d 100644 (file)
@@ -46,8 +46,8 @@ Record creation functions
 
   Various options can be set in the ``options`` parameter:
 
-  - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
-  - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
+  - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all' (default to 'random').
+  - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all' (default to 'random').
   - ``source``: Source IP address to check from
 
 
@@ -65,8 +65,8 @@ Record creation functions
 
   Various options can be set in the ``options`` parameter:
 
-  - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
-  - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all', 'none' (default to 'random').
+  - ``selector``: used to pick the IP address from list of viable candidates. Choices include 'pickclosest', 'random', 'hashed', 'all' (default to 'random').
+  - ``backupSelector``: used to pick the IP address from list of all candidates if all addresses are down. Choices include 'pickclosest', 'random', 'hashed', 'all' (default to 'random').
   - ``source``: Source IP address to check from
   - ``stringmatch``: check ``url`` for this string, only declare 'up' if found
 
index 2f42e5ca83e96e41776c58047d8e5e7c62c3cd4e..cad20bd556186608d39586d0807c1cd10ea2f239 100644 (file)
@@ -419,9 +419,7 @@ static vector<ComboAddress> useSelector(const std::string &selector, const Combo
 {
   vector<ComboAddress> ret;
 
-  if(selector=="none")
-    return ret;
-  else if(selector=="all")
+  if(selector=="all")
     return candidates;
   else if(selector=="random")
     ret.emplace_back(pickrandom(candidates));
index 2a4578d8316653d78c7d736b29f88605a80f5c6a..ffe762af9798b7a191f4c2668808c2eb67c9d613 100644 (file)
@@ -45,6 +45,7 @@ web3.example.org.            3600 IN A    {prefix}.103
 all.ifportup                 3600 IN LUA  A     "ifportup(8080, {{'{prefix}.101', '{prefix}.102'}})"
 some.ifportup                3600 IN LUA  A     "ifportup(8080, {{'192.168.42.21', '{prefix}.102'}})"
 none.ifportup                3600 IN LUA  A     "ifportup(8080, {{'192.168.42.21', '192.168.21.42'}})"
+all.noneup.ifportup          3600 IN LUA  A     "ifportup(8080, {{'192.168.42.21', '192.168.21.42'}}, {{ backupSelector='all' }})"
 
 whashed.example.org.         3600 IN LUA  A     "pickwhashed({{ {{15, '1.2.3.4'}}, {{42, '4.3.2.1'}} }})"
 rand.example.org.            3600 IN LUA  A     "pickrandom({{'{prefix}.101', '{prefix}.102'}})"
@@ -257,6 +258,22 @@ any              IN           TXT "hello there"
         self.assertRcodeEqual(res, dns.rcode.NOERROR)
         self.assertAnyRRsetInAnswer(res, expected)
 
+    def testIfportupWithAllDownAndAllBackupSelector(self):
+        """
+        Basic ifportup() test with all ports DOWN, fallback to 'all' backup selector
+        """
+        name = 'all.noneup.ifportup.example.org.'
+        query = dns.message.make_query(name, dns.rdatatype.A)
+        expected = [dns.rrset.from_text(name, 0, dns.rdataclass.IN, dns.rdatatype.A, '192.168.42.21', '192.168.21.42')]
+
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.NOERROR)
+
+        time.sleep(1)
+        res = self.sendUDPQuery(query)
+        self.assertRcodeEqual(res, dns.rcode.NOERROR)
+        self.assertEqual(res.answer, expected)
+
     def testIfurlup(self):
         """
         Basic ifurlup() test
@@ -362,7 +379,7 @@ any              IN           TXT "hello there"
             ('1.2.3.0', 24,  '1.2.3.5'),
             ('17.1.0.0', 16, '17.1.2.4')
         ]
-                
+
         for (subnet, mask, ip) in queries:
             ecso = clientsubnetoption.ClientSubnetOption(subnet, mask)
             query = dns.message.make_query(name, 'A', 'IN', use_edns=True, payload=4096, options=[ecso])