~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/stub_sftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2010-09-01 06:45:57 UTC
  • mfrom: (5247.2.41 more-ignored-exceptions)
  • Revision ID: pqm@pqm.ubuntu.com-20100901064557-qsxmjmp195ozbluf
(vila) Catch EPIPE when shutting down test servers. (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
344
344
    def setup(self):
345
345
        self.wrap_for_latency()
346
346
        tcs = self.server.test_case_server
347
 
        ptrans = paramiko.Transport(self.request)
348
 
        self.paramiko_transport = ptrans
349
 
        # Set it to a channel under 'bzr' so that we get debug info
350
 
        ptrans.set_log_channel('bzr.paramiko.transport')
351
 
        ptrans.add_server_key(tcs.get_host_key())
352
 
        ptrans.set_subsystem_handler('sftp', paramiko.SFTPServer,
353
 
                                     StubSFTPServer, root=tcs._root,
354
 
                                     home=tcs._server_homedir)
 
347
        ssh_server = paramiko.Transport(self.request)
 
348
        ssh_server.add_server_key(tcs.get_host_key())
 
349
        ssh_server.set_subsystem_handler('sftp', paramiko.SFTPServer,
 
350
                                         StubSFTPServer, root=tcs._root,
 
351
                                         home=tcs._server_homedir)
355
352
        server = tcs._server_interface(tcs)
356
 
        # This blocks until the key exchange has been done
357
 
        ptrans.start_server(None, server)
358
 
 
359
 
    def finish(self):
360
 
        # Wait for the conversation to finish, when the paramiko.Transport
361
 
        # thread finishes
362
 
        # TODO: Consider timing out after XX seconds rather than hanging.
363
 
        #       Also we could check paramiko_transport.active and possibly
364
 
        #       paramiko_transport.getException().
365
 
        self.paramiko_transport.join()
 
353
        ssh_server.start_server(None, server)
 
354
        # FIXME: Long story short:
 
355
        # bt.test_transport.TestSSHConnections.test_bzr_connect_to_bzr_ssh
 
356
        # fails if we wait less than 0.2 seconds... paramiko uses a lot of
 
357
        # timeouts internally which probably mask a synchronisation
 
358
        # problem. Note that this is the only test that requires this hack and
 
359
        # the test may need to be fixed instead, but it's late and the test is
 
360
        # horrible as mentioned in its comments :) -- vila 20100623
 
361
        import time
 
362
        time.sleep(0.2)
366
363
 
367
364
    def wrap_for_latency(self):
368
365
        tcs = self.server.test_case_server
383
380
            def get_transport(self):
384
381
                return self
385
382
            def get_log_channel(self):
386
 
                return 'bzr.paramiko'
 
383
                return 'paramiko'
387
384
            def get_name(self):
388
385
                return '1'
389
386
            def get_hexdump(self):
392
389
                pass
393
390
 
394
391
        tcs = self.server.test_case_server
395
 
        sftp_server = paramiko.SFTPServer(
 
392
        server = paramiko.SFTPServer(
396
393
            FakeChannel(), 'sftp', StubServer(tcs), StubSFTPServer,
397
394
            root=tcs._root, home=tcs._server_homedir)
398
 
        self.sftp_server = sftp_server
399
 
        sys_stderr = sys.stderr # Used in error reporting during shutdown
400
395
        try:
401
 
            sftp_server.start_subsystem(
 
396
            server.start_subsystem(
402
397
                'sftp', None, ssh.SocketAsChannelAdapter(self.request))
403
398
        except socket.error, e:
404
399
            if (len(e.args) > 0) and (e.args[0] == errno.EPIPE):
414
409
            # seems to be the best we can do.
415
410
            # FIXME: All interpreter shutdown errors should have been related
416
411
            # to daemon threads, cleanup needed -- vila 20100623
417
 
            sys_stderr.write('\nEXCEPTION %r: ' % (e.__class__,))
418
 
            sys_stderr.write('%s\n\n' % (e,))
419
 
 
420
 
    def finish(self):
421
 
        self.sftp_server.finish_subsystem()
 
412
            import sys
 
413
            sys.stderr.write('\nEXCEPTION %r: ' % (e.__class__,))
 
414
            sys.stderr.write('%s\n\n' % (e,))
 
415
        server.finish_subsystem()
422
416
 
423
417
 
424
418
class TestingSFTPServer(test_server.TestingThreadingTCPServer):