| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2017 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 pytest |
| 10 |
from lib389.tasks import * |
| 11 |
from lib389.utils import * |
| 12 |
from test389.topologies import topology_m1 |
| 13 |
from lib389.tombstone import Tombstones |
| 14 |
from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES |
| 15 |
from lib389.replica import ReplicationManager |
| 16 |
from lib389._constants import (defaultProperties, DEFAULT_SUFFIX, ReplicaRole, |
| 17 |
REPLICAID_SUPPLIER_1, REPLICA_PRECISE_PURGING, REPLICA_PURGE_DELAY, |
| 18 |
REPLICA_PURGE_INTERVAL) |
| 19 |
|
| 20 |
pytestmark = pytest.mark.tier2 |
| 21 |
|
| 22 |
|
| 23 |
def test_precise_tombstone_purging(topology_m1): |
| 24 |
""" Test precise tombstone purging |
| 25 |
|
| 26 |
:id: adb86f50-ae76-4ed6-82b4-3cdc30ccab79 |
| 27 |
:setup: supplier1 instance |
| 28 |
:steps: |
| 29 |
1. Create and Delete entry to create a tombstone |
| 30 |
2. export ldif, edit, and import ldif |
| 31 |
3. Check tombstones do not contain nsTombstoneCSN |
| 32 |
4. Run fixup task, and verify tombstones now have nsTombstone CSN |
| 33 |
5. Configure tombstone purging |
| 34 |
6. Verify tombstones are purged |
| 35 |
:expectedresults: |
| 36 |
1. Success |
| 37 |
2. Success |
| 38 |
3. Success |
| 39 |
4. Success |
| 40 |
5. Success |
| 41 |
6. Success |
| 42 |
""" |
| 43 |
|
| 44 |
m1 = topology_m1.ms['supplier1'] |
| 45 |
m1_tasks = Tasks(m1) |
| 46 |
m1_tasks.log = log |
| 47 |
|
| 48 |
# Create tombstone entry |
| 49 |
users = UserAccounts(m1, DEFAULT_SUFFIX) |
| 50 |
user = users.create_test_user(uid=1001) |
| 51 |
user.delete() |
| 52 |
|
| 53 |
# Verify tombstone was created |
| 54 |
tombstones = Tombstones(m1, DEFAULT_SUFFIX) |
| 55 |
assert len(tombstones.list()) == 1 |
| 56 |
|
| 57 |
# Export db, strip nsTombstoneCSN, and import it |
| 58 |
ldif_file = "{}/export.ldif".format(m1.get_ldif_dir()) |
| 59 |
args = {EXPORT_REPL_INFO: True, |
| 60 |
TASK_WAIT: True} |
| 61 |
m1_tasks.exportLDIF(DEFAULT_SUFFIX, None, ldif_file, args) |
| 62 |
m1.restart() # harden test case |
| 63 |
|
| 64 |
# Strip LDIF of nsTombstoneCSN, get the LDIF lines, then create new ldif |
| 65 |
ldif = open(ldif_file, "r") |
| 66 |
lines = ldif.readlines() |
| 67 |
ldif.close() |
| 68 |
|
| 69 |
ldif = open(ldif_file, "w") |
| 70 |
for line in lines: |
| 71 |
if not line.lower().startswith('nstombstonecsn'): |
| 72 |
ldif.write(line) |
| 73 |
ldif.close() |
| 74 |
|
| 75 |
# import the new ldif file |
| 76 |
log.info('Import replication LDIF file...') |
| 77 |
args = {TASK_WAIT: True} |
| 78 |
m1_tasks.importLDIF(DEFAULT_SUFFIX, None, ldif_file, args) |
| 79 |
|
| 80 |
# Search for the tombstone again |
| 81 |
tombstones = Tombstones(m1, DEFAULT_SUFFIX) |
| 82 |
assert len(tombstones.list()) == 1 |
| 83 |
|
| 84 |
# |
| 85 |
# Part 3 - test fixup task using the strip option. |
| 86 |
# |
| 87 |
args = {TASK_WAIT: True, |
| 88 |
TASK_TOMB_STRIP: True} |
| 89 |
m1_tasks.fixupTombstones(DEFAULT_BENAME, args) |
| 90 |
|
| 91 |
# Search for tombstones with nsTombstoneCSN - better not find any |
| 92 |
for ts in tombstones.list(): |
| 93 |
assert not ts.present("nsTombstoneCSN") |
| 94 |
|
| 95 |
# Now run the fixup task |
| 96 |
args = {TASK_WAIT: True} |
| 97 |
m1_tasks.fixupTombstones(DEFAULT_BENAME, args) |
| 98 |
|
| 99 |
# Search for tombstones with nsTombstoneCSN - better find some |
| 100 |
tombstones = Tombstones(m1, DEFAULT_SUFFIX) |
| 101 |
assert len(tombstones.list()) == 1 |
| 102 |
|
| 103 |
# Verify that all tombstones have a nsTombstoneCSN |
| 104 |
for ts in tombstones.list(): |
| 105 |
log.info(f'Checking nsTombstoneCSN on tombstone {ts}') |
| 106 |
assert ts.present("nsTombstoneCSN") |
| 107 |
|
| 108 |
# |
| 109 |
# Part 4 - Test tombstone purging |
| 110 |
# |
| 111 |
args = {REPLICA_PRECISE_PURGING: b'on', |
| 112 |
REPLICA_PURGE_DELAY: b'5', |
| 113 |
REPLICA_PURGE_INTERVAL: b'5'} |
| 114 |
m1.replica.setProperties(DEFAULT_SUFFIX, None, None, args) |
| 115 |
|
| 116 |
# Wait for the interval to pass |
| 117 |
log.info('Wait for tombstone purge interval to pass...') |
| 118 |
time.sleep(6) |
| 119 |
|
| 120 |
# Add an entry to trigger replication |
| 121 |
users.create_test_user(uid=1002) |
| 122 |
|
| 123 |
# Wait for the interval to pass again |
| 124 |
log.info('Wait for tombstone purge interval to pass again...') |
| 125 |
time.sleep(6) |
| 126 |
|
| 127 |
# search for tombstones, there should be none |
| 128 |
tombstones = Tombstones(m1, DEFAULT_SUFFIX) |
| 129 |
assert len(tombstones.list()) == 0 |
| 130 |
|