| 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 |
import ldap |
| 13 |
from lib389._constants import RETROCL_SUFFIX, DEFAULT_SUFFIX |
| 14 |
from test389.topologies import topology_st as topo |
| 15 |
from test389.topologies import topology_m1 |
| 16 |
from lib389.plugins import RetroChangelogPlugin |
| 17 |
from lib389.idm.user import UserAccounts |
| 18 |
from lib389._mapped_object import DSLdapObjects |
| 19 |
from lib389.properties import TASK_WAIT, INDEX_TYPE |
| 20 |
from lib389.index import Indexes |
| 21 |
|
| 22 |
|
| 23 |
log = logging.getLogger(__name__) |
| 24 |
|
| 25 |
TEST_REPL_DN = "cn=test_repl,{}".format(DEFAULT_SUFFIX) |
| 26 |
ENTRY_DN = "cn=test_entry,{}".format(DEFAULT_SUFFIX) |
| 27 |
|
| 28 |
OTHER_NAME = 'other_entry' |
| 29 |
MAX_OTHERS = 100 |
| 30 |
|
| 31 |
ATTRIBUTES = ['street', 'countryName', 'description', 'postalAddress', 'postalCode', 'title', 'l', 'roomNumber'] |
| 32 |
|
| 33 |
|
| 34 |
def test_indexing_is_online(topo): |
| 35 |
"""Test that the changenmumber index is online right after enabling the plugin |
| 36 |
|
| 37 |
:id: 16f4c001-9e0c-4448-a2b3-08ac1e85d40f |
| 38 |
:setup: Standalone Instance |
| 39 |
:steps: |
| 40 |
1. Enable retro cl |
| 41 |
2. Perform some updates |
| 42 |
3. Search for "(changenumber>=-1)", and it is not partially unindexed |
| 43 |
4. Search for "(&(changenumber>=-1)(targetuniqueid=*))", and it is not partially unindexed |
| 44 |
:expectedresults: |
| 45 |
1. Success |
| 46 |
2. Success |
| 47 |
3. Success |
| 48 |
4. Success |
| 49 |
""" |
| 50 |
|
| 51 |
# Enable plugin |
| 52 |
topo.standalone.config.set('nsslapd-accesslog-logbuffering', 'off') |
| 53 |
plugin = RetroChangelogPlugin(topo.standalone) |
| 54 |
plugin.enable() |
| 55 |
topo.standalone.restart() |
| 56 |
|
| 57 |
# Do a bunch of updates |
| 58 |
users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) |
| 59 |
user_entry = users.create(properties={ |
| 60 |
'sn': '1', |
| 61 |
'cn': 'user 1', |
| 62 |
'uid': 'user1', |
| 63 |
'uidNumber': '11', |
| 64 |
'gidNumber': '111', |
| 65 |
'givenname': 'user1', |
| 66 |
'homePhone': '0861234567', |
| 67 |
'carLicense': '131D16674', |
| 68 |
'mail': '[email protected]', |
| 69 |
'homeDirectory': '/home' |
| 70 |
}) |
| 71 |
for count in range(0, 10): |
| 72 |
user_entry.replace('mail', f'test{count}@test.com') |
| 73 |
|
| 74 |
# Search the retro cl, and check for error messages |
| 75 |
filter_simple = '(changenumber>=-1)' |
| 76 |
filter_compound = '(&(changenumber>=-1)(targetuniqueid=*))' |
| 77 |
retro_changelog_suffix = DSLdapObjects(topo.standalone, basedn=RETROCL_SUFFIX) |
| 78 |
retro_changelog_suffix.filter(filter_simple) |
| 79 |
assert not topo.standalone.searchAccessLog('Partially Unindexed Filter') |
| 80 |
|
| 81 |
# Search the retro cl again with compound filter |
| 82 |
retro_changelog_suffix.filter(filter_compound) |
| 83 |
assert not topo.standalone.searchAccessLog('Partially Unindexed Filter') |
| 84 |
|
| 85 |
|
| 86 |
def test_reindexing_retrochangelog(topology_m1): |
| 87 |
""" Test that the retro changelog can be successfully reindexed |
| 88 |
|
| 89 |
:id: 26d8df59-0886-4098-8d2c-b9337accc908 |
| 90 |
:setup: Supplier instance |
| 91 |
:steps: |
| 92 |
1. Enable retro changelog and restart instance |
| 93 |
2. Create test entries |
| 94 |
3. Create index |
| 95 |
4. Reindex retro changelog |
| 96 |
5. Verify indexed search |
| 97 |
6. Clean up test entries |
| 98 |
:expectedresults: |
| 99 |
1. Success |
| 100 |
2. Success |
| 101 |
3. Success |
| 102 |
4. Success |
| 103 |
5. Success |
| 104 |
6. Success |
| 105 |
""" |
| 106 |
|
| 107 |
log.info('Enable retro changelog and restart instance') |
| 108 |
retrocl = RetroChangelogPlugin(topology_m1.ms["supplier1"]) |
| 109 |
retrocl.enable() |
| 110 |
topology_m1.ms["supplier1"].restart() |
| 111 |
|
| 112 |
log.info('Creating test entries') |
| 113 |
users = UserAccounts(topology_m1.ms["supplier1"], DEFAULT_SUFFIX) |
| 114 |
for count in range(MAX_OTHERS): |
| 115 |
name = "{}{}".format(OTHER_NAME, count) |
| 116 |
users.create(properties={ |
| 117 |
'sn': name, |
| 118 |
'cn': name, |
| 119 |
'uid': name, |
| 120 |
'uidNumber': '1{}'.format(count), |
| 121 |
'gidNumber': '11{}'.format(count), |
| 122 |
'homeDirectory': '/home/{}'.format(name) |
| 123 |
}) |
| 124 |
|
| 125 |
log.info('Test entries created') |
| 126 |
|
| 127 |
try: |
| 128 |
log.info('Verify number of created entries') |
| 129 |
check_entries = users.list() |
| 130 |
assert len(check_entries) == MAX_OTHERS |
| 131 |
|
| 132 |
log.info('Create index') |
| 133 |
indexes = Indexes(topology_m1.ms["supplier1"]) |
| 134 |
for attr in ATTRIBUTES: |
| 135 |
indexes.create(properties={ |
| 136 |
'cn': attr, |
| 137 |
'nsSystemIndex': 'false', |
| 138 |
'nsIndexType': 'eq' |
| 139 |
}) |
| 140 |
topology_m1.ms["supplier1"].restart() |
| 141 |
|
| 142 |
log.info('Reindex retro changelog') |
| 143 |
args = {TASK_WAIT: True} |
| 144 |
for attr in ATTRIBUTES: |
| 145 |
rc = topology_m1.ms["supplier1"].tasks.reindex(suffix=RETROCL_SUFFIX, attrname=attr, args=args) |
| 146 |
log.info('Verify reindexing task was successful for attribute {}'.format(attr)) |
| 147 |
assert rc == 0 |
| 148 |
|
| 149 |
log.info('Check reindexed search') |
| 150 |
for attr in ATTRIBUTES: |
| 151 |
ents = topology_m1.ms["supplier1"].search_s(RETROCL_SUFFIX, ldap.SCOPE_SUBTREE, "({}=hello)".format(attr), |
| 152 |
escapehatch='i am sure') |
| 153 |
assert len(ents) == 0 |
| 154 |
finally: |
| 155 |
log.info('Clean up the test entries') |
| 156 |
entries = users.list() |
| 157 |
for entry in entries: |
| 158 |
entry.delete() |
| 159 |
|
| 160 |
|
| 161 |
if __name__ == '__main__': |
| 162 |
# Run isolated |
| 163 |
# -s for DEBUG mode |
| 164 |
CURRENT_FILE = os.path.realpath(__file__) |
| 165 |
pytest.main(["-s", CURRENT_FILE]) |