Browse Source

[1457] refactor: initialize ZoneFinder once per session

Jelte Jansen 13 years ago
parent
commit
0bfaa798f7
1 changed files with 39 additions and 43 deletions
  1. 39 43
      src/lib/python/isc/ddns/session.py

+ 39 - 43
src/lib/python/isc/ddns/session.py

@@ -19,6 +19,7 @@ from isc.log import *
 from isc.ddns.logger import logger, ClientFormatter, ZoneFormatter,\
 from isc.ddns.logger import logger, ClientFormatter, ZoneFormatter,\
                             RRsetFormatter
                             RRsetFormatter
 from isc.log_messages.libddns_messages import *
 from isc.log_messages.libddns_messages import *
+from isc.datasrc import ZoneFinder
 import isc.xfrin.diff
 import isc.xfrin.diff
 import copy
 import copy
 
 
@@ -233,6 +234,7 @@ class UpdateSession:
             self.zname = zname
             self.zname = zname
             self.zclass = zclass
             self.zclass = zclass
             self.datasrc_client = datasrc_client
             self.datasrc_client = datasrc_client
+            _, self.finder = datasrc_client.find_zone(zname)
             return datasrc_client, zname, zclass
             return datasrc_client, zname, zclass
         elif zone_type == isc.ddns.zone_config.ZONE_SECONDARY:
         elif zone_type == isc.ddns.zone_config.ZONE_SECONDARY:
             # We are a secondary server; since we don't yet support update
             # We are a secondary server; since we don't yet support update
@@ -271,10 +273,10 @@ class UpdateSession:
            only return what the result code would be (and not read/copy
            only return what the result code would be (and not read/copy
            any actual data).
            any actual data).
         '''
         '''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, _, _ = self.finder.find(rrset.get_name(), rrset.get_type(),
-        result, _, _ = finder.find(rrset.get_name(), rrset.get_type(),
+                                        ZoneFinder.NO_WILDCARD |
-                                   finder.NO_WILDCARD | finder.FIND_GLUE_OK)
+                                        ZoneFinder.FIND_GLUE_OK)
-        return result == finder.SUCCESS
+        return result == ZoneFinder.SUCCESS
 
 
     def __prereq_rrset_exists_value(self, rrset):
     def __prereq_rrset_exists_value(self, rrset):
         '''Check whether an rrset that matches name, type, and rdata(s) of the
         '''Check whether an rrset that matches name, type, and rdata(s) of the
@@ -282,11 +284,11 @@ class UpdateSession:
            RFC2136 Section 2.4.2
            RFC2136 Section 2.4.2
            Returns True if the prerequisite is satisfied, False otherwise.
            Returns True if the prerequisite is satisfied, False otherwise.
         '''
         '''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, found_rrset, _ = self.finder.find(rrset.get_name(),
-        result, found_rrset, _ = finder.find(rrset.get_name(), rrset.get_type(),
+                                                  rrset.get_type(),
-                                             finder.NO_WILDCARD |
+                                                  ZoneFinder.NO_WILDCARD |
-                                             finder.FIND_GLUE_OK)
+                                                  ZoneFinder.FIND_GLUE_OK)
-        if result == finder.SUCCESS and\
+        if result == ZoneFinder.SUCCESS and\
            rrset.get_name() == found_rrset.get_name() and\
            rrset.get_name() == found_rrset.get_name() and\
            rrset.get_type() == found_rrset.get_type():
            rrset.get_type() == found_rrset.get_type():
             # We need to match all actual RRs, unfortunately there is no
             # We need to match all actual RRs, unfortunately there is no
@@ -324,12 +326,11 @@ class UpdateSession:
            to only return what the result code would be (and not read/copy
            to only return what the result code would be (and not read/copy
            any actual data).
            any actual data).
         '''
         '''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, rrsets, flags = self.finder.find_all(rrset.get_name(),
-        result, rrsets, flags = finder.find_all(rrset.get_name(),
+                                                     ZoneFinder.NO_WILDCARD |
-                                                finder.NO_WILDCARD |
+                                                     ZoneFinder.FIND_GLUE_OK)
-                                                finder.FIND_GLUE_OK)
+        if result == ZoneFinder.SUCCESS and\
-        if result == finder.SUCCESS and\
+           (flags & ZoneFinder.RESULT_WILDCARD == 0):
-           (flags & finder.RESULT_WILDCARD == 0):
             return True
             return True
         return False
         return False
 
 
@@ -543,17 +544,16 @@ class UpdateSession:
         # is not explicitely ignored here)
         # is not explicitely ignored here)
         if rrset.get_type() == RRType.SOA():
         if rrset.get_type() == RRType.SOA():
             return
             return
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, orig_rrset, _ = self.finder.find(rrset.get_name(),
-        result, orig_rrset, _ = finder.find(rrset.get_name(),
+                                                 rrset.get_type(),
-                                            rrset.get_type(),
+                                                 ZoneFinder.NO_WILDCARD |
-                                            finder.NO_WILDCARD |
+                                                 ZoneFinder.FIND_GLUE_OK)
-                                            finder.FIND_GLUE_OK)
+        if result == self.finder.CNAME:
-        if result == finder.CNAME:
             # Ignore non-cname rrs that try to update CNAME records
             # Ignore non-cname rrs that try to update CNAME records
             # (if rrset itself is a CNAME, the finder result would be
             # (if rrset itself is a CNAME, the finder result would be
             # SUCCESS, see next case)
             # SUCCESS, see next case)
             return
             return
