Fix delegation on Precise.
authorGeoffrey Thomas <geofft@mit.edu>
Mon, 16 Jun 2014 19:01:11 +0000 (12:01 -0700)
committerGeoffrey Thomas <geofft@mit.edu>
Mon, 16 Jun 2014 19:01:11 +0000 (12:01 -0700)
* Handle Twisted deferred failures properly via an errback.
* Comment out code to switch answer and authority sections.

debian/changelog
invirt-dns

index 1e721c4..a65cb3a 100644 (file)
@@ -1,3 +1,10 @@
+invirt-dns (0.0.16) UNRELEASED; urgency=low
+
+  * Handle Twisted deferred failures properly via an errback.
+  * Comment out code to switch answer and authority sections.
+
+ -- Geoffrey Thomas <geofft@mit.edu>  Mon, 16 Jun 2014 11:59:46 -0700
+
 invirt-dns (0.0.15) precise; urgency=low
 
   * Updating version for precise migration.
index c320e51..c0950de 100755 (executable)
@@ -195,18 +195,24 @@ class DelegatingQuotingBindAuthority(authority.BindAuthority):
         return filter(None, L)
 
     def _lookup(self, name, cls, type, timeout = None):
-        maybeDelegate = False
         deferredResult = authority.BindAuthority._lookup(self, name, cls,
                                                          type, timeout)
         # If we didn't find an exact match for the name we were seeking,
         # check if it's within a subdomain we're supposed to delegate to
         # some other DNS server.
-        while (isinstance(deferredResult.result, failure.Failure)
-               and '.' in name):
-            maybeDelegate = True
+        deferredResult.addErrback(self._delegation_errback, name, cls, timeout)
+        return deferredResult
+
+    def _delegation_errback(self, deferredResult, name, cls, timeout):
+        if '.' in name:
             name = name[name.find('.') + 1 :]
             deferredResult = authority.BindAuthority._lookup(self, name, cls,
                                                              dns.NS, timeout)
+            #deferredResult.addCallback(self._delegation_callback)
+            deferredResult.addErrback(self._delegation_errback, name, cls, timeout)
+        return deferredResult
+
+    def _delegation_callback(self, result):
         # If we found somewhere to delegate the query to, our _lookup()
         # for the NS record resulted in it being in the 'results' section.
         # We need to instead return that information in the 'authority'
@@ -214,10 +220,8 @@ class DelegatingQuotingBindAuthority(authority.BindAuthority):
         # (because we didn't find the name we were asked about).  We
         # leave the 'additional' section as we received it because it
         # may contain A records for the DNS server we're delegating to.
-        if maybeDelegate and not isinstance(deferredResult.result,
-                                            failure.Failure):
-            (nsResults, nsAuthority, nsAdditional) = deferredResult.result
-            deferredResult = defer.succeed(([], nsResults, nsAdditional))
+        (nsResults, nsAuthority, nsAdditional) = result
+        deferredResult = defer.succeed(([], nsResults, nsAdditional))
         return deferredResult
 
 if '__main__' == __name__: