def topology_m1h1c1(request): """Create Replication Deployment with one master, one consumer and one hub""" topo_roles = {ReplicaRole.MASTER: 1, ReplicaRole.HUB: 1, ReplicaRole.CONSUMER: 1} topology = _create_instances(topo_roles, DEFAULT_SUFFIX) master = topology.ms["master1"] hub = topology.hs["hub1"] consumer = topology.cs["consumer1"] # Start with the master, and create it "first". log.info("Creating replication topology.") # Now get the first master ready. repl = ReplicationManager(DEFAULT_SUFFIX) repl.create_first_master(master) # Finish the topology creation repl.join_hub(master, hub) repl.join_consumer(hub, consumer) repl.test_replication(master, consumer) # Clear out the tmp dir for instance in topology: instance.clearTmpDir(__file__) def fin(): if DEBUGGING: [inst.stop() for inst in topology] else: assert _remove_ssca_db(topology) [inst.delete(pyinstall=PYINSTALL) for inst in topology if inst.exists()] request.addfinalizer(fin) topology.logcap = LogCapture() return topology
def test_multiple_changelogs(topo): """Test the multiple suffixes can be replicated with the new per backend changelog. :id: eafcdb57-4ea2-4887-a0a8-9e4d295f4f4d :setup: Supplier Instance, Consumer Instance :steps: 1. Create s second suffix 2. Enable replication for second backend 3. Perform some updates on both backends and make sure replication is working for both backends :expectedresults: 1. Success 2. Success 3. Success """ supplier = topo.ms['supplier1'] consumer = topo.cs['consumer1'] # Create second suffix dc=second_backend on both replicas for inst in [supplier, consumer]: # Create the backends props = {'cn': 'secondRoot', 'nsslapd-suffix': SECOND_SUFFIX} be = Backend(inst) be.create(properties=props) be.create_sample_entries('001004002') # Setup replication for second suffix repl = ReplicationManager(SECOND_SUFFIX) repl.create_first_supplier(supplier) repl.join_consumer(supplier, consumer) # Test replication works for each backend for suffix in [DEFAULT_SUFFIX, SECOND_SUFFIX]: replicas = Replicas(supplier) replica = replicas.get(suffix) log.info("Testing replication for: " + suffix) assert replica.test_replication([consumer])
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
def test_multiple_changelogs_export_import(topo): """Test that we can export and import the replication changelog :id: b74fcaaf-a13f-4ee0-98f9-248b281f8700 :setup: Supplier Instance, Consumer Instance :steps: 1. Create s second suffix 2. Enable replication for second backend 3. Perform some updates on a backend, and export the changelog 4. Do an export and import while the server is idle 5. Do an import while the server is under load :expectedresults: 1. Success 2. Success 3. Success 4. Success 5. Success """ SECOND_SUFFIX = 'dc=second_suffix' supplier = topo.ms['supplier1'] consumer = topo.cs['consumer1'] supplier.config.set('nsslapd-errorlog-level', '0') # Create second suffix dc=second_backend on both replicas for inst in [supplier, consumer]: # Create the backends props = {'cn': 'secondRoot', 'nsslapd-suffix': SECOND_SUFFIX} be = Backend(inst) try: be.create(properties=props) be.create_sample_entries('001004002') except ldap.UNWILLING_TO_PERFORM: pass # Setup replication for second suffix try: repl = ReplicationManager(SECOND_SUFFIX) repl.create_first_supplier(supplier) repl.join_consumer(supplier, consumer) except ldap.ALREADY_EXISTS: pass # Put the replica under load, and export the changelog replicas = Replicas(supplier) replica = replicas.get(DEFAULT_SUFFIX) doMods1 = DoMods(supplier, task="export") doMods1.start() replica.begin_task_cl2ldif() doMods1.join() replica.task_finished() # allow some time to pass, and test replication time.sleep(1) assert replica.test_replication([consumer]) # While idle, go an export and import, and make sure replication still works log.info("Testing idle server with CL export and import...") replica.begin_task_cl2ldif() replica.task_finished() replica.begin_task_ldif2cl() replica.task_finished() assert replica.test_replication([consumer]) # stability test, put the replica under load, import the changelog, and make # sure server did not crash. log.info("Testing busy server with CL import...") doMods2 = DoMods(supplier, task="import") doMods2.start() replica.begin_task_ldif2cl() doMods2.join() replica.task_finished() # Replication will be broken so no need to test it. This is just make sure # the import works, and the server is stable assert supplier.status() assert consumer.status()