Пример #1
0
 def test_getAttrsError(self):
     # Errors in getAttrs on TransportSFTPFile are translated into
     # SFTPErrors.
     filename = self.getPathSegment()
     deferred = self.openFile(filename, 0, {})
     deferred.addCallback(lambda handle: handle.getAttrs())
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #2
0
 def test_writeChunkOnDirectory(self):
     # Errors in writeChunk are translated to SFTPErrors.
     directory = self.getPathSegment()
     os.mkdir(directory)
     deferred = self.openFile(directory, filetransfer.FXF_WRITE, {})
     deferred.addCallback(lambda handle: handle.writeChunk(0, 'bar'))
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #3
0
 def test_makeDirectoryError(self):
     # Errors in makeDirectory are translated into SFTPErrors.
     nonexistent = self.getPathSegment()
     nonexistent_child = '%s/%s' % (nonexistent, self.getPathSegment())
     deferred = self.sftp_server.makeDirectory(
         nonexistent_child, {'permissions': 0o777})
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #4
0
 def test_getWorkerArguments_arbitrary_fault_raises(self):
     # When getImportDataForJobID signals an arbitrary fault, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=xmlrpc.Fault(1, ''))
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              xmlrpc.Fault)
Пример #5
0
 def test_getWorkerArguments_endpoint_failure_raises(self):
     # When getImportDataForJobID raises an arbitrary exception, it is not
     # handled in any special way by getWorkerArguments.
     worker_monitor = self.makeWorkerMonitorWithoutJob(
         exception=ZeroDivisionError())
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              ZeroDivisionError)
Пример #6
0
 def test_getWorkerArguments_job_not_found_raises_exit_quietly(self):
     # When getImportDataForJobID signals a fault indicating that
     # getWorkerArguments didn't find the supplied job, getWorkerArguments
     # translates this to an 'ExitQuietly' exception.
     worker_monitor = self.makeWorkerMonitorWithoutJob()
     return assert_fails_with(worker_monitor.getWorkerArguments(),
                              ExitQuietly)
Пример #7
0
    def assertFailure(self, deferred, exception):
        """
        ``twisted.trial.unittest.TestCase.assertFailure``-alike.

        This is not completely compatible.  ``assert_fails_with`` should be
        preferred for new code.
        """
        return assert_fails_with(deferred, exception)
Пример #8
0
 def test_prematureFailureWithoutStderr(self):
     # If the worker dies without reporting failure and doesn't have any
     # output on standard error, then we report failure using the reason we
     # have for the worker's death.
     self.protocol.do_startMirroring()
     self.simulateProcessExit(clean=False)
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
Пример #9
0
 def test_run_process_with_timeout_timeout(self):
     # On process timeout, the errback is fired with `TimeoutError`
     # failure.
     clock = task.Clock()
     d = run_process_with_timeout(
         ('sleep', '2'), timeout=1, clock=clock)
     clock.advance(2)
     return assert_fails_with(d, error.TimeoutError)
Пример #10
0
 def test_resumeSlaveHost_command_failed(self):
     reset_fail_config = """
         [builddmaster]
         vm_resume_command: /bin/false"""
     config.push('reset fail', reset_fail_config)
     self.addCleanup(config.pop, 'reset fail')
     d = self.resumeSlaveHost(MockBuilder(virtualized=True, vm_host="pop"))
     return assert_fails_with(d, CannotResumeHost)
Пример #11
0
 def test_pendingNotificationFails(self):
     # If the process exits cleanly while a notification is pending and the
     # notification subsequently fails, the notification's failure is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda: deferred)
     self.simulateProcessExit()
     deferred.errback(makeFailure(RuntimeError))
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Пример #12
0
 def test_unexpectedError(self):
     # unexpectedError() sends SIGINT to the child process but the
     # termination deferred is fired with originally passed-in failure.
     self.protocol.unexpectedError(
         makeFailure(RuntimeError, 'error message'))
     self.assertEqual(
         [('signalProcess', 'INT')],
         self.protocol.transport.calls)
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Пример #13
0
    def assertSFTPError(self, sftp_code, function, *args, **kwargs):
        """Assert that calling functions fails with `sftp_code`."""
        deferred = defer.maybeDeferred(function, *args, **kwargs)
        deferred = assert_fails_with(deferred, filetransfer.SFTPError)

        def check_sftp_code(exception):
            self.assertEqual(sftp_code, exception.code)
            return exception

        return deferred.addCallback(check_sftp_code)
