From 707cedf34aa34a07e45f75f3f225276ae43c1537 Mon Sep 17 00:00:00 2001 From: Charles-Henri Bruyand Date: Fri, 30 Nov 2018 11:40:35 +0100 Subject: [PATCH] auth: lua records - remove "none" selector, add test for "all" backup selector --- docs/lua-records/functions.rst | 8 ++++---- pdns/lua-record.cc | 4 +--- regression-tests.auth-py/test_LuaRecords.py | 19 ++++++++++++++++++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/docs/lua-records/functions.rst b/docs/lua-records/functions.rst index ab125acd67..b655cb1449 100644 --- a/docs/lua-records/functions.rst +++ b/docs/lua-records/functions.rst @@ -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 diff --git a/pdns/lua-record.cc b/pdns/lua-record.cc index 2f42e5ca83..cad20bd556 100644 --- a/pdns/lua-record.cc +++ b/pdns/lua-record.cc @@ -419,9 +419,7 @@ static vector useSelector(const std::string &selector, const Combo { vector ret; - if(selector=="none") - return ret; - else if(selector=="all") + if(selector=="all") return candidates; else if(selector=="random") ret.emplace_back(pickrandom(candidates)); diff --git a/regression-tests.auth-py/test_LuaRecords.py b/regression-tests.auth-py/test_LuaRecords.py index 2a4578d831..ffe762af97 100644 --- a/regression-tests.auth-py/test_LuaRecords.py +++ b/regression-tests.auth-py/test_LuaRecords.py @@ -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]) -- 2.47.2