| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2022 Red Hat, Inc. |
| 3 |
# All rights reserved. |
| 4 |
# |
| 5 |
# License: GPL (version 3 or any later version). |
| 6 |
# See LICENSE for details. |
| 7 |
# --- END COPYRIGHT BLOCK --- |
| 8 |
# |
| 9 |
import logging |
| 10 |
import pytest |
| 11 |
import os |
| 12 |
from lib389._constants import DEFAULT_SUFFIX, ReplicaRole |
| 13 |
from test389.topologies import topology_m1h1c1 as topo |
| 14 |
from lib389.replica import Replicas, ReplicationManager, Agreements |
| 15 |
|
| 16 |
pytestmark = pytest.mark.tier1 |
| 17 |
|
| 18 |
log = logging.getLogger(__name__) |
| 19 |
|
| 20 |
def test_promote_demote(topo): |
| 21 |
"""Test promoting and demoting a replica |
| 22 |
|
| 23 |
:id: 75edff64-f987-4ed5-a03d-9bee73c0fbf0 |
| 24 |
:setup: 2 Supplier Instances |
| 25 |
:steps: |
| 26 |
1. Promote Hub to a Supplier |
| 27 |
2. Test replication works |
| 28 |
3. Demote the supplier to a consumer |
| 29 |
4. Test replication works |
| 30 |
5. Promote consumer to supplier |
| 31 |
6. Test replication works |
| 32 |
:expectedresults: |
| 33 |
1. Success |
| 34 |
2. Success |
| 35 |
3. Success |
| 36 |
4. Success |
| 37 |
5. Success |
| 38 |
6. Success |
| 39 |
""" |
| 40 |
|
| 41 |
supplier = topo.ms["supplier1"] |
| 42 |
supplier_replica = Replicas(supplier).get(DEFAULT_SUFFIX) |
| 43 |
bind_dn = supplier_replica.get_attr_val_utf8('nsDS5ReplicaBindDN') |
| 44 |
hub = topo.hs["hub1"] |
| 45 |
hub_replica = Replicas(hub).get(DEFAULT_SUFFIX) |
| 46 |
consumer = topo.cs["consumer1"] |
| 47 |
|
| 48 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 49 |
|
| 50 |
# promote replica |
| 51 |
hub_replica.promote(ReplicaRole.SUPPLIER, binddn=bind_dn, rid='55') |
| 52 |
repl.test_replication(supplier, consumer) |
| 53 |
|
| 54 |
# Demote the replica |
| 55 |
hub_replica.demote(ReplicaRole.CONSUMER) |
| 56 |
repl.test_replication(supplier, hub) |
| 57 |
|
| 58 |
# promote replica and init it |
| 59 |
hub_replica.promote(ReplicaRole.SUPPLIER, binddn=bind_dn, rid='56') |
| 60 |
agmt = Agreements(supplier).list()[0] |
| 61 |
agmt.begin_reinit() |
| 62 |
agmt.wait_reinit() |
| 63 |
|
| 64 |
# init consumer |
| 65 |
agmt = Agreements(hub).list()[0] |
| 66 |
agmt.begin_reinit() |
| 67 |
agmt.wait_reinit() |
| 68 |
repl.test_replication(supplier, consumer) |
| 69 |
|
| 70 |
|
| 71 |
if __name__ == '__main__': |
| 72 |
# Run isolated |
| 73 |
# -s for DEBUG mode |
| 74 |
CURRENT_FILE = os.path.realpath(__file__) |
| 75 |
pytest.main(["-s", CURRENT_FILE]) |