Пример #14
0
 def test_errorBeforeStatusReport(self):
     # If the subprocess exits before reporting success or failure, the
     # puller master should record failure.
     self.protocol.do_startMirroring()
     self.protocol.errReceived('traceback')
     self.simulateProcessExit(clean=False)
     self.assertEqual(
         self.listener.calls,
         ['startMirroring', ('mirrorFailed', 'traceback', None)])
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
Пример #15
0
    def assertFiresFailure(self, exception, function, *args, **kwargs):
        """Assert that calling `function` will cause `exception` to be fired.

        In the synchronous tests, this means that `function` raises
        `exception`. In the asynchronous tests, `function` returns a Deferred
        that fires `exception` as a Failure.

        :return: A `Deferred`. You must return this from your test.
        """
        return assert_fails_with(
            self._ensureDeferred(function, *args, **kwargs), exception)
Пример #16
0
 def test_runNotificationFailure(self):
     # If a notification function fails, the child process is killed and
     # the manner of failure reported.
     def fail():
         raise RuntimeError
     self.protocol.runNotification(fail)
     self.assertEqual(
         [('signalProcess', 'INT')],
         self.protocol.transport.calls)
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Пример #17
0
    def test_mirrorFailedDoesNotResetTimeout(self):
        """Receiving 'mirrorFailed' doesn't reset the timeout.

        mirrorFailed doesn't reset the timeout for the same reasons as
        mirrorSucceeded.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_mirrorFailed('error message', 'OOPS')
        self.clock.advance(2)
        return assert_fails_with(
            self.termination_deferred, error.TimeoutError)
Пример #18
0
    def test_createBranch_error_translation(self):
        # createBranch raises PermissionDenied if we try to create a branch
        # for, say, a product that doesn't exist.
        branch_url = '/~%s/no-such-product/new-branch' % (self.requester.name)
        deferred = self.server.createBranch(branch_url)
        deferred = assert_fails_with(deferred, errors.PermissionDenied)

        def check_exception(exception):
            self.assertEqual(branch_url, exception.path)
            self.assertEqual(": Project 'no-such-product' does not exist.",
                             exception.extra)

        return deferred.addCallback(check_exception)
Пример #19
0
 def test_unexpectedErrorAndNotificationFailure(self):
     # If unexpectedError is called while a notification is pending and the
     # notification subsequently fails, the first failure "wins" and is
     # passed on to the termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda: deferred)
     self.protocol.unexpectedError(makeFailure(TypeError))
     runtime_error_failure = makeFailure(RuntimeError)
     deferred.errback(runtime_error_failure)
     self.assertEqual(
         flush_logged_errors(RuntimeError), [runtime_error_failure])
     return assert_fails_with(
         self.termination_deferred, TypeError)
Пример #20
0
    def test_branchChangedDoesNotResetTimeout(self):
        """Receiving 'branchChanged' doesn't reset the timeout.

        It's possible that in pathological cases, the worker process might
        hang around even after it has said that it's finished. When that
        happens, we want to kill it quickly so that we can continue mirroring
        other branches.
        """
        self.protocol.do_startMirroring()
        self.clock.advance(config.supermirror.worker_timeout - 1)
        self.protocol.do_branchChanged('', '', '', '', '', '')
        self.clock.advance(2)
        return assert_fails_with(
            self.termination_deferred, error.TimeoutError)
Пример #21
0
 def test_uncleanExitAndPendingNotificationFails(self):
     # If the process exits with a non-zero exit code while a
     # notification is pending and the notification subsequently
     # fails, the ProcessTerminated is still passed on to the
     # termination deferred.
     deferred = defer.Deferred()
     self.protocol.runNotification(lambda: deferred)
     self.simulateProcessExit(clean=False)
     runtime_error_failure = makeFailure(RuntimeError)
     deferred.errback(runtime_error_failure)
     self.assertEqual(
         flush_logged_errors(RuntimeError), [runtime_error_failure])
     return assert_fails_with(
         self.termination_deferred, error.ProcessTerminated)
Пример #22
0
    def test_failure_after_too_many_timeouts(self):
        host = 'foo.bar'
        requests = MIN_REQUESTS_TO_CONSIDER_RATIO
        timeouts = (
            (MIN_REQUESTS_TO_CONSIDER_RATIO / MIN_REQUEST_TIMEOUT_RATIO) + 2)
        distributionmirror_prober.host_requests = {host: requests}
        distributionmirror_prober.host_timeouts = {host: timeouts}
        # Ensure the number of requests and timeouts we're using should
        # cause a given host to be skipped.
        self.assertTrue(should_skip_host(host))

        d = self._createProberAndProbe(u'http://%s:%s/timeout' %
                                       (host, self.port))
        return assert_fails_with(d, ConnectionSkipped)
Пример #23
0
 def test_failingNotificationCancelsPendingNotifications(self):
     # A failed notification prevents any further notifications from being
     # run.  Specifically, if a notification returns a deferred which
     # subsequently errbacks, any notifications which have been requested
     # in the mean time are not run.
     deferred = defer.Deferred()
     calls = []
     self.protocol.runNotification(lambda: deferred)
     self.protocol.runNotification(calls.append, 'called')
     self.assertEqual(calls, [])
     deferred.errback(makeFailure(RuntimeError))
     self.assertEqual(calls, [])
     return assert_fails_with(
         self.termination_deferred, RuntimeError)
Пример #24
0
    def test_terminatesWithError(self):
        """When the child process terminates with an unexpected error, raise
        an error that includes the contents of stderr and the exit condition.
        """
        def check_failure(failure):
            self.assertEqual('error message', failure.error)
            return failure

        self.termination_deferred.addErrback(check_failure)

        self.protocol.errReceived('error message')
        self.simulateProcessExit(clean=False)

        return assert_fails_with(
            self.termination_deferred, error.ProcessTerminated)
Пример #25
0
    def test_connection_timeout(self):
        # The default timeout of 30 seconds should not cause a timeout,
        # only the config value should.
        self.pushConfig('builddmaster', socket_timeout=180)

        slave = self.slave_helper.getClientSlave(reactor=self.clock)
        d = slave.echo()
        # Advance past the 30 second timeout.  The real reactor will
        # never call connectTCP() since we're not spinning it up.  This
        # avoids "connection refused" errors and simulates an
        # environment where the endpoint doesn't respond.
        self.clock.advance(31)
        self.assertFalse(d.called)

        self.clock.advance(config.builddmaster.socket_timeout + 1)
        self.assertTrue(d.called)
        return assert_fails_with(d, defer.CancelledError)
Пример #26
0
    def test_errorBeforeStatusReportAndFailingMirrorFailed(self):
        # If the subprocess exits before reporting success or failure, *and*
        # the attempt to record failure fails, there's not much we can do but
        # we should still not hang.  In keeping with the general policy, we
        # fire the termination deferred with the first thing to go wrong --
        # the process termination in this case -- and log.err() the failed
        # attempt to call mirrorFailed().

        runtime_error_failure = makeFailure(RuntimeError)

        class FailingMirrorFailedStubPullerListener(self.StubPullerListener):
            def mirrorFailed(self, message, oops):
                return runtime_error_failure

        self.protocol.listener = FailingMirrorFailedStubPullerListener()
        self.listener = self.protocol.listener
        self.protocol.errReceived('traceback')
        self.simulateProcessExit(clean=False)
        self.assertEqual(
            flush_logged_errors(RuntimeError), [runtime_error_failure])
        return assert_fails_with(
            self.termination_deferred, error.ProcessTerminated)
Пример #27
0
 def test_removeDirectoryError(self):
     # Errors in removeDirectory are translated into SFTPErrors.
     directory = self.getPathSegment()
     deferred = self.sftp_server.removeDirectory(directory)
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #28
0
 def test_renameFileError(self):
     # Errors in renameFile are translated into SFTPErrors.
     orig_filename = self.getPathSegment()
     new_filename = self.getPathSegment()
     deferred = self.sftp_server.renameFile(orig_filename, new_filename)
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #29
0
 def test_removeFile_directory(self):
     # Errors in removeFile are translated into SFTPErrors.
     filename = self.getPathSegment()
     self.build_tree_contents([(filename + '/',)])
     deferred = self.sftp_server.removeFile(filename)
     return assert_fails_with(deferred, filetransfer.SFTPError)
Пример #30
0
 def test_openDirectoryError(self):
     # Errors in openDirectory are translated into SFTPErrors.
     nonexistent = self.getPathSegment()
     deferred = self.sftp_server.openDirectory(nonexistent)
     return assert_fails_with(deferred, filetransfer.SFTPError)