Browse Source

[1512] let UpdateSession.handle() return zone name and class, too.

the caller (b10-ddns) will use that to notify other processes of updates.
JINMEI Tatuya 13 years ago
parent
commit
d4e2862582
2 changed files with 31 additions and 14 deletions
  1. 18 7
      src/lib/python/isc/ddns/session.py
  2. 13 7
      src/lib/python/isc/ddns/tests/session_tests.py

+ 18 - 7
src/lib/python/isc/ddns/session.py

@@ -17,9 +17,9 @@ import isc.dns
 import isc.ddns.zone_config
 
 # Result codes for UpdateSession.handle()
-UPDATE_SUCCESS = 0     # update request granted and succeeded
-UPDATE_ERROR = 1       # some error happened with a corresponding response
-UPDATE_DROP = 2        # critical error happened, no response should be sent
+UPDATE_SUCCESS = 0
+UPDATE_ERROR = 1
+UPDATE_DROP = 2
 
 # Convenient aliases of update-specific section names
 SECTION_ZONE = isc.dns.Message.SECTION_QUESTION
@@ -54,8 +54,19 @@ class UpdateSession:
     def handle(self):
         '''Handle the update request according to RFC2136.
 
-        Return: the result code of the session, indicating the next action
-                to be taken.
+        This method returns a tuple of the following three elements that
+        indicate the result of the request.
+        - Result code of the request processing, which are:
+          UPDATE_SUCCESS Update request granted and succeeded.
+          UPDATE_ERROR Some error happened to be reported in the response.
+          UPDATE_DROP Error happened and no response should be sent.
+          Except the case of UPDATE_DROP, the UpdateSession object will have
+          created a response that is to be returned to the request client,
+          which can be retrieved by get_message().
+        - The name of the updated zone (isc.dns.Name object) in case of
+          UPDATE_SUCCESS; otherwise None.
+        - The RR class of the updated zone (isc.dns.RRClass object) in case
+          of UPDATE_SUCCESS; otherwise None.
 
         '''
         try:
@@ -65,10 +76,10 @@ class UpdateSession:
             # self.__check_update_acl()
             # self.__do_update()
             # self.__make_response(Rcode.NOERROR())
-            return UPDATE_SUCCESS
+            return UPDATE_SUCCESS, zname, zclass
         except ZoneError as e:
             self.__make_response(e.rcode)
-        return UPDATE_ERROR
+        return UPDATE_ERROR, None, None
 
     def __get_update_zone(self):
         '''Parse the zone section and find the zone to be updated.

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

@@ -68,14 +68,17 @@ class SessionTest(unittest.TestCase):
         # Zone section is empty
         msg_data, msg = create_update_msg(zones=[])
         session = UpdateSession(msg, msg_data, None, None)
-        self.assertEqual(UPDATE_ERROR, session.handle())
+        result, zname, zclass = session.handle()
+        self.assertEqual(UPDATE_ERROR, result)
+        self.assertEqual(None, zname)
+        self.assertEqual(None, zclass)
         self.check_response(session.get_message(), Rcode.FORMERR())
 
         # Zone section contains multiple records
         msg_data, msg = create_update_msg(zones=[TEST_ZONE_RECORD,
                                                  TEST_ZONE_RECORD])
         session = UpdateSession(msg, msg_data, None, None)
-        self.assertEqual(UPDATE_ERROR, session.handle())
+        self.assertEqual(UPDATE_ERROR, session.handle()[0])
         self.check_response(session.get_message(), Rcode.FORMERR())
 
         # Zone section's type is not SOA
@@ -83,7 +86,7 @@ class SessionTest(unittest.TestCase):
                                                           TEST_RRCLASS,
                                                           RRType.A())])
         session = UpdateSession(msg, msg_data, None, None)
-        self.assertEqual(UPDATE_ERROR, session.handle())
+        self.assertEqual(UPDATE_ERROR, session.handle()[0])
         self.check_response(session.get_message(), Rcode.FORMERR())
 
     def test_update_secondary(self):
@@ -96,13 +99,16 @@ class SessionTest(unittest.TestCase):
                                                           RRType.SOA())])
         session = UpdateSession(msg, msg_data, None,
                                 ZoneConfig([(sec_zone, TEST_RRCLASS)]))
-        self.assertEqual(UPDATE_ERROR, session.handle())
+        self.assertEqual(UPDATE_ERROR, session.handle()[0])
         self.check_response(session.get_message(), Rcode.REFUSED())
 
     def test_handle(self):
-        self.assertEqual(UPDATE_SUCCESS, self.__session.handle())
-        self.assertNotEqual(UPDATE_ERROR, self.__session.handle())
-        self.assertNotEqual(UPDATE_DROP, self.__session.handle())
+        result, zname, zclass = self.__session.handle()
+        self.assertEqual(UPDATE_SUCCESS, result)
+        self.assertNotEqual(UPDATE_ERROR, result)
+        self.assertNotEqual(UPDATE_DROP, result)
+        self.assertEqual(TEST_ZONE_NAME, zname)
+        self.assertEqual(TEST_RRCLASS, zclass)
 
 if __name__ == "__main__":
     isc.log.init("bind10")