def test_new_suffix(topo_m4, new_suffix): """Check that we can enable replication on a new suffix :id: d44a9ed4-26b0-4189-b0d0-b2b336ddccbd :setup: Four masters replication setup, a new suffix :steps: 1. Enable replication on the new suffix 2. Check if replication works 3. Disable replication on the new suffix :expectedresults: 1. Replication on the new suffix should be enabled 2. Replication should work 3. Replication on the new suffix should be disabled """ m1 = topo_m4.ms["master1"] m2 = topo_m4.ms["master2"] repl = ReplicationManager(NEW_SUFFIX) repl.create_first_master(m1) repl.join_master(m1, m2) repl.test_replication(m1, m2) repl.test_replication(m2, m1) repl.remove_master(m1) repl.remove_master(m2)
def restore_master4(topology_m4): """In our tests will always be removing master 4, so we need a common way to restore it for another test """ # Restart the remaining masters to allow rid 4 to be reused. for inst in topology_m4.ms.values(): inst.restart() repl = ReplicationManager(DEFAULT_SUFFIX) repl.join_master(topology_m4.ms["master1"], topology_m4.ms["master4"]) # Add the 2,3 -> 4 agmt. repl.ensure_agreement(topology_m4.ms["master2"], topology_m4.ms["master4"]) repl.ensure_agreement(topology_m4.ms["master3"], topology_m4.ms["master4"]) # And in reverse ... repl.ensure_agreement(topology_m4.ms["master4"], topology_m4.ms["master2"]) repl.ensure_agreement(topology_m4.ms["master4"], topology_m4.ms["master3"]) log.info('Master 4 has been successfully restored.')
def restore_master4(topology_m4): """In our tests will always be removing master 4, so we need a common way to restore it for another test """ log.info('Restoring master 4...') # Enable replication on master 4 M4 = topology_m4.ms["master4"] M1 = topology_m4.ms["master1"] repl = ReplicationManager(SUFFIX) repl.join_master(M1, M4) repl.ensure_agreement(M4, M1) repl.ensure_agreement(M1, M4) # Test Replication is working for num in range(2, 5): if topology_m4.ms["master1"].testReplication( DEFAULT_SUFFIX, topology_m4.ms["master{}".format(num)]): log.info('Replication is working m1 -> m{}.'.format(num)) else: log.fatal( 'restore_master4: Replication is not working from m1 -> m{}.'. format(num)) assert False time.sleep(1) # Check replication is working from master 4 to master1... if topology_m4.ms["master4"].testReplication(DEFAULT_SUFFIX, topology_m4.ms["master1"]): log.info('Replication is working m4 -> m1.') else: log.fatal('restore_master4: Replication is not working from m4 -> 1.') assert False time.sleep(5) log.info('Master 4 has been successfully restored.')
def replicate_backend(s1, s2, beSuffix): repl = ReplicationManager(beSuffix) repl.create_first_master(s1) repl.join_master(s1, s2) repl.ensure_agreement(s1, s2) repl.ensure_agreement(s2, s2)
def create_topology(topo_dict, suffix=DEFAULT_SUFFIX): """Create a requested topology. Cascading replication scenario isn't supported :param topo_dict: a dictionary {ReplicaRole.STANDALONE: num, ReplicaRole.MASTER: num, ReplicaRole.CONSUMER: num} :type topo_dict: dict :param suffix: a suffix for the replication :type suffix: str :return - TopologyMain object """ if not topo_dict: ValueError("You need to specify the dict. For instance: {ReplicaRole.STANDALONE: 1}") if ReplicaRole.HUB in topo_dict.keys(): NotImplementedError("Cascading replication scenario isn't supported." "Please, use existing topology or create your own.") topo = _create_instances(topo_dict, suffix) # Start with a single master, and create it "first". first_master = None try: first_master = list(topo.ms.values())[0] log.info("Creating replication topology.") # Now get the first master ready. repl = ReplicationManager(DEFAULT_SUFFIX) repl.create_first_master(first_master) except IndexError: pass # Now init the other masters from this. # This will reinit m, and put a bi-directional agreement # in place. for m in topo.ms.values(): # Skip firstmaster. if m is first_master: continue log.info("Joining master %s to %s ..." % (m.serverid, first_master.serverid)) repl.join_master(first_master, m) # Mesh the master agreements. for mo in topo.ms.values(): for mi in topo.ms.values(): if mo is mi: continue log.info("Ensuring master %s to %s ..." % (mo.serverid, mi.serverid)) repl.ensure_agreement(mo, mi) # Add master -> consumer agreements. for c in topo.cs.values(): log.info("Joining consumer %s from %s ..." % (c.serverid, first_master.serverid)) repl.join_consumer(first_master, c) for m in topo.ms.values(): for c in topo.cs.values(): log.info("Ensuring consumer %s from %s ..." % (c.serverid, m.serverid)) repl.ensure_agreement(m, c) # Clear out the tmp dir for instance in topo: instance.clearTmpDir(__file__) return topo