twisted.spread.pb.PBConnectionLost

Here are the examples of the python api twisted.spread.pb.PBConnectionLost taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: feat Source File: broker.py
    @manhole.expose()
    def shutdown_slaves(self, gentle=False):

        def error_handler(f):
            if f.check(ConnectionDone, pb.PBConnectionLost):
                self.log('Swallowing %r - this is expected result.',
                         f.value.__class__.__name__)
            else:
                f.raiseException()

        if self.is_master():

            def kill_slave(slave):
                self.log('slave is %r', slave)
                method_to_call = 'shutdown' if gentle else 'kill'
                d = slave.callRemote(method_to_call, stop_process=True)
                d.addErrback(error_handler)
                return d

            return defer.DeferredList([kill_slave(x)
                                       for x in self.iter_slaves()])
        elif self.is_slave():
            d = self._master.callRemote('shutdown_slaves')
            d.addErrback(error_handler)
            return d

Example 2

Project: feat Source File: test_agencies_net_agency.py
    @common.attr(timeout=40)
    @defer.inlineCallbacks
    def testBackupAgency(self):
        pid_path = os.path.join(os.path.curdir, 'feat.pid')
        hostname = self.agency.get_hostname()

        yield self.spawn_agency()
        yield self.wait_for_pid(pid_path)

        def host_descriptor():

            def check(host_desc):
                return host_desc.instance_id == 1

            d = self.db.get_docuement(hostname)
            d.addCallbacks(check, failure.Failure.trap,
                           errbackArgs=(NotFoundError, ))
            return d

        yield self.wait_for(host_descriptor, 5)

        yield common.delay(None, 5)
        yield self.agency.initiate()
        yield self.wait_for_slave()

        pid = run.get_pid(os.path.curdir)

        run.term_pid(pid)
        # now cleanup the stale descriptors the way the monitor agent would

        yield self.wait_for_master()
        yield host_restart.do_cleanup(self.db, hostname)

        def has_host():
            m = self.agency._get_host_medium()
            return m is not None and m.is_ready()

        yield self.wait_for(has_host, 15)

        host_desc = yield self.db.get_docuement(hostname)
        # for host agent the instance id should not increase
        # (this is only the case for agents run by host agent)
        self.assertEqual(1, host_desc.instance_id)

        yield self.wait_for_backup()
        slave = self.agency._broker.slaves.values()[0]

        self.info('killing slave %s', slave.slave_id)
        d = slave.callRemote('shutdown', stop_process=True)
        self.assertFailure(d, pb.PBConnectionLost)
        yield d

        yield common.delay(None, 0.5)
        yield self.wait_for_backup()

        slave2 = self.agency._broker.slaves.values()[0]
        self.assertNotEqual(slave.slave_id, slave2.slave_id)