| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2023 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 |
""" |
| 10 |
Created on Nov 7, 2013 |
| 11 |
|
| 12 |
@author: tbordaz |
| 13 |
""" |
| 14 |
import json |
| 15 |
import logging |
| 16 |
import re |
| 17 |
import time |
| 18 |
import ldap |
| 19 |
import pytest |
| 20 |
from lib389._constants import DN_CONFIG, DEFAULT_SUFFIX |
| 21 |
from test389.topologies import topology_m1c1 |
| 22 |
from lib389.idm.user import UserAccounts |
| 23 |
|
| 24 |
from lib389.utils import ensure_bytes, ensure_str, ds_is_older |
| 25 |
|
| 26 |
# Skip on older versions |
| 27 |
pytestmark = [pytest.mark.tier1, |
| 28 |
pytest.mark.skipif(ds_is_older('1.3'), reason="Not implemented")] |
| 29 |
logging.getLogger(__name__).setLevel(logging.DEBUG) |
| 30 |
log = logging.getLogger(__name__) |
| 31 |
|
| 32 |
TEST_REPL_DN = f"cn=test_repl,{DEFAULT_SUFFIX}" |
| 33 |
ENTRY_NAME = "test_user_1000" |
| 34 |
ENTRY_RDN = f"uid={ENTRY_NAME}" |
| 35 |
ENTRY_DN = f"{ENTRY_RDN},ou=People,{DEFAULT_SUFFIX}" |
| 36 |
MUST_OLD = "(postalAddress $ preferredLocale)" |
| 37 |
MUST_NEW = "(postalAddress $ preferredLocale $ telexNumber)" |
| 38 |
MAY_OLD = "(postalCode $ street)" |
| 39 |
MAY_NEW = "(postalCode $ street $ postOfficeBox)" |
| 40 |
|
| 41 |
MUST_OLD_2 = "(postalAddress $ preferredLocale $ telexNumber)" |
| 42 |
MUST_NEW_2 = "(postalAddress $ preferredLocale)" |
| 43 |
MAY_OLD_2 = "(postalCode $ street)" |
| 44 |
MAY_NEW_2 = "(telexNumber $ postalCode $ street)" |
| 45 |
|
| 46 |
|
| 47 |
def _header(topology_m1c1, label): |
| 48 |
topology_m1c1.ms["supplier1"].log.info("\n\n###############################################") |
| 49 |
topology_m1c1.ms["supplier1"].log.info("#######") |
| 50 |
topology_m1c1.ms["supplier1"].log.info(f"####### {label}") |
| 51 |
topology_m1c1.ms["supplier1"].log.info("#######") |
| 52 |
topology_m1c1.ms["supplier1"].log.info("###################################################") |
| 53 |
|
| 54 |
|
| 55 |
def pattern_errorlog(file, log_pattern): |
| 56 |
try: |
| 57 |
pattern_errorlog.last_pos += 1 |
| 58 |
except AttributeError: |
| 59 |
pattern_errorlog.last_pos = 0 |
| 60 |
|
| 61 |
found = None |
| 62 |
log.debug(f"_pattern_errorlog: start at offset {pattern_errorlog.last_pos}") |
| 63 |
file.seek(pattern_errorlog.last_pos) |
| 64 |
|
| 65 |
# Use a while true iteration because 'for line in file: hit a |
| 66 |
# python bug that break file.tell() |
| 67 |
while True: |
| 68 |
line = file.readline() |
| 69 |
log.debug(f"_pattern_errorlog: [{file.tell()}] {line}") |
| 70 |
found = log_pattern.search(line) |
| 71 |
if ((line == '') or (found)): |
| 72 |
break |
| 73 |
|
| 74 |
log.debug(f"_pattern_errorlog: end at offset {file.tell()}") |
| 75 |
pattern_errorlog.last_pos = file.tell() |
| 76 |
return found |
| 77 |
|
| 78 |
|
| 79 |
def _oc_definition(oid_ext, name, must=None, may=None): |
| 80 |
oid = f"1.2.3.4.5.6.7.8.9.10.{oid_ext}" |
| 81 |
desc = 'To test tickets 47490, 47573, 47721' |
| 82 |
sup = 'person' |
| 83 |
if not must: |
| 84 |
must = MUST_OLD |
| 85 |
if not may: |
| 86 |
may = MAY_OLD |
| 87 |
|
| 88 |
new_oc = f"( {oid} NAME '{name}' DESC '{desc}' SUP {sup} AUXILIARY MUST {must} MAY {may} )" |
| 89 |
return new_oc |
| 90 |
|
| 91 |
|
| 92 |
def add_OC(instance, oid_ext, name, must=None, may=None): |
| 93 |
new_oc = _oc_definition(oid_ext, name, must, may) |
| 94 |
instance.schema.add_schema('objectClasses', ensure_bytes(new_oc)) |
| 95 |
|
| 96 |
|
| 97 |
def mod_OC(instance, oid_ext, name, old_must=None, old_may=None, new_must=None, new_may=None): |
| 98 |
old_oc = _oc_definition(oid_ext, name, old_must, old_may) |
| 99 |
new_oc = _oc_definition(oid_ext, name, new_must, new_may) |
| 100 |
instance.schema.del_schema('objectClasses', ensure_bytes(old_oc)) |
| 101 |
instance.schema.add_schema('objectClasses', ensure_bytes(new_oc)) |
| 102 |
|
| 103 |
|
| 104 |
def support_schema_learning(topology_m1c1): |
| 105 |
""" |
| 106 |
with https://fedorahosted.org/389/ticket/47721, the supplier and consumer can learn |
| 107 |
schema definitions when a replication occurs. |
| 108 |
Before that ticket: replication of the schema fails requiring administrative operation |
| 109 |
In the test the schemaCSN (supplier consumer) differs |
| 110 |
|
| 111 |
After that ticket: replication of the schema succeeds (after an initial phase of learning) |
| 112 |
In the test the schema CSN (supplier consumer) are in sync |
| 113 |
|
| 114 |
This function returns True if 47721 is fixed in the current release |
| 115 |
False else |
| 116 |
""" |
| 117 |
ent = topology_m1c1.cs["consumer1"].getEntry(DN_CONFIG, ldap.SCOPE_BASE, "(cn=config)", ['nsslapd-versionstring']) |
| 118 |
if ent.hasAttr('nsslapd-versionstring'): |
| 119 |
val = ent.getValue('nsslapd-versionstring') |
| 120 |
version = ensure_str(val).split('/')[1].split('.') # something like ['1', '3', '1', '23', 'final_fix'] |
| 121 |
major = int(version[0]) |
| 122 |
minor = int(version[1]) |
| 123 |
if major > 1: |
| 124 |
return True |
| 125 |
if minor > 3: |
| 126 |
# version is 1.4 or after |
| 127 |
return True |
| 128 |
if minor == 3: |
| 129 |
if version[2].isdigit(): |
| 130 |
if int(version[2]) >= 3: |
| 131 |
return True |
| 132 |
return False |
| 133 |
|
| 134 |
|
| 135 |
def trigger_update(topology_m1c1): |
| 136 |
""" |
| 137 |
It triggers an update on the supplier. This will start a replication |
| 138 |
session and a schema push |
| 139 |
""" |
| 140 |
try: |
| 141 |
trigger_update.value += 1 |
| 142 |
except AttributeError: |
| 143 |
trigger_update.value = 1 |
| 144 |
|
| 145 |
user = UserAccounts(topology_m1c1.ms["supplier1"], DEFAULT_SUFFIX).get(ENTRY_NAME) |
| 146 |
user.replace('telephonenumber', ensure_bytes(str(trigger_update.value))) |
| 147 |
|
| 148 |
# wait 10 seconds that the update is replicated |
| 149 |
loop = 0 |
| 150 |
while loop <= 10: |
| 151 |
try: |
| 152 |
ent = topology_m1c1.cs["consumer1"].getEntry(ENTRY_DN, ldap.SCOPE_BASE, "(objectclass=*)", |
| 153 |
['telephonenumber']) |
| 154 |
val = ent.telephonenumber or "0" |
| 155 |
if int(val) == trigger_update.value: |
| 156 |
return |
| 157 |
# the expected value is not yet replicated. try again |
| 158 |
time.sleep(1) |
| 159 |
loop += 1 |
| 160 |
log.debug(f"trigger_update: receive {val} (expected {trigger_update.value})") |
| 161 |
except ldap.NO_SUCH_OBJECT: |
| 162 |
time.sleep(1) |
| 163 |
loop += 1 |
| 164 |
|
| 165 |
|
| 166 |
def trigger_schema_push(topology_m1c1): |
| 167 |
''' |
| 168 |
Trigger update to create a replication session. |
| 169 |
In case of 47721 is fixed and the replica needs to learn the missing definition, then |
| 170 |
the first replication session learn the definition and the second replication session |
| 171 |
push the schema (and the schemaCSN. |
| 172 |
This is why there is two updates and replica agreement is stopped/start (to create a second session) |
| 173 |
''' |
| 174 |
agreements = topology_m1c1.ms["supplier1"].agreement.list(suffix=DEFAULT_SUFFIX, |
| 175 |
consumer_host=topology_m1c1.cs["consumer1"].host, |
| 176 |
consumer_port=topology_m1c1.cs["consumer1"].port) |
| 177 |
assert (len(agreements) == 1) |
| 178 |
ra = agreements[0] |
| 179 |
trigger_update(topology_m1c1) |
| 180 |
topology_m1c1.ms["supplier1"].agreement.pause(ra.dn) |
| 181 |
topology_m1c1.ms["supplier1"].agreement.resume(ra.dn) |
| 182 |
trigger_update(topology_m1c1) |
| 183 |
|
| 184 |
|
| 185 |
@pytest.fixture(scope="function") |
| 186 |
def schema_replication_init(request, topology_m1c1): |
| 187 |
"""Initialize the test environment |
| 188 |
|
| 189 |
""" |
| 190 |
users = UserAccounts(topology_m1c1.ms["supplier1"], DEFAULT_SUFFIX) |
| 191 |
if users.exists(ENTRY_RDN): |
| 192 |
# delete the test entry if it exists |
| 193 |
users.delete(ENTRY_RDN) |
| 194 |
|
| 195 |
log.debug("test_schema_replication_init topology_m1c1 %r (supplier %r, consumer %r" % ( |
| 196 |
topology_m1c1, topology_m1c1.ms["supplier1"], topology_m1c1.cs["consumer1"])) |
| 197 |
# check if a warning message is logged in the error log of the supplier |
| 198 |
topology_m1c1.ms["supplier1"].errorlog_file = open(topology_m1c1.ms["supplier1"].errlog, "r") |
| 199 |
|
| 200 |
# This entry will be used to trigger attempt of schema push |
| 201 |
user = users.create_test_user() |
| 202 |
|
| 203 |
def fin(): |
| 204 |
if user.exists(): |
| 205 |
user.delete() |
| 206 |
|
| 207 |
request.addfinalizer(fin) |
| 208 |
|
| 209 |
|
| 210 |
def test_schema_replication_one(topology_m1c1, schema_replication_init): |
| 211 |
"""Check supplier schema is a superset (one extra OC) of consumer schema, then |
| 212 |
schema is pushed and there is no message in the error log |
| 213 |
|
| 214 |
:id: d6c6ff30-b3ae-4001-80ff-0fb18563a393 |
| 215 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 216 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 217 |
:steps: |
| 218 |
1. Update the schema of supplier, so it will be superset of consumer |
| 219 |
2. Push the Schema (no error) |
| 220 |
3. Check both supplier and consumer has same schemaCSN |
| 221 |
4. Check the startup/final state |
| 222 |
:expectedresults: |
| 223 |
1. Operation should be successful |
| 224 |
2. Operation should be successful |
| 225 |
3. Operation should be successful |
| 226 |
4. State at startup: |
| 227 |
- supplier default schema |
| 228 |
- consumer default schema |
| 229 |
Final state |
| 230 |
- supplier +supplierNewOCA |
| 231 |
- consumer +supplierNewOCA |
| 232 |
""" |
| 233 |
|
| 234 |
_header(topology_m1c1, "Extra OC Schema is pushed - no error") |
| 235 |
|
| 236 |
log.debug(f"test_schema_replication_one topology_m1c1 {topology_m1c1} " |
| 237 |
f"(supplier {topology_m1c1.ms["supplier1"]}, consumer {topology_m1c1.cs["consumer1"]}") |
| 238 |
# update the schema of the supplier so that it is a superset of consumer. Schema should be pushed |
| 239 |
add_OC(topology_m1c1.ms["supplier1"], 2, 'supplierNewOCA') |
| 240 |
|
| 241 |
trigger_schema_push(topology_m1c1) |
| 242 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 243 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 244 |
|
| 245 |
# Check the schemaCSN was updated on the consumer |
| 246 |
log.debug(f"test_schema_replication_one supplier_schema_csn={supplier_schema_csn}") |
| 247 |
log.debug(f"test_schema_replication_one consumer_schema_csn={consumer_schema_csn}") |
| 248 |
assert supplier_schema_csn == consumer_schema_csn |
| 249 |
|
| 250 |
# Check the error log of the supplier does not contain an error |
| 251 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 252 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 253 |
assert res is None |
| 254 |
|
| 255 |
|
| 256 |
def test_schema_replication_two(topology_m1c1, schema_replication_init): |
| 257 |
"""Check consumer schema is a superset (one extra OC) of supplier schema, then |
| 258 |
schema is pushed and there is a message in the error log |
| 259 |
|
| 260 |
:id: b5db9b75-a9a7-458e-86ec-2a8e7bd1c014 |
| 261 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 262 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 263 |
:steps: |
| 264 |
1. Update the schema of consumer, so it will be superset of supplier |
| 265 |
2. Update the schema of supplier so ti make it's nsSchemaCSN larger than consumer |
| 266 |
3. Push the Schema (error should be generated) |
| 267 |
4. Check supplier learns the missing definition |
| 268 |
5. Check the error logs |
| 269 |
6. Check the startup/final state |
| 270 |
:expectedresults: |
| 271 |
1. Operation should be successful |
| 272 |
2. Operation should be successful |
| 273 |
3. Operation should be successful |
| 274 |
4. Operation should be successful |
| 275 |
5. Operation should be successful |
| 276 |
6. State at startup |
| 277 |
- supplier +supplierNewOCA |
| 278 |
- consumer +supplierNewOCA |
| 279 |
Final state |
| 280 |
- supplier +supplierNewOCA +supplierNewOCB |
| 281 |
- consumer +supplierNewOCA +consumerNewOCA |
| 282 |
""" |
| 283 |
|
| 284 |
_header(topology_m1c1, "Extra OC Schema is pushed - (ticket 47721 allows to learn missing def)") |
| 285 |
|
| 286 |
# add this OC on consumer. Supplier will no push the schema |
| 287 |
add_OC(topology_m1c1.cs["consumer1"], 1, 'consumerNewOCA') |
| 288 |
|
| 289 |
# add a new OC on the supplier so that its nsSchemaCSN is larger than the consumer (wait 2s) |
| 290 |
time.sleep(2) |
| 291 |
add_OC(topology_m1c1.ms["supplier1"], 3, 'supplierNewOCB') |
| 292 |
|
| 293 |
# now push the schema |
| 294 |
trigger_schema_push(topology_m1c1) |
| 295 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 296 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 297 |
|
| 298 |
# Check the schemaCSN was NOT updated on the consumer |
| 299 |
# with 47721, supplier learns the missing definition |
| 300 |
log.debug(f"test_schema_replication_two supplier_schema_csn={supplier_schema_csn}") |
| 301 |
log.debug(f"test_schema_replication_two consumer_schema_csn={consumer_schema_csn}") |
| 302 |
if support_schema_learning(topology_m1c1): |
| 303 |
assert supplier_schema_csn == consumer_schema_csn |
| 304 |
else: |
| 305 |
assert supplier_schema_csn != consumer_schema_csn |
| 306 |
|
| 307 |
# Check the error log of the supplier does contain an error |
| 308 |
# This message may happen during the learning phase |
| 309 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 310 |
pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 311 |
|
| 312 |
# Check that standard schema was not rewritten to be "user defined' on the consumer |
| 313 |
cn_attrs = json.loads(topology_m1c1.cs["consumer1"].schema.query_attributetype("cn", json=True)) |
| 314 |
cn_attr = cn_attrs['at'] |
| 315 |
assert cn_attr['x_origin'][0].lower() != "user defined" |
| 316 |
if len(cn_attr['x_origin']) > 1: |
| 317 |
assert cn_attr['x_origin'][1].lower() != "user defined" |
| 318 |
|
| 319 |
# Check that the new OC "supplierNewOCB" was written to be "user defined' on the consumer |
| 320 |
ocs = json.loads(topology_m1c1.cs["consumer1"].schema.query_objectclass("supplierNewOCB", json=True)) |
| 321 |
new_oc = ocs['oc'] |
| 322 |
assert new_oc['x_origin'][0].lower() == "user defined" |
| 323 |
|
| 324 |
|
| 325 |
def test_schema_replication_three(topology_m1c1, schema_replication_init): |
| 326 |
"""Check supplier schema is again a superset (one extra OC), then |
| 327 |
schema is pushed and there is no message in the error log |
| 328 |
|
| 329 |
:id: 45888895-76bc-4cc3-9f90-33a69d027116 |
| 330 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 331 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 332 |
:steps: |
| 333 |
1. Update the schema of supplier |
| 334 |
2. Push the Schema (no error) |
| 335 |
3. Check the schemaCSN was NOT updated on the consumer |
| 336 |
4. Check the error logs for no errors |
| 337 |
5. Check the startup/final state |
| 338 |
:expectedresults: |
| 339 |
1. Operation should be successful |
| 340 |
2. Operation should be successful |
| 341 |
3. Operation should be successful |
| 342 |
4. Operation should be successful |
| 343 |
5. State at startup |
| 344 |
- supplier +supplierNewOCA +supplierNewOCB |
| 345 |
- consumer +supplierNewOCA +consumerNewOCA |
| 346 |
Final state |
| 347 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 348 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 349 |
""" |
| 350 |
_header(topology_m1c1, "Extra OC Schema is pushed - no error") |
| 351 |
|
| 352 |
# Do an upate to trigger the schema push attempt |
| 353 |
# add this OC on consumer. Supplier will no push the schema |
| 354 |
add_OC(topology_m1c1.ms["supplier1"], 1, 'consumerNewOCA') |
| 355 |
|
| 356 |
# now push the scheam |
| 357 |
trigger_schema_push(topology_m1c1) |
| 358 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 359 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 360 |
|
| 361 |
# Check the schemaCSN was NOT updated on the consumer |
| 362 |
log.debug(f"test_schema_replication_three supplier_schema_csn={supplier_schema_csn}") |
| 363 |
log.debug(f"test_schema_replication_three consumer_schema_csn={consumer_schema_csn}") |
| 364 |
assert supplier_schema_csn == consumer_schema_csn |
| 365 |
|
| 366 |
# Check the error log of the supplier does not contain an error |
| 367 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 368 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 369 |
assert res is None |
| 370 |
|
| 371 |
|
| 372 |
def test_schema_replication_four(topology_m1c1, schema_replication_init): |
| 373 |
"""Check supplier schema is again a superset (OC with more MUST), then |
| 374 |
schema is pushed and there is no message in the error log |
| 375 |
|
| 376 |
:id: 39304242-2641-4eb8-a9fb-5ff0cf80718f |
| 377 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 378 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 379 |
:steps: |
| 380 |
1. Add telenumber to 'supplierNewOCA' on the supplier |
| 381 |
2. Push the Schema (no error) |
| 382 |
3. Check the schemaCSN was updated on the consumer |
| 383 |
4. Check the error log of the supplier does not contain an error |
| 384 |
5. Check the startup/final state |
| 385 |
:expectedresults: |
| 386 |
1. Operation should be successful |
| 387 |
2. Operation should be successful |
| 388 |
3. Operation should be successful |
| 389 |
4. Operation should be successful |
| 390 |
5. State at startup |
| 391 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 392 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 393 |
Final state |
| 394 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 395 |
+must=telexnumber |
| 396 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 397 |
+must=telexnumber |
| 398 |
""" |
| 399 |
_header(topology_m1c1, "Same OC - extra MUST: Schema is pushed - no error") |
| 400 |
|
| 401 |
mod_OC(topology_m1c1.ms["supplier1"], 2, 'supplierNewOCA', |
| 402 |
old_must=MUST_OLD, new_must=MUST_NEW, |
| 403 |
old_may=MAY_OLD, new_may=MAY_OLD) |
| 404 |
|
| 405 |
trigger_schema_push(topology_m1c1) |
| 406 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 407 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 408 |
|
| 409 |
# Check the schemaCSN was updated on the consumer |
| 410 |
log.debug(f"test_schema_replication_four supplier_schema_csn={supplier_schema_csn}") |
| 411 |
log.debug(f"test_schema_replication_four consumer_schema_csn={consumer_schema_csn}") |
| 412 |
assert supplier_schema_csn == consumer_schema_csn |
| 413 |
|
| 414 |
# Check the error log of the supplier does not contain an error |
| 415 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 416 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 417 |
assert res is None |
| 418 |
|
| 419 |
|
| 420 |
def test_schema_replication_five(topology_m1c1, schema_replication_init): |
| 421 |
"""Check consumer schema is a superset (OC with more MUST), then |
| 422 |
schema is pushed (fix for 47721) and there is a message in the error log |
| 423 |
|
| 424 |
:id: 498527df-28c8-4e1a-bc9e-799fd2b7b2bb |
| 425 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 426 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 427 |
:steps: |
| 428 |
1. Add telenumber to 'consumerNewOCA' on the consumer |
| 429 |
2. Add a new OC on the supplier so that its nsSchemaCSN is larger than the consumer |
| 430 |
3. Push the Schema |
| 431 |
4. Check the schemaCSN was NOT updated on the consumer |
| 432 |
5. Check the error log of the supplier contain an error |
| 433 |
6. Check the startup/final state |
| 434 |
:expectedresults: |
| 435 |
1. Operation should be successful |
| 436 |
2. Operation should be successful |
| 437 |
3. Operation should be successful |
| 438 |
4. Operation should be successful |
| 439 |
5. Operation should be successful |
| 440 |
6. State at startup |
| 441 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 442 |
+must=telexnumber |
| 443 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 444 |
+must=telexnumber |
| 445 |
Final state |
| 446 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 447 |
+must=telexnumber |
| 448 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 449 |
+must=telexnumber +must=telexnumber |
| 450 |
|
| 451 |
Note: replication log is enabled to get more details |
| 452 |
""" |
| 453 |
_header(topology_m1c1, "Same OC - extra MUST: Schema is pushed - (fix for 47721)") |
| 454 |
|
| 455 |
# get more detail why it fails |
| 456 |
topology_m1c1.ms["supplier1"].enableReplLogging() |
| 457 |
|
| 458 |
# add telenumber to 'consumerNewOCA' on the consumer |
| 459 |
mod_OC(topology_m1c1.cs["consumer1"], 1, 'consumerNewOCA', |
| 460 |
old_must=MUST_OLD, new_must=MUST_NEW, |
| 461 |
old_may=MAY_OLD, new_may=MAY_OLD) |
| 462 |
# add a new OC on the supplier so that its nsSchemaCSN is larger than the consumer (wait 2s) |
| 463 |
time.sleep(2) |
| 464 |
add_OC(topology_m1c1.ms["supplier1"], 4, 'supplierNewOCC') |
| 465 |
|
| 466 |
trigger_schema_push(topology_m1c1) |
| 467 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 468 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 469 |
|
| 470 |
# Check the schemaCSN was NOT updated on the consumer |
| 471 |
# with 47721, supplier learns the missing definition |
| 472 |
log.debug(f"test_schema_replication_five supplier_schema_csn={supplier_schema_csn}") |
| 473 |
log.debug(f"test_schema_replication_five consumer_schema_csn={consumer_schema_csn}") |
| 474 |
if support_schema_learning(topology_m1c1): |
| 475 |
assert supplier_schema_csn == consumer_schema_csn |
| 476 |
else: |
| 477 |
assert supplier_schema_csn != consumer_schema_csn |
| 478 |
|
| 479 |
# Check the error log of the supplier does contain an error |
| 480 |
# This message may happen during the learning phase |
| 481 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 482 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 483 |
assert res is not None |
| 484 |
|
| 485 |
|
| 486 |
def test_schema_replication_six(topology_m1c1, schema_replication_init): |
| 487 |
"""Check supplier schema is again a superset (OC with more MUST), then |
| 488 |
schema is pushed and there is no message in the error log |
| 489 |
|
| 490 |
:id: ed57b0cc-6a10-4f89-94ae-9f18542b1954 |
| 491 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 492 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 493 |
:steps: |
| 494 |
1. Add telenumber to 'consumerNewOCA' on the supplier |
| 495 |
2. Push the Schema (no error) |
| 496 |
3. Check the schemaCSN was NOT updated on the consumer |
| 497 |
4. Check the error log of the supplier does not contain an error |
| 498 |
5. Check the startup/final state |
| 499 |
:expectedresults: |
| 500 |
1. Operation should be successful |
| 501 |
2. Operation should be successful |
| 502 |
3. Operation should be successful |
| 503 |
4. Operation should be successful |
| 504 |
5. State at startup |
| 505 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 506 |
+must=telexnumber |
| 507 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA |
| 508 |
+must=telexnumber +must=telexnumber |
| 509 |
Final state |
| 510 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 511 |
+must=telexnumber +must=telexnumber |
| 512 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 513 |
+must=telexnumber +must=telexnumber |
| 514 |
|
| 515 |
Note: replication log is enabled to get more details |
| 516 |
""" |
| 517 |
_header(topology_m1c1, "Same OC - extra MUST: Schema is pushed - no error") |
| 518 |
|
| 519 |
# add telenumber to 'consumerNewOCA' on the consumer |
| 520 |
mod_OC(topology_m1c1.ms["supplier1"], 1, 'consumerNewOCA', |
| 521 |
old_must=MUST_OLD, new_must=MUST_NEW, |
| 522 |
old_may=MAY_OLD, new_may=MAY_OLD) |
| 523 |
|
| 524 |
trigger_schema_push(topology_m1c1) |
| 525 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 526 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 527 |
|
| 528 |
# Check the schemaCSN was NOT updated on the consumer |
| 529 |
log.debug(f"test_schema_replication_six supplier_schema_csn={supplier_schema_csn}") |
| 530 |
log.debug(f"test_schema_replication_six consumer_schema_csn={consumer_schema_csn}") |
| 531 |
assert supplier_schema_csn == consumer_schema_csn |
| 532 |
|
| 533 |
# Check the error log of the supplier does not contain an error |
| 534 |
# This message may happen during the learning phase |
| 535 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 536 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 537 |
assert res is None |
| 538 |
|
| 539 |
|
| 540 |
def test_schema_replication_seven(topology_m1c1, schema_replication_init): |
| 541 |
"""Check supplier schema is again a superset (OC with more MAY), then |
| 542 |
schema is pushed and there is no message in the error log |
| 543 |
|
| 544 |
:id: 8725055a-b3f8-4d1d-a4d6-bb7dccf644d0 |
| 545 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 546 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 547 |
:steps: |
| 548 |
1. Add telenumber to 'supplierNewOCA' on the supplier |
| 549 |
2. Push the Schema (no error) |
| 550 |
3. Check the schemaCSN was updated on the consumer |
| 551 |
4. Check the error log of the supplier does not contain an error |
| 552 |
5. Check the startup/final state |
| 553 |
:expectedresults: |
| 554 |
1. Operation should be successful |
| 555 |
2. Operation should be successful |
| 556 |
3. Operation should be successful |
| 557 |
4. Operation should be successful |
| 558 |
5. State at startup |
| 559 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 560 |
+must=telexnumber +must=telexnumber |
| 561 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 562 |
+must=telexnumber +must=telexnumber |
| 563 |
Final state |
| 564 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 565 |
+must=telexnumber +must=telexnumber |
| 566 |
+may=postOfficeBox |
| 567 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 568 |
+must=telexnumber +must=telexnumber |
| 569 |
+may=postOfficeBox |
| 570 |
""" |
| 571 |
_header(topology_m1c1, "Same OC - extra MAY: Schema is pushed - no error") |
| 572 |
|
| 573 |
mod_OC(topology_m1c1.ms["supplier1"], 2, 'supplierNewOCA', |
| 574 |
old_must=MUST_NEW, new_must=MUST_NEW, |
| 575 |
old_may=MAY_OLD, new_may=MAY_NEW) |
| 576 |
|
| 577 |
trigger_schema_push(topology_m1c1) |
| 578 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 579 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 580 |
|
| 581 |
# Check the schemaCSN was updated on the consumer |
| 582 |
log.debug(f"test_schema_replication_seven supplier_schema_csn={supplier_schema_csn}") |
| 583 |
log.debug(f"test_schema_replication_seven consumer_schema_csn={consumer_schema_csn}") |
| 584 |
assert supplier_schema_csn == consumer_schema_csn |
| 585 |
|
| 586 |
# Check the error log of the supplier does not contain an error |
| 587 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 588 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 589 |
assert res is None |
| 590 |
|
| 591 |
|
| 592 |
def test_schema_replication_eight(topology_m1c1, schema_replication_init): |
| 593 |
"""Check consumer schema is a superset (OC with more MAY), then |
| 594 |
schema is pushed (fix for 47721) and there is message in the error log |
| 595 |
|
| 596 |
:id: 2310d150-a71a-498d-add8-4056beeb58c6 |
| 597 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 598 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 599 |
:steps: |
| 600 |
1. Add telenumber to 'consumerNewOCA' on the consumer |
| 601 |
2. Modify OC on the supplier so that its nsSchemaCSN is larger than the consumer |
| 602 |
3. Push the Schema (no error) |
| 603 |
4. Check the schemaCSN was updated on the consumer |
| 604 |
5. Check the error log of the supplier does not contain an error |
| 605 |
6. Check the startup/final state |
| 606 |
:expectedresults: |
| 607 |
1. Operation should be successful |
| 608 |
2. Operation should be successful |
| 609 |
3. Operation should be successful |
| 610 |
4. Operation should be successful |
| 611 |
5. Operation should be successful |
| 612 |
6. State at startup |
| 613 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 614 |
+must=telexnumber +must=telexnumber |
| 615 |
+may=postOfficeBox |
| 616 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 617 |
+must=telexnumber +must=telexnumber |
| 618 |
+may=postOfficeBox |
| 619 |
Final state |
| 620 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 621 |
+must=telexnumber +must=telexnumber |
| 622 |
+may=postOfficeBox +may=postOfficeBox |
| 623 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 624 |
+must=telexnumber +must=telexnumber |
| 625 |
+may=postOfficeBox +may=postOfficeBox |
| 626 |
""" |
| 627 |
_header(topology_m1c1, "Same OC - extra MAY: Schema is pushed (fix for 47721)") |
| 628 |
|
| 629 |
mod_OC(topology_m1c1.cs["consumer1"], 1, 'consumerNewOCA', |
| 630 |
old_must=MUST_NEW, new_must=MUST_NEW, |
| 631 |
old_may=MAY_OLD, new_may=MAY_NEW) |
| 632 |
|
| 633 |
# modify OC on the supplier so that its nsSchemaCSN is larger than the consumer (wait 2s) |
| 634 |
time.sleep(2) |
| 635 |
mod_OC(topology_m1c1.ms["supplier1"], 4, 'supplierNewOCC', |
| 636 |
old_must=MUST_OLD, new_must=MUST_OLD, |
| 637 |
old_may=MAY_OLD, new_may=MAY_NEW) |
| 638 |
|
| 639 |
trigger_schema_push(topology_m1c1) |
| 640 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 641 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 642 |
|
| 643 |
# Check the schemaCSN was not updated on the consumer |
| 644 |
# with 47721, supplier learns the missing definition |
| 645 |
log.debug(f"test_schema_replication_eight supplier_schema_csn={supplier_schema_csn}") |
| 646 |
log.debug(f"test_schema_replication_eight consumer_schema_csn={consumer_schema_csn}") |
| 647 |
if support_schema_learning(topology_m1c1): |
| 648 |
assert supplier_schema_csn == consumer_schema_csn |
| 649 |
else: |
| 650 |
assert supplier_schema_csn != consumer_schema_csn |
| 651 |
|
| 652 |
# Check the error log of the supplier does contain an error |
| 653 |
# This message may happen during the learning phase |
| 654 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 655 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 656 |
assert res is not None |
| 657 |
|
| 658 |
|
| 659 |
def test_schema_replication_nine(topology_m1c1, schema_replication_init): |
| 660 |
"""Check consumer schema is a superset (OC with more MAY), then |
| 661 |
schema is not pushed and there is message in the error log |
| 662 |
|
| 663 |
:id: 851b24c6-b1e0-466f-9714-aa2940fbfeeb |
| 664 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 665 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 666 |
:steps: |
| 667 |
1. Add postOfficeBox to 'consumerNewOCA' on the supplier |
| 668 |
3. Push the Schema |
| 669 |
4. Check the schemaCSN was updated on the consumer |
| 670 |
5. Check the error log of the supplier does contain an error |
| 671 |
6. Check the startup/final state |
| 672 |
:expectedresults: |
| 673 |
1. Operation should be successful |
| 674 |
2. Operation should be successful |
| 675 |
3. Operation should be successful |
| 676 |
4. Operation should be successful |
| 677 |
5. Operation should be successful |
| 678 |
6. State at startup |
| 679 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 680 |
+must=telexnumber +must=telexnumber |
| 681 |
+may=postOfficeBox +may=postOfficeBox |
| 682 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 683 |
+must=telexnumber +must=telexnumber |
| 684 |
+may=postOfficeBox +may=postOfficeBox |
| 685 |
Final state |
| 686 |
- supplier +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 687 |
+must=telexnumber +must=telexnumber |
| 688 |
+may=postOfficeBox +may=postOfficeBox +may=postOfficeBox |
| 689 |
- consumer +supplierNewOCA +supplierNewOCB +consumerNewOCA +supplierNewOCC |
| 690 |
+must=telexnumber +must=telexnumber |
| 691 |
+may=postOfficeBox +may=postOfficeBox +may=postOfficeBox |
| 692 |
""" |
| 693 |
_header(topology_m1c1, "Same OC - extra MAY: Schema is pushed - no error") |
| 694 |
|
| 695 |
mod_OC(topology_m1c1.ms["supplier1"], 1, 'consumerNewOCA', |
| 696 |
old_must=MUST_NEW, new_must=MUST_NEW, |
| 697 |
old_may=MAY_OLD, new_may=MAY_NEW) |
| 698 |
|
| 699 |
trigger_schema_push(topology_m1c1) |
| 700 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 701 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 702 |
|
| 703 |
# Check the schemaCSN was updated on the consumer |
| 704 |
log.debug(f"test_schema_replication_nine supplier_schema_csn={supplier_schema_csn}") |
| 705 |
log.debug(f"test_schema_replication_nine consumer_schema_csn={consumer_schema_csn}") |
| 706 |
assert supplier_schema_csn == consumer_schema_csn |
| 707 |
|
| 708 |
# Check the error log of the supplier does not contain an error |
| 709 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 710 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 711 |
assert res is None |
| 712 |
|
| 713 |
log.info('Testcase PASSED') |
| 714 |
|
| 715 |
|
| 716 |
def test_move_must_attribute_to_may(topology_m1c1, schema_replication_init): |
| 717 |
""" Check that if a MUST attribute is moved to MAY on supplier, but remains unchanged on the consumer, |
| 718 |
thus making the consumer a superset (OC has more MUST), then schema is pushed |
| 719 |
|
| 720 |
:id: c39acd35-4566-47cf-97ba-657dcf7e56ab |
| 721 |
:setup: Supplier Consumer, check if a warning message is logged in the |
| 722 |
error log of the supplier and add a test entry to trigger attempt of schema push. |
| 723 |
:steps: |
| 724 |
1. Create OCwithMayAttr on the supplier with MUST and MAY attributes |
| 725 |
2. Push the schema |
| 726 |
3. Check the schemaCSN was updated on the consumer |
| 727 |
4. Check the error log of the supplier does not contain an error |
| 728 |
5. Change the OCwithMayAttr on the supplier to move a MUST attribute to MAY |
| 729 |
6. Push the schema |
| 730 |
7. Check the schemaCSN was NOT updated on the consumer |
| 731 |
8. Check the error log of the supplier does not contain an error |
| 732 |
9. Create an entry with OCwithMayAttr on the supplier |
| 733 |
10. Check the entry was replicated to the consumer |
| 734 |
:expectedresults: |
| 735 |
1. Operation should be successful |
| 736 |
2. Operation should be successful |
| 737 |
3. Operation should be successful |
| 738 |
4. Operation should be successful |
| 739 |
5. Operation should be successful |
| 740 |
6. Operation should be successful |
| 741 |
7. Operation should be successful |
| 742 |
8. Operation should be successful |
| 743 |
9. Operation should be successful |
| 744 |
10. Operation should be successful |
| 745 |
""" |
| 746 |
log.debug(f"test_move_must_attribute_to_may topology_m1c1 {topology_m1c1} " |
| 747 |
f"(supplier {topology_m1c1.ms["supplier1"]}, consumer {topology_m1c1.cs["consumer1"]}") |
| 748 |
|
| 749 |
# update the schema of the supplier so that it is a superset of consumer. Schema should be pushed |
| 750 |
add_OC(topology_m1c1.ms["supplier1"], 5, 'OCwithMayAttr', |
| 751 |
must=MUST_OLD_2, may=MAY_OLD_2) |
| 752 |
|
| 753 |
trigger_schema_push(topology_m1c1) |
| 754 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 755 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 756 |
|
| 757 |
# Check the schemaCSN was updated on the consumer |
| 758 |
log.debug(f"test_move_must_attribute_to_may supplier_schema_csn={supplier_schema_csn}") |
| 759 |
log.debug(f"test_move_must_attribute_to_may consumer_schema_csn={consumer_schema_csn}") |
| 760 |
assert supplier_schema_csn == consumer_schema_csn |
| 761 |
|
| 762 |
# Check the error log of the supplier does not contain an error |
| 763 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 764 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 765 |
assert res is None |
| 766 |
|
| 767 |
# Update the objectclass so that a MUST attribute is moved to MAY attribute |
| 768 |
mod_OC(topology_m1c1.ms["supplier1"], 5, 'OCwithMayAttr', |
| 769 |
old_must=MUST_OLD_2, new_must=MUST_NEW_2, |
| 770 |
old_may=MAY_OLD_2, new_may=MAY_NEW_2) |
| 771 |
|
| 772 |
# push the schema |
| 773 |
trigger_schema_push(topology_m1c1) |
| 774 |
supplier_schema_csn = topology_m1c1.ms["supplier1"].schema.get_schema_csn() |
| 775 |
consumer_schema_csn = topology_m1c1.cs["consumer1"].schema.get_schema_csn() |
| 776 |
|
| 777 |
# Check the schemaCSN was NOT updated on the consumer |
| 778 |
log.debug(f"test_move_must_attribute_to_may supplier_schema_csn={supplier_schema_csn}") |
| 779 |
log.debug(f"test_move_must_attribute_to_may consumer_schema_csn={consumer_schema_csn}") |
| 780 |
assert supplier_schema_csn == consumer_schema_csn |
| 781 |
|
| 782 |
# Check the error log of the supplier does not contain an error |
| 783 |
regex = re.compile(r"must not be overwritten \(set replication log for additional info\)") |
| 784 |
res = pattern_errorlog(topology_m1c1.ms["supplier1"].errorlog_file, regex) |
| 785 |
assert res is None |
| 786 |
|
| 787 |
# Check replication is working fine |
| 788 |
users = UserAccounts(topology_m1c1.ms["supplier1"], DEFAULT_SUFFIX) |
| 789 |
user = users.create_test_user(2000) |
| 790 |
user.add_many(('telexNumber', '12$us$21'), |
| 791 |
('postalCode', '54321'), |
| 792 |
('postalAddress', 'here'), |
| 793 |
('preferredLocale', 'en'), |
| 794 |
('objectclass', 'OCwithMayAttr')) |
| 795 |
|
| 796 |
loop = 0 |
| 797 |
ent = None |
| 798 |
while loop <= 10: |
| 799 |
try: |
| 800 |
ent = topology_m1c1.cs["consumer1"].getEntry(user.dn, ldap.SCOPE_BASE, "(objectclass=*)") |
| 801 |
break |
| 802 |
except ldap.NO_SUCH_OBJECT: |
| 803 |
time.sleep(1) |
| 804 |
loop += 1 |
| 805 |
if ent is None: |
| 806 |
assert False |
| 807 |
|
| 808 |
log.info('Testcase PASSED') |
| 809 |
|
| 810 |
|
| 811 |
if __name__ == '__main__': |
| 812 |
# Run isolated |
| 813 |
# -s for DEBUG mode |
| 814 |
CURRENT_FILE = os.path.realpath(__file__) |
| 815 |
pytest.main("-s %s" % CURRENT_FILE) |