]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Fix 'Too many return statements' pylint error
authorŠtěpán Balážik <stepan@isc.org>
Wed, 28 Jan 2026 14:21:58 +0000 (15:21 +0100)
committerŠtěpán Balážik <stepan@isc.org>
Fri, 20 Feb 2026 14:17:32 +0000 (15:17 +0100)
Refactor `Key.match_properties` into multiple functions.

bin/tests/system/isctest/kasp.py
pyproject.toml

index 96d874fa296794ade9b7b9a37523da88cb6f5a71..9364f3c752df053b83bd3e8284aee23366a5ce26 100644 (file)
@@ -650,14 +650,10 @@ class Key:
             isctest.log.debug(f"{self.name} {key} TIMING UNEXPECTED: {value}")
         return value == "undefined"
 
-    def match_properties(self, zone, properties):
+    def _check_public_key_file(self, zone, properties):
         """
-        Check the key with given properties.
+        Check the public key file.
         """
-        # Check file existence.
-        # Noop. If file is missing then the get_metadata calls will fail.
-
-        # Check the public key file.
         role = properties.role_full()
         comment = f"This is a {role} key, keyid {self.tag}, for {zone}."
         if not isctest.util.file_contents_contain(self.keyfile, comment):
@@ -672,31 +668,45 @@ class Key:
             isctest.log.debug(f"{self.name} DNSKEY MISMATCH: expected '{dnskey}'")
             return False
 
-        # Now check the private key file.
-        if properties.private:
-            # Retrieve creation date.
-            created = self.get_metadata("Generated")
+        return True
 
-            pval = self.get_metadata("Created", file=self.privatefile)
-            if pval != created:
-                isctest.log.debug(
-                    f"{self.name} Created METADATA MISMATCH: {pval} - {created}"
-                )
-                return False
-            pval = self.get_metadata("Private-key-format", file=self.privatefile)
-            if pval != "v1.3":
-                isctest.log.debug(
-                    f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3"
-                )
-                return False
-            pval = self.get_metadata("Algorithm", file=self.privatefile)
-            if pval != f"{alg}":
-                isctest.log.debug(
-                    f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}"
-                )
-                return False
+    def _check_private_key_file(self, properties):
+        """
+        Check the private key file.
+        """
+        if not properties.private:
+            return True
+
+        alg = properties.metadata["Algorithm"]
+
+        # Retrieve creation date.
+        created = self.get_metadata("Generated")
+
+        pval = self.get_metadata("Created", file=self.privatefile)
+        if pval != created:
+            isctest.log.debug(
+                f"{self.name} Created METADATA MISMATCH: {pval} - {created}"
+            )
+            return False
+        pval = self.get_metadata("Private-key-format", file=self.privatefile)
+        if pval != "v1.3":
+            isctest.log.debug(
+                f"{self.name} Private-key-format METADATA MISMATCH: {pval} - v1.3"
+            )
+            return False
+        pval = self.get_metadata("Algorithm", file=self.privatefile)
+        if pval != f"{alg}":
+            isctest.log.debug(
+                f"{self.name} Algorithm METADATA MISMATCH: {pval} - {alg}"
+            )
+            return False
 
-        # Now check the key state file.
+        return True
+
+    def _check_key_state_file(self, zone, properties):
+        """
+        Check the key state file.
+        """
         if properties.legacy:
             return True
 
@@ -727,7 +737,24 @@ class Key:
         if self.tag > properties.keytag_max:
             return False
 
-        # A match is found.
+        return True
+
+    def match_properties(self, zone, properties):
+        """
+        Check the key with given properties.
+        """
+        # Check file existence.
+        # Noop. If file is missing then the get_metadata calls will fail.
+
+        if not self._check_public_key_file(zone, properties):
+            return False
+
+        if not self._check_private_key_file(properties):
+            return False
+
+        if not self._check_key_state_file(zone, properties):
+            return False
+
         return True
 
     def match_timingmetadata(self, timings, file=None, comment=False):
index 9b6d430ec913e4498d77bb2f5088d5f86f020943..4aed089859ec36a81b7cdd557620f7d8c4252859 100644 (file)
@@ -29,7 +29,6 @@ disable = [
   "R0801", # duplicate-code
   "R0902", # too-many-instance-attributes
   "R0903", # too-few-public-methods
-  "R0911", # too-many-return-statements
   "R0912", # too-many-branches
   "R0913", # too-many-arguments
   "R0914", # too-many-locals