def test(self): mgr = SyncManager(DEFAULT_NAME) leases = self.mycfg["Leases"] mgr.initStorage(leases, self.mycfg["NumberOfHosts"], MAXIMUM_NUMBER_OF_HOSTS) for lease, drives in leases: for drive, offset in drives: with open(drive, "rb") as f: f.seek(offset) leader, blocks = readState(f, MAXIMUM_NUMBER_OF_HOSTS) self.assertEquals(nullTerminated(leader.resourceID), lease) self.assertEquals(leader.numHosts, self.mycfg["NumberOfHosts"]) self.assertEquals(leader.maxHosts, MAXIMUM_NUMBER_OF_HOSTS) for block in blocks: self.assertEquals(block.bal, 0) self.assertEquals(block.mbal, 0) self.assertEquals(block.inp, 0) self.assertEquals(block.lver, 0)
def formatPaxoState(disk, offset): with open(disk, "rb") as f: f.seek(offset) leader, dblocks = readState(f) res = StringIO() res.write("LEADER\n------\n") for key in leader._fields: val = getattr(leader, key) if key == "timestamp": val = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(val)) elif isinstance(val, str): val = nullTerminated(val) res.write("%s:\t%s%s\n" % (key, '\t' if len(key) < 7 else '', val)) res.write("\nBLOCKS\n------\n") for field in DBlock._fields: res.write("%s:" % field) for dblock in dblocks: res.write("\t%s" % getattr(dblock, field)) res.write("\n") res.seek(0) return res.read()