Rev 3183: (andrew) Don't traceback on host name errors when connecting to in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Tue Jan 15 07:45:06 GMT 2008


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3183
revision-id:pqm at pqm.ubuntu.com-20080115074456-0v1w54h783oq7n48
parent: pqm at pqm.ubuntu.com-20080115061554-qyfxjo4fxlsjobar
parent: andrew.bennetts at canonical.com-20080115054841-kwestb10z4j7cwj6
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Tue 2008-01-15 07:44:56 +0000
message:
  (andrew) Don't traceback on host name errors when connecting to
  	bzr:// URLs.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
  bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3180.1.3
    revision-id:andrew.bennetts at canonical.com-20080115054841-kwestb10z4j7cwj6
    parent: andrew.bennetts at canonical.com-20080115053632-us99yszek4lhs8sw
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: smart-tcp-unknown-host
    timestamp: Tue 2008-01-15 16:48:41 +1100
    message:
      Add NEWS entry.
    modified:
      NEWS                           NEWS-20050323055033-4e00b5db738777ff
    ------------------------------------------------------------
    revno: 3180.1.2
    revision-id:andrew.bennetts at canonical.com-20080115053632-us99yszek4lhs8sw
    parent: andrew.bennetts at canonical.com-20080115005912-sz20uhvhskju57t0
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: smart-tcp-unknown-host
    timestamp: Tue 2008-01-15 16:36:32 +1100
    message:
      Add a test, and also add InvalidHostnameFeature.
    modified:
      bzrlib/tests/test_smart_transport.py test_ssh_transport.py-20060608202016-c25gvf1ob7ypbus6-2
    ------------------------------------------------------------
    revno: 3180.1.1
    revision-id:andrew.bennetts at canonical.com-20080115005912-sz20uhvhskju57t0
    parent: pqm at pqm.ubuntu.com-20080115003405-jfuumkpctmvl2e4r
    committer: Andrew Bennetts <andrew.bennetts at canonical.com>
    branch nick: smart-tcp-unknown-host
    timestamp: Tue 2008-01-15 11:59:12 +1100
    message:
      Don't traceback on host name errors when connecting to bzr://...
    modified:
      bzrlib/smart/medium.py         medium.py-20061103051856-rgu2huy59fkz902q-1
=== modified file 'NEWS'
--- a/NEWS	2008-01-15 06:15:54 +0000
+++ b/NEWS	2008-01-15 07:44:56 +0000
@@ -138,6 +138,9 @@
      removed use characters not supported in the terminal encoding.
      (Aaron Bentley)
 
+   * Unknown hostnames when connecting to a ``bzr://`` URL no longer cause
+     tracebacks.  (Andrew Bennetts, #182849)
+
    * When dumb http servers return whole files instead of the requested ranges,
      read the remaining bytes by chunks to avoid overflowing network buffers.
      (Vincent Ladeuil, #175886)

=== modified file 'bzrlib/smart/medium.py'
--- a/bzrlib/smart/medium.py	2007-12-19 02:25:26 +0000
+++ b/bzrlib/smart/medium.py	2008-01-15 00:59:12 +0000
@@ -545,10 +545,17 @@
             port = BZR_DEFAULT_PORT
         else:
             port = int(self._port)
-        result = self._socket.connect_ex((self._host, port))
-        if result:
+        try:
+            self._socket.connect((self._host, port))
+        except socket.error, err:
+            # socket errors either have a (string) or (errno, string) as their
+            # args.
+            if type(err.args) is str:
+                err_msg = err.args
+            else:
+                err_msg = err.args[1]
             raise errors.ConnectionError("failed to connect to %s:%d: %s" %
-                    (self._host, port, os.strerror(result)))
+                    (self._host, port, err_msg))
         self._connected = True
 
     def _flush(self):

=== modified file 'bzrlib/tests/test_smart_transport.py'
--- a/bzrlib/tests/test_smart_transport.py	2008-01-14 22:45:15 +0000
+++ b/bzrlib/tests/test_smart_transport.py	2008-01-15 05:36:32 +0000
@@ -80,6 +80,30 @@
         return self.vendor.read_from, self.vendor.write_to
 
 
+class _InvalidHostnameFeature(tests.Feature):
+    """Does 'non_existent.invalid' fail to resolve?
+    
+    RFC 2606 states that .invalid is reserved for invalid domain names, and
+    also underscores are not a valid character in domain names.  Despite this,
+    it's possible a badly misconfigured name server might decide to always
+    return an address for any name, so this feature allows us to distinguish a
+    broken system from a broken test.
+    """
+
+    def _probe(self):
+        try:
+            socket.gethostbyname('non_existent.invalid')
+        except socket.gaierror:
+            # The host name failed to resolve.  Good.
+            return True
+        else:
+            return False
+
+    def feature_name(self):
+        return 'invalid hostname'
+
+InvalidHostnameFeature = _InvalidHostnameFeature()
+
 
 class SmartClientMediumTests(tests.TestCase):
     """Tests for SmartClientMedium.
@@ -443,6 +467,13 @@
         # really did disconnect.
         medium.disconnect()
 
+    def test_tcp_client_host_unknown_connection_error(self):
+        self.requireFeature(InvalidHostnameFeature)
+        client_medium = medium.SmartTCPClientMedium(
+            'non_existent.invalid', 4155)
+        self.assertRaises(
+            errors.ConnectionError, client_medium._ensure_connection)
+
 
 class TestSmartClientStreamMediumRequest(tests.TestCase):
     """Tests the for SmartClientStreamMediumRequest.




More information about the bazaar-commits mailing list