Esempio n. 1
0
    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_document(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_document(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)
Esempio n. 2
0
    def testCleaningUp(self):
        self.agency1 = yield self.driver.spawn_agency(hostname=u"host1")
        yield self.wait_for_idle(10)
        self.agency2 = yield self.driver.spawn_agency(hostname=u"host2")
        yield self.wait_for_idle(10)
        self.assertEquals(2, self.count_agents("host_agent"))
        self.assertEquals(1, self.count_agents("shard_agent"))
        db = self.driver._database_connection
        host_desc = yield db.get_document("host1_1")

        yield host_restart.do_cleanup(db, "host1_1")
        should_dissapear = [x.recipient.key for x in host_desc.partners]
        should_dissapear += "host1_1"
        for agent_id in should_dissapear:
            doc = yield host_restart.safe_get(db, agent_id)
            self.assertIs(None, doc)
        doc = yield host_restart.safe_get(db, "host2_2")
        self.assertIsNot(None, doc)