From: Štěpán Balážik Date: Wed, 28 Jan 2026 14:12:45 +0000 (+0100) Subject: Fix pylint's 'invalid-name' errors X-Git-Tag: v9.21.19~15^2~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=50ed74197cee16ff9df55175a251c341a191b0b3;p=thirdparty%2Fbind9.git Fix pylint's 'invalid-name' errors Where possible comply with the naming rules. Add exceptions for the function names used in KASP tests. --- diff --git a/bin/tests/system/dnssec/tests_signing.py b/bin/tests/system/dnssec/tests_signing.py index 8ed481025ac..6eb9f9cba4d 100644 --- a/bin/tests/system/dnssec/tests_signing.py +++ b/bin/tests/system/dnssec/tests_signing.py @@ -455,13 +455,13 @@ def test_offline_ksk_signing(ns2): def ksk_remove(): isctest.log.info("remove the KSK from disk") - os.rename(f"ns2/{KSK}.key", f"ns2/{KSK}.key.bak") - os.rename(f"ns2/{KSK}.private", f"ns2/{KSK}.private.bak") + os.rename(f"ns2/{ksk}.key", f"ns2/{ksk}.key.bak") + os.rename(f"ns2/{ksk}.private", f"ns2/{ksk}.private.bak") def ksk_recover(): isctest.log.info("put back the KSK") - os.rename(f"ns2/{KSK}.key.bak", f"ns2/{KSK}.key") - os.rename(f"ns2/{KSK}.private.bak", f"ns2/{KSK}.private") + os.rename(f"ns2/{ksk}.key.bak", f"ns2/{ksk}.key") + os.rename(f"ns2/{ksk}.private.bak", f"ns2/{ksk}.private") def loadkeys(): pattern = Re(f"{zone}/IN.*next key event") @@ -472,26 +472,26 @@ def test_offline_ksk_signing(ns2): ksk_only_types = ["DNSKEY", "CDNSKEY", "CDS"] zone = "updatecheck-kskonly.secure" - KSK = getfrom(f"ns2/{zone}.ksk.key") - ZSK = getfrom(f"ns2/{zone}.zsk.key") - KSKID = int(getfrom(f"ns2/{zone}.ksk.id")) - ZSKID = int(getfrom(f"ns2/{zone}.zsk.id")) + ksk = getfrom(f"ns2/{zone}.ksk.key") + zsk = getfrom(f"ns2/{zone}.zsk.key") + ksk_id = int(getfrom(f"ns2/{zone}.ksk.id")) + zsk_id = int(getfrom(f"ns2/{zone}.zsk.id")) # set key state for KSK. the ZSK rollovers below assume that there is a # chain of trust established, so we tell named that the DS is in # omnipresent state. timings = SettimeOptions(d="OMNIPRESENT now") - setkeytimes(KSK, timings, keydir="ns2") + setkeytimes(ksk, timings, keydir="ns2") isctest.log.info("check state before KSK is made offline") isctest.log.info("make sure certain types are signed with KSK only") - check_signing_keys(ksk_only_types, expect=[KSKID], prohibit=[ZSKID]) + check_signing_keys(ksk_only_types, expect=[ksk_id], prohibit=[zsk_id]) isctest.log.info("check SOA is signed with ZSK only") - check_signing_keys(["SOA"], expect=[ZSKID], prohibit=[KSKID]) + check_signing_keys(["SOA"], expect=[zsk_id], prohibit=[ksk_id]) isctest.log.info("roll the ZSK") - ZSK2 = keygen( + zsk_2 = keygen( "-qKns2", "-Pnone", "-Anone", @@ -501,27 +501,27 @@ def test_offline_ksk_signing(ns2): os.environ["DEFAULT_BITS"], zone, ) - ZSKID2 = getkeyid(ZSK2) + zsk_2_id = getkeyid(zsk_2) isctest.log.info("prepublish new ZSK") - ns2.rndc(f"dnssec -rollover -key {ZSKID} {zone}") + ns2.rndc(f"dnssec -rollover -key {zsk_id} {zone}") isctest.run.retry_with_timeout(check_zskcount, 5) isctest.log.info("make the new ZSK active") timings = SettimeOptions(I="now") - setkeytimes(ZSK, timings, keydir="ns2") + setkeytimes(zsk, timings, keydir="ns2") timings = SettimeOptions( A="now", k="OMNIPRESENT now", ) - setkeytimes(ZSK2, timings, keydir="ns2") + setkeytimes(zsk_2, timings, keydir="ns2") loadkeys() with ns2.watch_log_from_start() as watcher: watcher.wait_for_line( - [f"{ZSKID2} (ZSK) is now active", f"{ZSKID} (ZSK) is now inactive"] + [f"{zsk_2_id} (ZSK) is now active", f"{zsk_id} (ZSK) is now inactive"] ) ksk_remove() @@ -536,13 +536,13 @@ def test_offline_ksk_signing(ns2): "redo the tests now that the zone is updated and the KSK is offline" ) isctest.log.info("make sure certain types are signed with KSK only") - check_signing_keys(ksk_only_types, expect=[KSKID], prohibit=[ZSKID, ZSKID2]) + check_signing_keys(ksk_only_types, expect=[ksk_id], prohibit=[zsk_id, zsk_2_id]) isctest.log.info("check TXT, SOA are signed with ZSK2 only") def check_txt_soa_zsk2(): return check_signing_keys( - ["TXT", "SOA"], expect=[ZSKID2], prohibit=[KSKID, ZSKID] + ["TXT", "SOA"], expect=[zsk_2_id], prohibit=[ksk_id, zsk_id] ) isctest.run.retry_with_timeout(check_txt_soa_zsk2, 5) @@ -550,7 +550,7 @@ def test_offline_ksk_signing(ns2): ksk_recover() isctest.log.info("roll the ZSK again") - ZSK3 = keygen( + zsk_3 = keygen( "-qKns2", "-Pnone", "-Anone", @@ -560,7 +560,7 @@ def test_offline_ksk_signing(ns2): os.environ["DEFAULT_BITS"], zone, ) - ZSKID3 = getkeyid(ZSK3) + zsk_3_id = getkeyid(zsk_3) isctest.log.info("delete old ZSK, schedule ZSK2 inactive, pre-publish ZSK3") @@ -569,18 +569,18 @@ def test_offline_ksk_signing(ns2): z="HIDDEN now", D="now", ) - setkeytimes(ZSK, timings, keydir="ns2") + setkeytimes(zsk, timings, keydir="ns2") timings = SettimeOptions( k="OMNIPRESENT now", z="OMNIPRESENT now", ) - setkeytimes(ZSK2, timings, keydir="ns2") + setkeytimes(zsk_2, timings, keydir="ns2") loadkeys() - ns2.rndc(f"dnssec -rollover -key {ZSKID2} {zone}") + ns2.rndc(f"dnssec -rollover -key {zsk_2_id} {zone}") with ns2.watch_log_from_start() as watcher: - watcher.wait_for_line(f"{ZSKID3} (ZSK) is now published") + watcher.wait_for_line(f"{zsk_3_id} (ZSK) is now published") ksk_remove() @@ -594,13 +594,15 @@ def test_offline_ksk_signing(ns2): isctest.log.info("redo the tests now that the ZSK roll has deleted the old key") isctest.log.info("make sure certain types are signed with KSK only") - check_signing_keys(ksk_only_types, expect=[KSKID], prohibit=[ZSKID, ZSKID2, ZSKID3]) + check_signing_keys( + ksk_only_types, expect=[ksk_id], prohibit=[zsk_id, zsk_2_id, zsk_3_id] + ) isctest.log.info("check A, TXT, SOA are signed with ZSK2 only") def check_a_txt_soa_zsk2(): return check_signing_keys( - ["A", "TXT", "SOA"], expect=[ZSKID2], prohibit=[KSKID, ZSKID, ZSKID3] + ["A", "TXT", "SOA"], expect=[zsk_2_id], prohibit=[ksk_id, zsk_id, zsk_3_id] ) isctest.run.retry_with_timeout(check_a_txt_soa_zsk2, 5) @@ -610,18 +612,18 @@ def test_offline_ksk_signing(ns2): isctest.log.info("make ZSK3 active") timings = SettimeOptions(I="now") - setkeytimes(ZSK2, timings, keydir="ns2") + setkeytimes(zsk_2, timings, keydir="ns2") timings = SettimeOptions( k="OMNIPRESENT now", A="now", ) - setkeytimes(ZSK3, timings, keydir="ns2") + setkeytimes(zsk_3, timings, keydir="ns2") loadkeys() with ns2.watch_log_from_start() as watcher: watcher.wait_for_line( - [f"{ZSKID3} (ZSK) is now active", f"{ZSKID2} (ZSK) is now inactive"] + [f"{zsk_3_id} (ZSK) is now active", f"{zsk_2_id} (ZSK) is now inactive"] ) ksk_remove() @@ -636,15 +638,17 @@ def test_offline_ksk_signing(ns2): isctest.log.info("redo the tests one last time") isctest.log.info("make sure certain types are signed with KSK only") - check_signing_keys(ksk_only_types, expect=[KSKID], prohibit=[ZSKID, ZSKID2, ZSKID3]) + check_signing_keys( + ksk_only_types, expect=[ksk_id], prohibit=[zsk_id, zsk_2_id, zsk_3_id] + ) isctest.log.info("check A, TXT, SOA are signed with ZSK2 only") def check_aaaa_a_txt_soa_zsk3(): return check_signing_keys( ["AAAA", "A", "TXT", "SOA"], - expect=[ZSKID3], - prohibit=[KSKID, ZSKID, ZSKID2], + expect=[zsk_3_id], + prohibit=[ksk_id, zsk_id, zsk_2_id], ) isctest.run.retry_with_timeout(check_aaaa_a_txt_soa_zsk3, 5) diff --git a/bin/tests/system/isctest/kasp.py b/bin/tests/system/isctest/kasp.py index bf7b1d25739..96d874fa296 100644 --- a/bin/tests/system/isctest/kasp.py +++ b/bin/tests/system/isctest/kasp.py @@ -86,24 +86,24 @@ def Iret(config, zsk=True, ksk=False, rollover=True, smooth=True): sign_delay = config["signatures-validity"] - config["signatures-refresh"] safety_interval = config["retire-safety"] - iretKSK = timedelta(0) + iret_ksk = timedelta(0) if ksk: # KSK: Double-KSK Method: Iret = DprpP + TTLds - iretKSK = ( + iret_ksk = ( config["parent-propagation-delay"] + config["ds-ttl"] + safety_interval ) - iretZSK = timedelta(0) + iret_zsk = timedelta(0) if zsk: # ZSK: Pre-Publication Method: Iret = Dsgn + Dprp + TTLsig - iretZSK = ( + iret_zsk = ( sign_delay + config["zone-propagation-delay"] + config["max-zone-ttl"] + safety_interval ) - return max(iretKSK, iretZSK) + return max(iret_ksk, iret_zsk) @total_ordering @@ -314,6 +314,7 @@ class KeyProperties: self.timing["ZRRSIGChange"] = None +# pylint: disable=invalid-name @dataclass class SettimeOptions: diff --git a/bin/tests/system/nta/tests_nta.py b/bin/tests/system/nta/tests_nta.py index 70e8f088914..d2b056cb76f 100644 --- a/bin/tests/system/nta/tests_nta.py +++ b/bin/tests/system/nta/tests_nta.py @@ -22,8 +22,7 @@ def active(blob): # global start-time variable # pylint: disable=global-statement -# pylint: disable=global-variable-not-assigned -start = 0 +START = 0 def test_initial(): @@ -70,7 +69,7 @@ def test_nta_bogus_lifetimes(servers): def test_nta_install(servers): - global start + global START ns4 = servers["ns4"] ns4.rndc("nta -f -l 20s bogus.example") @@ -91,12 +90,11 @@ def test_nta_install(servers): response = ns4.rndc("nta -d") assert len(response.out.splitlines()) == 5 - start = time.time() + START = time.time() def test_nta_behavior(servers): - global start - assert start, "test_nta_behavior must be run as part of the full NTA test" + assert START, "test_nta_behavior must be run as part of the full NTA test" m = isctest.query.create("a.bogus.example.", "A") res = isctest.query.tcp(m, "10.53.0.4") @@ -129,7 +127,7 @@ def test_nta_behavior(servers): # is configured to 9s, so at t=10 the NTAs for secure.example and # fakenode.secure.example should both be lifted, while badds.example # should still be going. - delay = start + 10 - time.time() + delay = START + 10 - time.time() if delay > 0: time.sleep(delay) @@ -151,7 +149,7 @@ def test_nta_behavior(servers): # bogus.example was set to expire in 20s, so at t=13 # it should still be NTA'd, but badds.example used the default # lifetime of 12s, so it should revert to SERVFAIL now. - delay = start + 13 - time.time() + delay = START + 13 - time.time() if delay > 0: time.sleep(delay) @@ -177,7 +175,7 @@ def test_nta_behavior(servers): isctest.check.adflag(res) # at t=21, all the NTAs should have expired. - delay = start + 21 - time.time() + delay = START + 21 - time.time() if delay > 0: time.sleep(delay) @@ -225,15 +223,15 @@ def test_nta_removals(servers): def test_nta_restarts(servers): - global start - assert start, "test_nta_restarts must be run as part of the full NTA test" + global START + assert START, "test_nta_restarts must be run as part of the full NTA test" # test NTA persistence across restarts ns4 = servers["ns4"] response = ns4.rndc("nta -d") assert active(response.out) == 0 - start = time.time() + START = time.time() ns4.rndc("nta -f -l 30s bogus.example") ns4.rndc("nta -f -l 10s badds.example") response = ns4.rndc("nta -d") @@ -244,7 +242,7 @@ def test_nta_restarts(servers): # wait 14s before restarting. badds.example's NTA (lifetime=10s) should # have expired, and bogus.example should still be running. - delay = start + 14 - time.time() + delay = START + 14 - time.time() if delay > 0: time.sleep(delay) ns4.start(["--noclean", "--restart", "--port", os.environ["PORT"]]) @@ -266,8 +264,8 @@ def test_nta_restarts(servers): def test_nta_regular(servers): - global start - assert start, "test_nta_regular must be run as part of the full NTA test" + global START + assert START, "test_nta_regular must be run as part of the full NTA test" # check "regular" attribute in NTA file ns4 = servers["ns4"] @@ -297,8 +295,8 @@ def test_nta_regular(servers): # nta-recheck is configured as 9s, so at t=12 the NTA for # secure.example. should be lifted as it is not a "forced" NTA. - start = time.mktime(now) - delay = start + 12 - time.time() + START = time.mktime(now) + delay = START + 12 - time.time() if delay > 0: time.sleep(delay) @@ -314,8 +312,8 @@ def test_nta_regular(servers): def test_nta_forced(servers): - global start - assert start, "test_nta_regular must be run as part of the full NTA test" + global START + assert START, "test_nta_regular must be run as part of the full NTA test" # check "forced" attribute in NTA file ns4 = servers["ns4"] @@ -348,8 +346,8 @@ def test_nta_forced(servers): # nta-recheck is configured as 9s. at t=12 the NTA for # secure.example. should NOT be lifted as it is "forced". - start = time.mktime(now) - delay = start + 12 - time.time() + START = time.mktime(now) + delay = START + 12 - time.time() if delay > 0: time.sleep(delay) diff --git a/bin/tests/system/rndc/tests_cve-2023-3341.py b/bin/tests/system/rndc/tests_cve_2023_3341.py similarity index 100% rename from bin/tests/system/rndc/tests_cve-2023-3341.py rename to bin/tests/system/rndc/tests_cve_2023_3341.py diff --git a/bin/tests/system/statschannel/generic.py b/bin/tests/system/statschannel/generic.py index e77f3fc37fa..09a374e1207 100644 --- a/bin/tests/system/statschannel/generic.py +++ b/bin/tests/system/statschannel/generic.py @@ -21,7 +21,7 @@ import dns.rcode import isctest # ISO datetime format without msec -fmt = "%Y-%m-%dT%H:%M:%SZ" +FMT = "%Y-%m-%dT%H:%M:%SZ" # The constants were taken from BIND 9 source code (lib/dns/zone.c) max_refresh = timedelta(seconds=2419200) # 4 weeks @@ -29,7 +29,7 @@ max_expires = timedelta(seconds=14515200) # 24 weeks dayzero = datetime.utcfromtimestamp(0).replace(microsecond=0) # Wait for the secondary zone files to appear to extract their mtime -max_secondary_zone_waittime_sec = 5 +MAX_SECONDARY_ZONE_WAITTIME_SEC = 5 # Generic helper functions @@ -45,7 +45,7 @@ def check_refresh(refresh, min_time, max_time): def check_loaded(loaded, expected, now): # Sanity check the zone timers values - assert (loaded - expected).total_seconds() < max_secondary_zone_waittime_sec + assert (loaded - expected).total_seconds() < MAX_SECONDARY_ZONE_WAITTIME_SEC assert loaded <= now @@ -97,7 +97,7 @@ def test_zone_timers_secondary(fetch_zones, load_timers, **kwargs): zonedir = kwargs["zonedir"] # If any one of the zone files isn't ready, then retry until timeout. - tries = max_secondary_zone_waittime_sec + tries = MAX_SECONDARY_ZONE_WAITTIME_SEC while tries >= 0: zones = fetch_zones(statsip, statsport) again = False diff --git a/bin/tests/system/statschannel/tests_json.py b/bin/tests/system/statschannel/tests_json.py index 72a6e41e1b0..30348f4e69f 100755 --- a/bin/tests/system/statschannel/tests_json.py +++ b/bin/tests/system/statschannel/tests_json.py @@ -67,7 +67,7 @@ def load_timers_json(zone, primary=True): # Check if the primary zone timer exists assert "loaded" in zone - loaded = datetime.strptime(zone["loaded"], generic.fmt) + loaded = datetime.strptime(zone["loaded"], generic.FMT) if primary: # Check if the secondary zone timers does not exist @@ -78,8 +78,8 @@ def load_timers_json(zone, primary=True): else: assert "expires" in zone assert "refresh" in zone - expires = datetime.strptime(zone["expires"], generic.fmt) - refresh = datetime.strptime(zone["refresh"], generic.fmt) + expires = datetime.strptime(zone["expires"], generic.FMT) + refresh = datetime.strptime(zone["refresh"], generic.FMT) return (name, loaded, expires, refresh) diff --git a/bin/tests/system/statschannel/tests_xml.py b/bin/tests/system/statschannel/tests_xml.py index e0c8dd3425d..1ceb46f9b4b 100755 --- a/bin/tests/system/statschannel/tests_xml.py +++ b/bin/tests/system/statschannel/tests_xml.py @@ -95,7 +95,7 @@ def load_timers_xml(zone, primary=True): loaded_el = zone.find("loaded") assert loaded_el is not None - loaded = datetime.strptime(loaded_el.text, generic.fmt) + loaded = datetime.strptime(loaded_el.text, generic.FMT) expires_el = zone.find("expires") refresh_el = zone.find("refresh") @@ -107,8 +107,8 @@ def load_timers_xml(zone, primary=True): else: assert expires_el is not None assert refresh_el is not None - expires = datetime.strptime(expires_el.text, generic.fmt) - refresh = datetime.strptime(refresh_el.text, generic.fmt) + expires = datetime.strptime(expires_el.text, generic.FMT) + refresh = datetime.strptime(refresh_el.text, generic.FMT) return (name, loaded, expires, refresh) diff --git a/bin/tests/system/xferquota/setup.py b/bin/tests/system/xferquota/setup.py index ec457bf171f..bd8f96bc0ca 100644 --- a/bin/tests/system/xferquota/setup.py +++ b/bin/tests/system/xferquota/setup.py @@ -15,9 +15,9 @@ # Set up test data for zone transfer quota tests. # -zones = 300 +ZONES = 300 -for z in range(zones): +for z in range(ZONES): zn = f"zone{z:06d}.example" with open(f"ns1/{zn}.db", "w", encoding="utf-8") as f: f.write("""$TTL 300 @@ -35,7 +35,7 @@ xyzzy A 10.0.0.2 with open("ns1/zones.conf", "w", encoding="utf-8") as priconf, open( "ns2/zones.conf", "w", encoding="utf-8" ) as secconf: - for z in range(zones): + for z in range(ZONES): zn = f"zone{z:06d}.example" priconf.write(f'zone "{zn}" {{ type primary; file "{zn}.db"; }};\n') secconf.write( diff --git a/pyproject.toml b/pyproject.toml index 99ce2021e4b..9b6d430ec91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,13 +9,18 @@ # See the COPYRIGHT file distributed with this work for additional # information regarding copyright ownership. +[tool.pylint.basic] +good-names-rgxs = [ + # Allow names from KASP tests + "I(pub|ret)C?", + "T(act|pub|ret|rem|sbm)N1?", +] [tool.pylint.imports] deprecated-modules = [ "dns.resolver", ] [tool.pylint.messages_control] disable = [ - "C0103", # invalid-name "C0114", # missing-module-docstring "C0115", # missing-class-docstring "C0116", # missing-function-docstring