| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2021 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 os |
| 10 |
import time |
| 11 |
import logging |
| 12 |
import ldap |
| 13 |
import pytest |
| 14 |
from lib389.idm.user import TEST_USER_PROPERTIES, UserAccounts, UserAccount |
| 15 |
from lib389.utils import * |
| 16 |
from lib389._constants import * |
| 17 |
from lib389.replica import Changelog5 |
| 18 |
from lib389.dseldif import * |
| 19 |
from test389.topologies import topology_m3 as topo_m3 |
| 20 |
from lib389.agreement import Agreements |
| 21 |
from lib389.replica import ReplicationManager, Replicas |
| 22 |
|
| 23 |
|
| 24 |
pytestmark = pytest.mark.tier1 |
| 25 |
|
| 26 |
NEW_SUFFIX_NAME = 'test_repl' |
| 27 |
NEW_SUFFIX = 'o={}'.format(NEW_SUFFIX_NAME) |
| 28 |
NEW_BACKEND = 'repl_base' |
| 29 |
CHANGELOG = 'cn=changelog,{}'.format(DN_USERROOT_LDBM) |
| 30 |
MAXAGE_ATTR = 'nsslapd-changelogmaxage' |
| 31 |
MAXAGE_STR = '30s' |
| 32 |
TRIMINTERVAL_STR = '5' |
| 33 |
TRIMINTERVAL = 'nsslapd-changelogtrim-interval' |
| 34 |
|
| 35 |
DEBUGGING = os.getenv("DEBUGGING", default=False) |
| 36 |
if DEBUGGING: |
| 37 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 38 |
else: |
| 39 |
logging.getLogger(__name__).setLevel(logging.INFO) |
| 40 |
log = logging.getLogger(__name__) |
| 41 |
|
| 42 |
count = 0 |
| 43 |
|
| 44 |
def test_cleanallruv_repl(topo_m3): |
| 45 |
"""Test that cleanallruv could not break replication if anchor csn in ruv originated |
| 46 |
in deleted replica |
| 47 |
|
| 48 |
:id: 46faba9a-897e-45b8-98dc-aec7fa8cec9a |
| 49 |
:setup: 3 Suppliers |
| 50 |
:steps: |
| 51 |
1. Configure error log level to 8192 in all suppliers |
| 52 |
2. Modify nsslapd-changelogmaxage=30 and nsslapd-changelogtrim-interval=5 for M1 and M2 |
| 53 |
3. Add test users to 3 suppliers |
| 54 |
4. Launch ClearRuv but withForce |
| 55 |
5. Check the users after CleanRUV, because of changelog trimming, it will effect the CLs |
| 56 |
:expectedresults: |
| 57 |
1. Error logs should be configured successfully |
| 58 |
2. Modify should be successful |
| 59 |
3. Test users should be added successfully |
| 60 |
4. ClearRuv should be launched successfully |
| 61 |
5. Users should be present according to the changelog trimming effect |
| 62 |
""" |
| 63 |
|
| 64 |
M1 = topo_m3.ms["supplier1"] |
| 65 |
M2 = topo_m3.ms["supplier2"] |
| 66 |
M3 = topo_m3.ms["supplier3"] |
| 67 |
|
| 68 |
log.info("Change the error log levels for all suppliers") |
| 69 |
for s in (M1, M2, M3): |
| 70 |
s.config.replace('nsslapd-errorlog-level', "8192") |
| 71 |
|
| 72 |
log.info("Get the replication agreements for all 3 suppliers") |
| 73 |
m1_m2 = M1.agreement.list(suffix=SUFFIX, consumer_host=M2.host, consumer_port=M2.port) |
| 74 |
m1_m3 = M1.agreement.list(suffix=SUFFIX, consumer_host=M3.host, consumer_port=M3.port) |
| 75 |
m3_m1 = M3.agreement.list(suffix=SUFFIX, consumer_host=M1.host, consumer_port=M1.port) |
| 76 |
|
| 77 |
log.info("Modify nsslapd-changelogmaxage=30 and nsslapd-changelogtrim-interval=5 for M1 and M2") |
| 78 |
if ds_supports_new_changelog(): |
| 79 |
CHANGELOG = 'cn=changelog,{}'.format(DN_USERROOT_LDBM) |
| 80 |
|
| 81 |
# set_value(M1, MAXAGE_ATTR, MAXAGE_STR) |
| 82 |
try: |
| 83 |
M1.modify_s(CHANGELOG, [(ldap.MOD_REPLACE, MAXAGE_ATTR, ensure_bytes(MAXAGE_STR))]) |
| 84 |
except ldap.LDAPError as e: |
| 85 |
log.error('Failed to add ' + MAXAGE_ATTR, + ': ' + MAXAGE_STR + ' to ' + CHANGELOG + ': error {}'.format(get_ldap_error_msg(e,'desc'))) |
| 86 |
assert False |
| 87 |
|
| 88 |
# set_value(M2, TRIMINTERVAL, TRIMINTERVAL_STR) |
| 89 |
try: |
| 90 |
M2.modify_s(CHANGELOG, [(ldap.MOD_REPLACE, TRIMINTERVAL, ensure_bytes(TRIMINTERVAL_STR))]) |
| 91 |
except ldap.LDAPError as e: |
| 92 |
log.error('Failed to add ' + TRIMINTERVAL, + ': ' + TRIMINTERVAL_STR + ' to ' + CHANGELOG + ': error {}'.format(get_ldap_error_msg(e,'desc'))) |
| 93 |
assert False |
| 94 |
else: |
| 95 |
log.info("Get the changelog enteries for M1 and M2") |
| 96 |
changelog_m1 = Changelog5(M1) |
| 97 |
changelog_m1.set_max_age(MAXAGE_STR) |
| 98 |
changelog_m1.set_trim_interval(TRIMINTERVAL_STR) |
| 99 |
|
| 100 |
log.info("Add test users to 3 suppliers") |
| 101 |
users_m1 = UserAccounts(M1, DEFAULT_SUFFIX) |
| 102 |
users_m2 = UserAccounts(M2, DEFAULT_SUFFIX) |
| 103 |
users_m3 = UserAccounts(M3, DEFAULT_SUFFIX) |
| 104 |
user_props = TEST_USER_PROPERTIES.copy() |
| 105 |
|
| 106 |
user_props.update({'uid': "testuser10"}) |
| 107 |
user10 = users_m1.create(properties=user_props) |
| 108 |
|
| 109 |
user_props.update({'uid': "testuser20"}) |
| 110 |
user20 = users_m2.create(properties=user_props) |
| 111 |
|
| 112 |
user_props.update({'uid': "testuser30"}) |
| 113 |
user30 = users_m3.create(properties=user_props) |
| 114 |
|
| 115 |
# ::important:: the testuser31 is the oldest csn in M2, |
| 116 |
# because it will be cleared by changelog trimming |
| 117 |
user_props.update({'uid': "testuser31"}) |
| 118 |
user31 = users_m3.create(properties=user_props) |
| 119 |
|
| 120 |
user_props.update({'uid': "testuser11"}) |
| 121 |
user11 = users_m1.create(properties=user_props) |
| 122 |
|
| 123 |
user_props.update({'uid': "testuser21"}) |
| 124 |
user21 = users_m2.create(properties=user_props) |
| 125 |
# this is to trigger changelog trim and interval values |
| 126 |
time.sleep(40) |
| 127 |
|
| 128 |
# Here M1, M2, M3 should have 11,21,31 and 10,20,30 are CL cleared |
| 129 |
M2.stop() |
| 130 |
M1.agreement.pause(m1_m2[0].dn) |
| 131 |
user_props.update({'uid': "testuser32"}) |
| 132 |
user32 = users_m3.create(properties=user_props) |
| 133 |
|
| 134 |
user_props.update({'uid': "testuser33"}) |
| 135 |
user33 = users_m3.create(properties=user_props) |
| 136 |
|
| 137 |
user_props.update({'uid': "testuser12"}) |
| 138 |
user12 = users_m1.create(properties=user_props) |
| 139 |
|
| 140 |
M3.agreement.pause(m3_m1[0].dn) |
| 141 |
M3.agreement.resume(m3_m1[0].dn) |
| 142 |
time.sleep(40) |
| 143 |
|
| 144 |
# Here because of changelog trimming testusers 31 and 32 are CL cleared |
| 145 |
# ClearRuv is launched but with Force |
| 146 |
M3.stop() |
| 147 |
M1.tasks.cleanAllRUV(suffix=SUFFIX, replicaid='3', |
| 148 |
force=True, args={TASK_WAIT: False}) |
| 149 |
|
| 150 |
# here M1 should clear 31 |
| 151 |
M2.start() |
| 152 |
M1.agreement.pause(m1_m2[0].dn) |
| 153 |
M1.agreement.resume(m1_m2[0].dn) |
| 154 |
time.sleep(10) |
| 155 |
|
| 156 |
# Check the users after CleanRUV |
| 157 |
expected_m1_users = [user31.dn, user11.dn, user21.dn, user32.dn, user33.dn, user12.dn] |
| 158 |
expected_m1_users = [x.lower() for x in expected_m1_users] |
| 159 |
expected_m2_users = [user31.dn, user11.dn, user21.dn, user12.dn] |
| 160 |
expected_m2_users = [x.lower() for x in expected_m2_users] |
| 161 |
|
| 162 |
current_m1_users = [user.dn for user in users_m1.list()] |
| 163 |
current_m1_users = [x.lower() for x in current_m1_users] |
| 164 |
current_m2_users = [user.dn for user in users_m2.list()] |
| 165 |
current_m2_users = [x.lower() for x in current_m2_users] |
| 166 |
|
| 167 |
assert set(expected_m1_users).issubset(current_m1_users) |
| 168 |
assert set(expected_m2_users).issubset(current_m2_users) |
| 169 |
M3.start() |
| 170 |
|
| 171 |
|
| 172 |
def get_agmt(inst_from, inst_to): |
| 173 |
for agmt in Agreements(inst_from).list(): |
| 174 |
if agmt.get_attr_val_utf8("nsDS5ReplicaPort") == str(inst_to.port): |
| 175 |
return agmt |
| 176 |
return None |
| 177 |
|
| 178 |
|
| 179 |
def wait_for_val(user, val, timeout=60): |
| 180 |
val = val.encode() |
| 181 |
for _ in range(timeout): |
| 182 |
time.sleep(1) |
| 183 |
vals = user.get_attr_vals('description') |
| 184 |
if val in vals: |
| 185 |
return |
| 186 |
assert False, f"Value {val} not found in {repr(user)} after {timeout} seconds" |
| 187 |
|
| 188 |
|
| 189 |
def perform_updates(inst, replicas): |
| 190 |
global count |
| 191 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 192 |
dn = 'uid=demo_user,ou=people,dc=example,dc=com' |
| 193 |
user = UserAccount(inst, dn) |
| 194 |
for _ in range(4): |
| 195 |
val = f'Test {count}' |
| 196 |
user.add('description', val) |
| 197 |
count += 1 |
| 198 |
for r in replicas: |
| 199 |
user = UserAccount(r, dn) |
| 200 |
wait_for_val(user, val) |
| 201 |
|
| 202 |
|
| 203 |
def check_updates(inst): |
| 204 |
global count |
| 205 |
dn = 'uid=demo_user,ou=people,dc=example,dc=com' |
| 206 |
user = UserAccount(inst, dn) |
| 207 |
vals = user.get_attr_vals('description') |
| 208 |
for i in range(count): |
| 209 |
assert f'Test {i}'.encode() in vals |
| 210 |
|
| 211 |
|
| 212 |
def test_offline_import(topo_m3, request): |
| 213 |
"""Test that keep alive is not updated too soon after an offline import |
| 214 |
|
| 215 |
:id: 493a4810-cc5b-11f0-8c70-c85309d5c3e3 |
| 216 |
:setup: 3 Suppliers |
| 217 |
:steps: |
| 218 |
1. Configure Topology in single loop S1 --> S2 --> S3 --> S1 |
| 219 |
2. Set keep alive interrval to 60 seconds |
| 220 |
3. Perform some updates on S1 |
| 221 |
4. Wait until changes are replicated to S2 and S3 |
| 222 |
5. Stop S3 |
| 223 |
6. Export S3 to ldif with replication metadata |
| 224 |
7. Perform some updates on S1 |
| 225 |
8. Wait until changes are replicated to S2 |
| 226 |
9. Stop S2 |
| 227 |
10. Perform bulk import S3->S1 |
| 228 |
11. Start S3 |
| 229 |
12. Wait 40s |
| 230 |
13. Start S2 |
| 231 |
14. Perform some updates on S2 |
| 232 |
15. Wait until changes are replicated to S3 and S1 |
| 233 |
16. Check that all changes are present on S1 |
| 234 |
:expectedresults: |
| 235 |
1. No error |
| 236 |
2. No error |
| 237 |
3. No error |
| 238 |
4. No error |
| 239 |
5. No error |
| 240 |
6. No error |
| 241 |
7. No error |
| 242 |
8. No error |
| 243 |
9. No error |
| 244 |
10. No error |
| 245 |
11. No error |
| 246 |
12. No error |
| 247 |
13. No error |
| 248 |
14. No error |
| 249 |
15. No error |
| 250 |
16. No error if RHEL-129675 is fixed |
| 251 |
""" |
| 252 |
|
| 253 |
S1 = topo_m3.ms["supplier1"] |
| 254 |
S2 = topo_m3.ms["supplier2"] |
| 255 |
S3 = topo_m3.ms["supplier3"] |
| 256 |
|
| 257 |
def fin(): |
| 258 |
get_agmt(S1, S3).resume() |
| 259 |
get_agmt(S2, S1).resume() |
| 260 |
get_agmt(S3, S2).resume() |
| 261 |
|
| 262 |
request.addfinalizer(fin) |
| 263 |
r1 = Replicas(S1).get(DEFAULT_SUFFIX) |
| 264 |
# 60 is the smallest accepted value for the interval time |
| 265 |
r1.replace('nsds5ReplicaKeepAliveUpdateInterval', '60') |
| 266 |
# Need to restart to reset repeated timer |
| 267 |
S1.restart() |
| 268 |
|
| 269 |
get_agmt(S1, S3).pause() |
| 270 |
get_agmt(S2, S1).pause() |
| 271 |
get_agmt(S3, S2).pause() |
| 272 |
perform_updates(S1, (S2, S3)) |
| 273 |
S3.stop() |
| 274 |
ldif_file = '%s/supplier3.ldif' % S3.get_ldif_dir() |
| 275 |
S3.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], |
| 276 |
excludeSuffixes=None, repl_data=True, |
| 277 |
outputfile=ldif_file, encrypt=False) |
| 278 |
perform_updates(S1, (S2,)) |
| 279 |
S2.stop() |
| 280 |
S1.stop() |
| 281 |
S3.start() |
| 282 |
S1.ldif2db(DEFAULT_BENAME, None, None, None, ldif_file) |
| 283 |
S1.start() |
| 284 |
# wait more than 30s to update keep alive |
| 285 |
time.sleep(40) |
| 286 |
S2.start() |
| 287 |
perform_updates(S2, (S3,S1)) |
| 288 |
check_updates(S1) |
| 289 |
|
| 290 |
|
| 291 |
if __name__ == '__main__': |
| 292 |
# Run isolated |
| 293 |
# -s for DEBUG mode |
| 294 |
CURRENT_FILE = os.path.realpath(__file__) |
| 295 |
pytest.main("-s %s" % CURRENT_FILE) |