From: Rob van der Linde Date: Thu, 8 Feb 2024 09:47:14 +0000 (+1300) Subject: netcmd: models: stop using LookupError exception and change it to NotFound X-Git-Tag: tdb-1.4.11~1764 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=128a5cf087b1f4e764f1e4afa0667a249346a810;p=thirdparty%2Fsamba.git netcmd: models: stop using LookupError exception and change it to NotFound LookupError is a base class for IndexError and KeyError and isn't really the appropriate exception. NotFound inherits from ModelError just like the other model exceptions. Signed-off-by: Rob van der Linde Reviewed-by: Andrew Bartlett Reviewed-by: Jo Sutton --- diff --git a/python/samba/netcmd/domain/auth/silo.py b/python/samba/netcmd/domain/auth/silo.py index 2e277610e8e..d35d5f716db 100644 --- a/python/samba/netcmd/domain/auth/silo.py +++ b/python/samba/netcmd/domain/auth/silo.py @@ -150,7 +150,7 @@ class cmd_domain_auth_silo_create(Command): """ try: return AuthenticationPolicy.lookup(ldb, name) - except (LookupError, ValueError) as e: + except (ModelError, ValueError) as e: raise CommandError(e) def run(self, hostopts=None, sambaopts=None, credopts=None, @@ -267,7 +267,7 @@ class cmd_domain_auth_silo_modify(Command): """ try: return AuthenticationPolicy.lookup(ldb, name) - except (LookupError, ModelError, ValueError) as e: + except (ModelError, ValueError) as e: raise CommandError(e) def run(self, hostopts=None, sambaopts=None, credopts=None, diff --git a/python/samba/netcmd/domain/claim/claim_type.py b/python/samba/netcmd/domain/claim/claim_type.py index c0825c660d2..754f8b11117 100644 --- a/python/samba/netcmd/domain/claim/claim_type.py +++ b/python/samba/netcmd/domain/claim/claim_type.py @@ -92,7 +92,7 @@ class cmd_domain_claim_claim_type_create(Command): applies_to = [ClassSchema.lookup(ldb, name) for name in class_names] attribute = AttributeSchema.lookup(ldb, attribute_name) value_type = ValueType.lookup(ldb, attribute) - except (LookupError, ModelError, ValueError) as e: + except (ModelError, ValueError) as e: raise CommandError(e) # Generate the new Claim Type cn. @@ -211,7 +211,7 @@ class cmd_domain_claim_claim_type_modify(Command): try: applies_to = [ClassSchema.lookup(ldb, name) for name in class_names] - except (LookupError, ValueError) as e: + except (ModelError, ValueError) as e: raise CommandError(e) claim_type.claim_type_applies_to_class = [obj.dn for obj in applies_to] diff --git a/python/samba/netcmd/domain/models/auth_policy.py b/python/samba/netcmd/domain/models/auth_policy.py index c56966c8e51..a41c43a90b1 100644 --- a/python/samba/netcmd/domain/models/auth_policy.py +++ b/python/samba/netcmd/domain/models/auth_policy.py @@ -86,11 +86,11 @@ class AuthenticationPolicy(Model): @staticmethod def lookup(ldb, name): - """Helper function to return auth policy or raise LookupError. + """Helper function to return auth policy or raise NotFound. :param ldb: Ldb connection :param name: Either DN or name of Authentication Policy - :raises: LookupError if not found + :raises: NotFound if not found :raises: ValueError if name is not set """ if not name: diff --git a/python/samba/netcmd/domain/models/schema.py b/python/samba/netcmd/domain/models/schema.py index 59ece05084a..221cd73eaf8 100644 --- a/python/samba/netcmd/domain/models/schema.py +++ b/python/samba/netcmd/domain/models/schema.py @@ -20,6 +20,7 @@ # along with this program. If not, see . # +from .exceptions import NotFound from .fields import BinaryField, BooleanField, DnField, GUIDField,\ IntegerField, StringField from .model import Model @@ -58,11 +59,11 @@ class ClassSchema(Model): @classmethod def lookup(cls, ldb, name): - """Helper function to lookup class or raise LookupError. + """Helper function to lookup class or raise NotFound. :param ldb: Ldb connection :param name: Class name - :raises: LookupError if not found + :raises: NotFound if not found :raises: ValueError if name is not provided """ if not name: @@ -70,7 +71,7 @@ class ClassSchema(Model): attr = cls.get(ldb, ldap_display_name=name) if attr is None: - raise LookupError(f"Could not locate {name} in class schema.") + raise NotFound(f"Could not locate {name} in class schema.") return attr @@ -107,11 +108,11 @@ class AttributeSchema(Model): @classmethod def lookup(cls, ldb, name): - """Helper function to lookup attribute or raise LookupError. + """Helper function to lookup attribute or raise NotFound. :param ldb: Ldb connection :param name: Attribute name - :raises: LookupError if not found + :raises: NotFound if not found :raises: ValueError if name is not provided """ if not name: @@ -119,6 +120,6 @@ class AttributeSchema(Model): attr = cls.get(ldb, ldap_display_name=name) if attr is None: - raise LookupError(f"Could not locate {name} in attribute schema.") + raise NotFound(f"Could not locate {name} in attribute schema.") return attr diff --git a/python/samba/netcmd/domain/models/value_type.py b/python/samba/netcmd/domain/models/value_type.py index 00a4e072427..84fe27995cc 100644 --- a/python/samba/netcmd/domain/models/value_type.py +++ b/python/samba/netcmd/domain/models/value_type.py @@ -20,6 +20,7 @@ # along with this program. If not, see . # +from .exceptions import NotFound from .fields import BooleanField, DnField, IntegerField, StringField from .model import Model @@ -67,11 +68,11 @@ class ValueType(Model): @classmethod def lookup(cls, ldb, attribute): - """Helper function to get ValueType by attribute or raise LookupError. + """Helper function to get ValueType by attribute or raise NotFound. :param ldb: Ldb connection :param attribute: AttributeSchema object - :raises: LookupError if not found + :raises: NotFound if not found :raises: ValueError for unknown attribute syntax """ # If attribute is None. @@ -87,8 +88,7 @@ class ValueType(Model): # This should always return something but should still be handled. value_type = cls.get(ldb, cn=cn) if value_type is None: - raise LookupError( - f"Could not find claim value type for {attribute}.") + raise NotFound(f"Could not find claim value type for {attribute}.") return value_type