def simple_replica(topo, new_suffixes, request): """Enable simple multi-supplier replication""" supplier1 = topo.ins["standalone1"] supplier2 = topo.ins["standalone2"] log.info("Enable two supplier replicas") replicas_m1 = Replicas(supplier1) replica_m1 = replicas_m1.enable(suffix=NEW_SUFFIX, role=ReplicaRole.SUPPLIER, replicaID=REPLICA_SUPPLIER_ID) replicas_m2 = Replicas(supplier2) replica_m2 = replicas_m2.enable(suffix=NEW_SUFFIX, role=ReplicaRole.SUPPLIER, replicaID=REPLICA_SUPPLIER_ID + 1) log.info("Create agreements between the instances") supplier1.agreement.create(suffix=NEW_SUFFIX, host=supplier2.host, port=supplier2.port) supplier2.agreement.create(suffix=NEW_SUFFIX, host=supplier1.host, port=supplier1.port) log.info("Test replication") replicas_m1.test(NEW_SUFFIX, supplier2) def fin(): replicas_m1.disable(NEW_SUFFIX) replicas_m2.disable(NEW_SUFFIX) request.addfinalizer(fin) return [replica_m1, replica_m2]
def test_demote(topo, new_suffixes, clean_up, role_from, role_to): """Check that replica demote method works properly :feature: Replication :steps: 1. Enable replication on the instance 2. Demote it to another role (check supplier-hub, supplier-consumer, hub-consumer) 3. Check that role was successfully changed 4. Disable replication :expectedresults: No errors happen, replica successfully demoted """ inst = topo.ins["standalone1"] log.info("Enable replication on instance with a role - {}".format( role_from.name)) replicas = Replicas(inst) replica = replicas.enable(suffix=NEW_SUFFIX, role=role_from, replicaID=REPLICA_SUPPLIER_ID) log.info("Promote replica to {}".format(role_to.name)) replica.demote(newrole=role_to) log.info("Check that replica was successfully promoted") replica_role = replica.get_role() assert replica_role == role_to
def test_demote_fail(topo, new_suffixes, clean_up, role_from): """Check that replica demote method fails when demoted to wrong direction :feature: Replication :steps: 1. Enable replication on the instance 2. Try to demote it to wrong role (for example, consumer-supplier, hub-supplier) 3. Disable replication :expectedresults: Replica shouldn't be demoted """ inst = topo.ins["standalone1"] log.info("Enable replication on instance with a role - {}".format( role_from.name)) replicas = Replicas(inst) replica = replicas.enable(suffix=NEW_SUFFIX, role=role_from, replicaID=REPLICA_SUPPLIER_ID) for role_to in [x for x in range(1, 4) if x >= role_from.value]: role_to = ReplicaRole(role_to) log.info("Try to demote replica to {}".format(role_to.name)) with pytest.raises(ValueError): replica.demote(newrole=role_to)
def test_basic(topo, new_suffixes, clean_up): """Check basic replica functionality :feature: Replication :steps: 1. Enable replication on supplier. hub and consumer 2. Create agreements: supplier-hub, hub-consumer 3. Test supplier-consumer replication 4. Disable replication 5. Check that replica, agreements and changelog were deleted :expectedresults: No errors happen, replication is successfully enabled and disabled """ supplier = topo.ins["standalone1"] hub = topo.ins["standalone2"] consumer = topo.ins["standalone3"] log.info("Enable replicas (create replica and changelog entries)") supplier_replicas = Replicas(supplier) supplier_replicas.enable(suffix=NEW_SUFFIX, role=ReplicaRole.SUPPLIER, replicaID=REPLICA_SUPPLIER_ID) ents = supplier_replicas.list() assert len(ents) == 1 ents = supplier.changelog.list() assert len(ents) == 1 hub_replicas = Replicas(hub) hub_replicas.enable(suffix=NEW_SUFFIX, role=ReplicaRole.HUB, replicaID=CONSUMER_REPLICAID) ents = hub_replicas.list() assert len(ents) == 1 ents = hub.changelog.list() assert len(ents) == 1 consumer_replicas = Replicas(consumer) consumer_replicas.enable(suffix=NEW_SUFFIX, role=ReplicaRole.CONSUMER) ents = consumer_replicas.list() assert len(ents) == 1 log.info("Create agreements between the instances") supplier.agreement.create(suffix=NEW_SUFFIX, host=hub.host, port=hub.port) ents = supplier.agreement.list(suffix=NEW_SUFFIX) assert len(ents) == 1 hub.agreement.create(suffix=NEW_SUFFIX, host=consumer.host, port=consumer.port) ents = hub.agreement.list(suffix=NEW_SUFFIX) assert len(ents) == 1 log.info("Test replication") supplier_replicas.test(NEW_SUFFIX, consumer) log.info("Disable replication") supplier_replicas.disable(suffix=NEW_SUFFIX) hub_replicas.disable(suffix=NEW_SUFFIX) consumer_replicas.disable(suffix=NEW_SUFFIX) log.info("Check that replica, agreements and changelog were deleted") for num in range(1, 4): log.info("Checking standalone{} instance".format(num)) inst = topo.ins["standalone{}".format(num)] log.info("Checking that replica entries don't exist") replicas = Replicas(inst) ents = replicas.list() assert len(ents) == 0 log.info("Checking that changelog doesn't exist") ents = inst.changelog.list() assert len(ents) == 0 log.info( "Checking that agreements can't be acquired because the replica entry doesn't exist" ) with pytest.raises(NoSuchEntryError) as e: inst.agreement.list(suffix=NEW_SUFFIX) assert "no replica set up" in e.msg