-        elif result == finder.SUCCESS:
+        elif result == ZoneFinder.SUCCESS:
             # if update is cname, and zone rr is not, ignore
             # if update is cname, and zone rr is not, ignore
             if rrset.get_type() == RRType.CNAME():
             if rrset.get_type() == RRType.CNAME():
                 # Remove original CNAME record (the new one
                 # Remove original CNAME record (the new one
@@ -563,7 +563,7 @@ class UpdateSession:
             # are special Update equality rules such as for WKS, and
             # are special Update equality rules such as for WKS, and
             # we do have support for the type, this is where the check
             # we do have support for the type, this is where the check
             # (and potential delete) would go.
             # (and potential delete) would go.
-        elif result == finder.NXRRSET:
+        elif result == ZoneFinder.NXRRSET:
             # There is data present, but not for this type.
             # There is data present, but not for this type.
             # If this type is CNAME, ignore the update
             # If this type is CNAME, ignore the update
             if rrset.get_type() == RRType.CNAME():
             if rrset.get_type() == RRType.CNAME():
@@ -577,11 +577,10 @@ class UpdateSession:
            Special cases: if the delete statement is for the
            Special cases: if the delete statement is for the
            zone's apex, and the type is either SOA or NS, it
            zone's apex, and the type is either SOA or NS, it
            is ignored.'''
            is ignored.'''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, to_delete, _ = self.finder.find(rrset.get_name(),
-        result, to_delete, _ = finder.find(rrset.get_name(),
+                                                rrset.get_type(),
-                                           rrset.get_type(),
+                                                ZoneFinder.NO_WILDCARD |
-                                           finder.NO_WILDCARD |
+                                                ZoneFinder.FIND_GLUE_OK)
-                                           finder.FIND_GLUE_OK)
         if to_delete.get_name() == self.zname and\
         if to_delete.get_name() == self.zname and\
            (to_delete.get_type() == RRType.SOA() or\
            (to_delete.get_type() == RRType.SOA() or\
             to_delete.get_type() == RRType.NS()):
             to_delete.get_type() == RRType.NS()):
@@ -595,11 +594,10 @@ class UpdateSession:
            may never be removed (and any action that would do so
            may never be removed (and any action that would do so
            should be ignored).
            should be ignored).
         '''
         '''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, orig_rrset, _ = self.finder.find(rrset.get_name(),
-        result, orig_rrset, _ = finder.find(rrset.get_name(),
+                                                 rrset.get_type(),
-                                            rrset.get_type(),
+                                                 ZoneFinder.NO_WILDCARD |
-                                            finder.NO_WILDCARD |
+                                                 ZoneFinder.FIND_GLUE_OK)
-                                            finder.FIND_GLUE_OK)
         # Even a real rrset comparison wouldn't help here...
         # Even a real rrset comparison wouldn't help here...
         # The goal is to make sure that after deletion of the
         # The goal is to make sure that after deletion of the
         # given rrset, at least 1 NS record is left (at the apex).
         # given rrset, at least 1 NS record is left (at the apex).
@@ -629,12 +627,11 @@ class UpdateSession:
            Special case: if the name is the zone's apex, SOA and
            Special case: if the name is the zone's apex, SOA and
            NS records are kept.
            NS records are kept.
         '''
         '''
-        _, finder = self.datasrc_client.find_zone(rrset.get_name())
+        result, rrsets, flags = self.finder.find_all(rrset.get_name(),
-        result, rrsets, flags = finder.find_all(rrset.get_name(),
+                                                     ZoneFinder.NO_WILDCARD |
-                                                finder.NO_WILDCARD |
+                                                     ZoneFinder.FIND_GLUE_OK)
-                                                finder.FIND_GLUE_OK)
+        if result == ZoneFinder.SUCCESS and\
-        if result == finder.SUCCESS and\
+           (flags & ZoneFinder.RESULT_WILDCARD == 0):
-           (flags & finder.RESULT_WILDCARD == 0):
             for to_delete in rrsets:
             for to_delete in rrsets:
                 # if name == self.zname and type is soa or ns, don't delete!
                 # if name == self.zname and type is soa or ns, don't delete!
                 if to_delete.get_name() == self.zname and\
                 if to_delete.get_name() == self.zname and\
@@ -680,10 +677,9 @@ class UpdateSession:
         # serial magic and add the newly created one
         # serial magic and add the newly created one
 
 
         # get it from DS and to increment and stuff
         # get it from DS and to increment and stuff
-        _, finder = self.datasrc_client.find_zone(self.zname)
+        result, old_soa, _ = self.finder.find(self.zname, RRType.SOA(),
-        result, old_soa, _ = finder.find(self.zname, RRType.SOA(),
+                                              ZoneFinder.NO_WILDCARD |
-                                         finder.NO_WILDCARD |
+                                              ZoneFinder.FIND_GLUE_OK)
-                                         finder.FIND_GLUE_OK)
 
 
         if self.__added_soa is not None:
         if self.__added_soa is not None:
             new_soa = self.__added_soa
             new_soa = self.__added_soa