| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2024 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 |
import os |
| 9 |
import logging |
| 10 |
import pytest |
| 11 |
import time |
| 12 |
import subprocess |
| 13 |
from test389.topologies import topology_i2 as topo_i2 |
| 14 |
from lib389.replica import ReplicationManager, Replicas |
| 15 |
from lib389._constants import * |
| 16 |
from lib389.agreement import Agreements |
| 17 |
from lib389.properties import * |
| 18 |
|
| 19 |
pytestmark = pytest.mark.tier1 |
| 20 |
|
| 21 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 22 |
if DEBUGGING: |
| 23 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 24 |
else: |
| 25 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 26 |
log = logging.getLogger(__name__) |
| 27 |
|
| 28 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 29 |
def test_replication_agreement_creation_time(topo_i2): |
| 30 |
"""Test the creation time of a replication agreement using dsconf command |
| 31 |
|
| 32 |
:id: 30b2d6a4-64a2-4732-adac-9f73b5c4d07f |
| 33 |
:setup: Two standalone instances |
| 34 |
:steps: |
| 35 |
1. Create and Enable Replication on standalone2 and set role as consumer |
| 36 |
2. Create and Enable Replication on standalone1 and set role as supplier |
| 37 |
3. Prepare dsconf command with replication agreement parameters |
| 38 |
4. Execute dsconf command to create replication agreement |
| 39 |
5. Measure execution time of dsconf command |
| 40 |
6. Verify that the agreement was created successfully |
| 41 |
7. Check if replication works |
| 42 |
:expectedresults: |
| 43 |
1. Replication should be enabled successfully on consumer |
| 44 |
2. Replication should be enabled successfully on supplier |
| 45 |
3. dsconf command should be prepared correctly |
| 46 |
4. dsconf command should execute successfully |
| 47 |
5. Execution time should be less than 5 seconds |
| 48 |
6. Agreement should be present in the supplier's configuration |
| 49 |
7. Replication works |
| 50 |
""" |
| 51 |
|
| 52 |
# Step 1: Get instances |
| 53 |
supplier = topo_i2.ins["standalone1"] |
| 54 |
consumer = topo_i2.ins["standalone2"] |
| 55 |
|
| 56 |
# Step 2: Enable replication on both instances |
| 57 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 58 |
repl.create_first_supplier(supplier) |
| 59 |
consumer.replica.enableReplication(suffix=DEFAULT_SUFFIX, role=ReplicaRole.CONSUMER, replicaId=CONSUMER_REPLICAID) |
| 60 |
|
| 61 |
# Step 3: Prepare variables for the dsconf command |
| 62 |
BINDDN = defaultProperties[REPLICATION_BIND_DN] |
| 63 |
BINDPW = defaultProperties[REPLICATION_BIND_PW] |
| 64 |
BIND_METHOD = defaultProperties[REPLICATION_BIND_METHOD] |
| 65 |
TRANSPORT = defaultProperties[REPLICATION_TRANSPORT] |
| 66 |
|
| 67 |
# Step 4: Prepare the dsconf command |
| 68 |
cmd = [ |
| 69 |
'dsconf', '-D', 'cn=Directory Manager', '-w', PW_DM, |
| 70 |
f'ldap://{supplier.host}:{supplier.port}', |
| 71 |
'repl-agmt', 'create', f'--suffix={DEFAULT_SUFFIX}', |
| 72 |
f'--host={consumer.host}', f'--port={consumer.port}', |
| 73 |
f'--conn-protocol={TRANSPORT}', f'--bind-dn={BINDDN}', |
| 74 |
f'--bind-passwd={BINDPW}', f'--bind-method={BIND_METHOD}', '--init', 'example-agreement' |
| 75 |
] |
| 76 |
|
| 77 |
log.info(f'Executing dsconf command: {" ".join(cmd)}') |
| 78 |
|
| 79 |
# Step 5: Execute the command and measure the time |
| 80 |
start_time = time.time() |
| 81 |
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 82 |
_, stderr = process.communicate() |
| 83 |
end_time = time.time() |
| 84 |
|
| 85 |
execution_time = end_time - start_time |
| 86 |
|
| 87 |
# Check if the command was successful |
| 88 |
if process.returncode == 0: |
| 89 |
log.info(f'Command executed successfully in {execution_time:.2f} seconds') |
| 90 |
else: |
| 91 |
log.error(f'Command failed with error: {stderr.decode("utf-8")}') |
| 92 |
assert process.returncode == 0, f"Command failed with error: {stderr.decode('utf-8')}" |
| 93 |
|
| 94 |
# Assert that the execution time is less than 5 seconds |
| 95 |
log.info(f'Checking execution time: {execution_time:.2f} seconds') |
| 96 |
assert execution_time < 10, f"Command took too long: {execution_time:.2f} seconds" |
| 97 |
|
| 98 |
# Step 6: Verify that the agreement was created |
| 99 |
log.info('Verifying that the agreement was created') |
| 100 |
agreements = Agreements(supplier).list() |
| 101 |
assert len(agreements) == 1, "Agreement was not created successfully" |
| 102 |
|
| 103 |
# Step 7: Check if replication works |
| 104 |
replicas = Replicas(supplier) |
| 105 |
replica = replicas.get(DEFAULT_SUFFIX) |
| 106 |
log.info(f"Testing replication for {DEFAULT_SUFFIX}") |
| 107 |
assert replica.test_replication([consumer]) |
| 108 |
|
| 109 |
log.info('Replication initialization completed successfully') |
| 110 |
log.info('Test completed successfully') |
| 111 |
|
| 112 |
if __name__ == '__main__': |
| 113 |
# Run isolated |
| 114 |
# -s for DEBUG mode |
| 115 |
CURRENT_FILE = os.path.realpath(__file__) |
| 116 |
pytest.main("-s %s" % CURRENT_FILE) |