def all_is_lost_errback(failure): if failure.check(BackendError): # This failure is something that the TFTP server knows how to deal # with, so pass it through. return failure else: # Something broke badly; record it. log.err(failure, "TFTP back-end failed.") # Don't keep people waiting; tell them something broke right now. raise BackendError(failure.getErrorMessage())
def test_generic_backend_error(self): tftp = TFTP(BackendFactory(BackendError("A backend that couldn't")), _clock=self.clock) tftp.transport = self.transport rrq_datagram = RRQDatagram(b'foobar', b'netascii', {}) tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111)) self.clock.advance(1) error_datagram = TFTPDatagramFactory( *split_opcode(self.transport.value())) self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED) self.transport.clear() rrq_datagram = RRQDatagram(b'foobar', b'octet', {}) tftp.datagramReceived(rrq_datagram.to_wire(), ('127.0.0.1', 1111)) self.clock.advance(1) error_datagram = TFTPDatagramFactory( *split_opcode(self.transport.value())) self.assertEqual(error_datagram.errorcode, ERR_NOT_DEFINED)