Beispiel #1
0
 def test_connection_refused(self):
     """Check that connection refused errors are handeled correctly.
     """
     from twisted.internet import reactor
     host, port = 'localhost', 1  # Use a port that is not open for connection
     self.inductor = SSHProcessInductor(reactor, host, port)
     deferred = self.inductor.getConnection()
     return self.assertFailure(deferred, ConnectionRefusedError)
Beispiel #2
0
class SSHInductorEndpointTest(TestCase, InductorEndpointTestMixin):
    def setUp(self):
        from twisted.internet import reactor
        host, port = 'localhost', 22
        self.inductor = SSHProcessInductor(reactor, host, port)
        self.inductor.setCredentials(UID, PASSWORD)

    def tearDown(self):
        inductor = self.inductor
        self.inductor = None
        inductor.disconnectAll()
Beispiel #3
0
class SSHInductorEndpointTest(TestCase, InductorEndpointTestMixin):
    def setUp(self):
        from twisted.internet import reactor
        host, port = 'localhost', 22
        self.inductor = SSHProcessInductor(reactor, host, port)
        self.inductor.setCredentials(UID, PASSWORD)

    def tearDown(self):
        inductor = self.inductor
        self.inductor = None
        inductor.disconnectAll()
Beispiel #4
0
 def test_connection_refused(self):
     """Check that connection refused errors are handeled correctly.
     """
     from twisted.internet import reactor
     host, port = 'localhost', 1 # Use a port that is not open for connection
     self.inductor = SSHProcessInductor(reactor, host, port)
     deferred = self.inductor.getConnection()
     return self.assertFailure(deferred, ConnectionRefusedError)
Beispiel #5
0
class SSHProcessInductorTest(TestCase, InductorTestMixin):
    """This test need to authenticate the connect to an ssh server.
    """
    def setUp(self):
        from twisted.internet import reactor
        host, port = 'localhost', 22
        self.inductor = SSHProcessInductor(reactor, host, port)
        self.inductor.setCredentials(UID, PASSWORD)

    def test_authentication_failure(self):
        """Check that we get auth failure with wring credentials.
        """
        self.inductor.setCredentials(WRONG_USER, WRONG_PASSWORD)
        protocol = ProcessProtocol()
        processDeferred = self.inductor.execute(protocol,
                                                SUCCEEDING_COMMAND,
                                                uid=WRONG_USER)
        return self.assertFailure(processDeferred, TooManyAuthFailures)

    def test_connection_refused(self):
        """Check that connection refused errors are handeled correctly.
        """
        from twisted.internet import reactor
        host, port = 'localhost', 1  # Use a port that is not open for connection
        self.inductor = SSHProcessInductor(reactor, host, port)
        deferred = self.inductor.getConnection()
        return self.assertFailure(deferred, ConnectionRefusedError)

    def tearDown(self):
        inductor = self.inductor
        self.inductor = None
        inductor.disconnectAll()
Beispiel #6
0
class SSHProcessInductorTest(TestCase, InductorTestMixin):
    """This test need to authenticate the connect to an ssh server.
    """

    def setUp(self):
        from twisted.internet import reactor
        host, port = 'localhost', 22
        self.inductor = SSHProcessInductor(reactor, host, port)
        self.inductor.setCredentials(UID, PASSWORD)

    def test_authentication_failure(self):
        """Check that we get auth failure with wring credentials.
        """
        self.inductor.setCredentials(WRONG_USER, WRONG_PASSWORD)
        protocol = ProcessProtocol()
        processDeferred = self.inductor.execute(protocol, SUCCEEDING_COMMAND,
                                                uid=WRONG_USER)
        return self.assertFailure(processDeferred, TooManyAuthFailures)

    def test_connection_refused(self):
        """Check that connection refused errors are handeled correctly.
        """
        from twisted.internet import reactor
        host, port = 'localhost', 1 # Use a port that is not open for connection
        self.inductor = SSHProcessInductor(reactor, host, port)
        deferred = self.inductor.getConnection()
        return self.assertFailure(deferred, ConnectionRefusedError)

    def tearDown(self):
        inductor = self.inductor
        self.inductor = None
        inductor.disconnectAll()
Beispiel #7
0
 def setUp(self):
     from twisted.internet import reactor
     host, port = 'localhost', 22
     self.inductor = SSHProcessInductor(reactor, host, port)
     self.inductor.setCredentials(UID, PASSWORD)
Beispiel #8
0
 def setUp(self):
     from twisted.internet import reactor
     host, port = 'localhost', 22
     self.inductor = SSHProcessInductor(reactor, host, port)
     self.inductor.setCredentials(UID, PASSWORD)
Beispiel #9
0
        # Set up a deferred that will be triggered when the process ends
        self.deferred = defer.Deferred()

    def processEnded(self, reason):
        # Trigger the deferred with the exit code of the process
        exit_code = reason.value.exitCode
        self.deferred.callback(exit_code)


# Set up a local process inductor and run the process through our relay protocol
local_inductor = LocalProcessInductor(reactor)
local_protocol = RelayProtocol('Local process: ')
remote_process = local_inductor.execute(local_protocol, command)

# Set up a remote process inductor and run the same command
remote_inductor = SSHProcessInductor(reactor, remote_host, remote_port)
remote_inductor.setCredentials(remote_user, remote_password)
remote_protocol = RelayProtocol('Remote process: ')
remote_process = remote_inductor.execute(remote_protocol, command)

# Gather the results from the local and remote process
results = defer.DeferredList([local_protocol.deferred,
                              remote_process, remote_protocol.deferred],
                             fireOnOneErrback=True)
@results.addCallback
def get_exit_codes(deferredListResults):
    global exit_codes
    exit_codes = []
    for _, exit_code in deferredListResults:
        exit_codes.append(exit_code)