Browse Source

[2018] separate diff creation from get_update_zone

and made get_update_zone protected instead of private
Jelte Jansen 13 years ago
parent
commit
47965690b1
2 changed files with 28 additions and 14 deletions
  1. 21 10
      src/lib/python/isc/ddns/session.py
  2. 7 4
      src/lib/python/isc/ddns/tests/session_tests.py

+ 21 - 10
src/lib/python/isc/ddns/session.py

@@ -189,13 +189,13 @@ class UpdateSession:
 
 
         '''
         '''
         try:
         try:
-            self.__get_update_zone()
+            self._get_update_zone()
-            # conceptual code that would follow
+            self.__check_update_acl(self.__zname, self.__zclass)
+            self._create_diff()
             prereq_result = self.__check_prerequisites()
             prereq_result = self.__check_prerequisites()
             if prereq_result != Rcode.NOERROR():
             if prereq_result != Rcode.NOERROR():
                 self.__make_response(prereq_result)
                 self.__make_response(prereq_result)
                 return UPDATE_ERROR, self.__zname, self.__zclass
                 return UPDATE_ERROR, self.__zname, self.__zclass
-            self.__check_update_acl(self.__zname, self.__zclass)
             update_result = self.__do_update()
             update_result = self.__do_update()
             if update_result != Rcode.NOERROR():
             if update_result != Rcode.NOERROR():
                 self.__make_response(update_result)
                 self.__make_response(update_result)
@@ -215,7 +215,7 @@ class UpdateSession:
             self.__message = None
             self.__message = None
             return UPDATE_DROP, None, None
             return UPDATE_DROP, None, None
 
 
-    def __get_update_zone(self):
+    def _get_update_zone(self):
         '''Parse the zone section and find the zone to be updated.
         '''Parse the zone section and find the zone to be updated.
 
 
         If the zone section is valid and the specified zone is found in
         If the zone section is valid and the specified zone is found in
@@ -224,7 +224,6 @@ class UpdateSession:
                           zone
                           zone
         __zname: The zone name as a Name object
         __zname: The zone name as a Name object
         __zclass: The zone class as an RRClass object
         __zclass: The zone class as an RRClass object
-        __finder: A ZoneFinder for this zone
         If this method raises an exception, these members are not set
         If this method raises an exception, these members are not set
         '''
         '''
         # Validation: the zone section must contain exactly one question,
         # Validation: the zone section must contain exactly one question,
@@ -243,13 +242,9 @@ class UpdateSession:
         zclass = zrecord.get_class()
         zclass = zrecord.get_class()
         zone_type, datasrc_client = self.__zone_config.find_zone(zname, zclass)
         zone_type, datasrc_client = self.__zone_config.find_zone(zname, zclass)
         if zone_type == isc.ddns.zone_config.ZONE_PRIMARY:
         if zone_type == isc.ddns.zone_config.ZONE_PRIMARY:
-            # create an ixfr-out-friendly diff structure to work on
+            self.__datasrc_client = datasrc_client
-            self.__diff = isc.xfrin.diff.Diff(datasrc_client, zname,
-                                              journaling=True,
-                                              single_update_mode=True)
             self.__zname = zname
             self.__zname = zname
             self.__zclass = zclass
             self.__zclass = zclass
-            self.__datasrc_client = datasrc_client
             return
             return
         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
@@ -264,6 +259,22 @@ class UpdateSession:
                      ZoneFormatter(zname, zclass))
                      ZoneFormatter(zname, zclass))
         raise UpdateError('notauth', zname, zclass, Rcode.NOTAUTH(), True)
         raise UpdateError('notauth', zname, zclass, Rcode.NOTAUTH(), True)
 
 
+    def _create_diff(self):
+        '''
+        Initializes the internal data structure used for searching current
+        data and for adding and deleting data. This is supposed to be called
+        after ACL checks but before prerequisite checks (since the latter
+        needs the find calls provided by the Diff class).
+        Adds the private member:
+        __diff: A buffer of changes made against the zone by this update
+                This object also contains find() calls, see documentation
+                of the Diff class.
+        '''
+        self.__diff = isc.xfrin.diff.Diff(self.__datasrc_client,
+                                          self.__zname,
+                                          journaling=True,
+                                          single_update_mode=True)
+
     def __check_update_acl(self, zname, zclass):
     def __check_update_acl(self, zname, zclass):
         '''Apply update ACL for the zone to be updated.'''
         '''Apply update ACL for the zone to be updated.'''
         acl = self.__zone_config.get_update_acl(zname, zclass)
         acl = self.__zone_config.get_update_acl(zname, zclass)

+ 7 - 4
src/lib/python/isc/ddns/tests/session_tests.py

@@ -112,10 +112,11 @@ class SessionTestBase(unittest.TestCase):
                                       ZoneConfig([], TEST_RRCLASS,
                                       ZoneConfig([], TEST_RRCLASS,
                                                  self._datasrc_client,
                                                  self._datasrc_client,
                                                  self._acl_map))
                                                  self._acl_map))
-        self._session._UpdateSession__get_update_zone()
+        self._session._get_update_zone()
+        self._session._create_diff()
 
 
     def tearDown(self):
     def tearDown(self):
-        # With the Updater created in __get_update_zone, and tests
+        # With the Updater created in _get_update_zone, and tests
         # doing all kinds of crazy stuff, one might get database locked
         # doing all kinds of crazy stuff, one might get database locked
         # errors if it doesn't clean up explicitely after each test
         # errors if it doesn't clean up explicitely after each test
         self._session = None
         self._session = None
@@ -448,7 +449,8 @@ class SessionTest(SessionTestBase):
         zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
         zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
                              self._acl_map)
                              self._acl_map)
         session = UpdateSession(msg, TEST_CLIENT4, zconfig)
         session = UpdateSession(msg, TEST_CLIENT4, zconfig)
-        session._UpdateSession__get_update_zone()
+        session._get_update_zone()
+        session._create_diff()
         # compare the to_text output of the rcodes (nicer error messages)
         # compare the to_text output of the rcodes (nicer error messages)
         # This call itself should also be done by handle(),
         # This call itself should also be done by handle(),
         # but just for better failures, it is first called on its own
         # but just for better failures, it is first called on its own
@@ -473,7 +475,8 @@ class SessionTest(SessionTestBase):
         zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
         zconfig = ZoneConfig([], TEST_RRCLASS, self._datasrc_client,
                              self._acl_map)
                              self._acl_map)
         session = UpdateSession(msg, TEST_CLIENT4, zconfig)
         session = UpdateSession(msg, TEST_CLIENT4, zconfig)
-        session._UpdateSession__get_update_zone()
+        session._get_update_zone()
+        session._create_diff()
         # compare the to_text output of the rcodes (nicer error messages)
         # compare the to_text output of the rcodes (nicer error messages)
         # This call itself should also be done by handle(),
         # This call itself should also be done by handle(),
         # but just for better failures, it is first called on its own
         # but just for better failures, it is first called on its own