| 1 |
# --- BEGIN COPYRIGHT BLOCK --- |
| 2 |
# Copyright (C) 2016 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 Dec 09, 2014 |
| 11 |
|
| 12 |
@author: mreynolds |
| 13 |
''' |
| 14 |
import logging |
| 15 |
|
| 16 |
import ldap.sasl |
| 17 |
import pytest |
| 18 |
from lib389.tasks import * |
| 19 |
from lib389.replica import ReplicationManager |
| 20 |
from lib389.config import LDBMConfig |
| 21 |
from lib389._constants import * |
| 22 |
from test389.topologies import topology_m2 |
| 23 |
from ..plugins import acceptance_test |
| 24 |
from . import stress_tests |
| 25 |
|
| 26 |
pytestmark = pytest.mark.tier1 |
| 27 |
|
| 28 |
log = logging.getLogger(__name__) |
| 29 |
|
| 30 |
|
| 31 |
def check_replicas(topology_m2): |
| 32 |
"""Check that replication is in sync and working""" |
| 33 |
|
| 34 |
m1 = topology_m2.ms["supplier1"] |
| 35 |
m2 = topology_m2.ms["supplier2"] |
| 36 |
|
| 37 |
log.info('Checking if replication is in sync...') |
| 38 |
repl = ReplicationManager(DEFAULT_SUFFIX) |
| 39 |
repl.test_replication_topology(topology_m2) |
| 40 |
# |
| 41 |
# Verify the databases are identical. There should not be any "user, entry, employee" entries |
| 42 |
# |
| 43 |
log.info('Checking if the data is the same between the replicas...') |
| 44 |
|
| 45 |
# Check the supplier |
| 46 |
try: |
| 47 |
entries = m1.search_s(DEFAULT_SUFFIX, |
| 48 |
ldap.SCOPE_SUBTREE, |
| 49 |
"(|(uid=person*)(uid=entry*)(uid=employee*))") |
| 50 |
if len(entries) > 0: |
| 51 |
log.error('Supplier database has incorrect data set!\n') |
| 52 |
assert False |
| 53 |
except ldap.LDAPError as e: |
| 54 |
log.fatal('Unable to search db on supplier: ' + e.message['desc']) |
| 55 |
assert False |
| 56 |
|
| 57 |
# Check the consumer |
| 58 |
try: |
| 59 |
entries = m2.search_s(DEFAULT_SUFFIX, |
| 60 |
ldap.SCOPE_SUBTREE, |
| 61 |
"(|(uid=person*)(uid=entry*)(uid=employee*))") |
| 62 |
if len(entries) > 0: |
| 63 |
log.error('Consumer database in not consistent with supplier database') |
| 64 |
assert False |
| 65 |
except ldap.LDAPError as e: |
| 66 |
log.fatal('Unable to search db on consumer: ' + e.message['desc']) |
| 67 |
assert False |
| 68 |
|
| 69 |
log.info('Data is consistent across the replicas.\n') |
| 70 |
|
| 71 |
#unstable or unstatus tests, skipped for now |
| 72 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 73 |
def test_acceptance(topology_m2): |
| 74 |
"""Exercise each plugin and its main features, while |
| 75 |
changing the configuration without restarting the server. |
| 76 |
|
| 77 |
:id: 96136538-0151-4b09-9933-0e0cbf2c786c |
| 78 |
:setup: 2 Supplier Instances |
| 79 |
:steps: |
| 80 |
1. Pause all replication |
| 81 |
2. Set nsslapd-dynamic-plugins to on |
| 82 |
3. Try to update LDBM config entry |
| 83 |
4. Go through all plugin basic functionality |
| 84 |
5. Resume replication |
| 85 |
6. Go through all plugin basic functionality again |
| 86 |
7. Check that data in sync and replication is working |
| 87 |
:expectedresults: |
| 88 |
1. Success |
| 89 |
2. Success |
| 90 |
3. Success |
| 91 |
4. Success |
| 92 |
5. Success |
| 93 |
6. Success |
| 94 |
7. Success |
| 95 |
""" |
| 96 |
|
| 97 |
m1 = topology_m2.ms["supplier1"] |
| 98 |
msg = ' (no replication)' |
| 99 |
replication_run = False |
| 100 |
|
| 101 |
# First part of the test should be without replication |
| 102 |
topology_m2.pause_all_replicas() |
| 103 |
|
| 104 |
# First enable dynamic plugins |
| 105 |
m1.config.replace('nsslapd-dynamic-plugins', 'on') |
| 106 |
|
| 107 |
# Test that critical plugins can be updated even though the change might not be applied |
| 108 |
ldbm_config = LDBMConfig(m1) |
| 109 |
ldbm_config.replace('description', 'test') |
| 110 |
|
| 111 |
while True: |
| 112 |
# First run the tests with replication disabled, then rerun them with replication set up |
| 113 |
|
| 114 |
############################################################################ |
| 115 |
# Test plugin functionality |
| 116 |
############################################################################ |
| 117 |
|
| 118 |
log.info('####################################################################') |
| 119 |
log.info('Testing Dynamic Plugins Functionality' + msg + '...') |
| 120 |
log.info('####################################################################\n') |
| 121 |
|
| 122 |
acceptance_test.check_all_plugins(topology_m2) |
| 123 |
|
| 124 |
log.info('####################################################################') |
| 125 |
log.info('Successfully Tested Dynamic Plugins Functionality' + msg + '.') |
| 126 |
log.info('####################################################################\n') |
| 127 |
|
| 128 |
if replication_run: |
| 129 |
# We're done. |
| 130 |
break |
| 131 |
else: |
| 132 |
log.info('Resume replication and run everything one more time') |
| 133 |
topology_m2.resume_all_replicas() |
| 134 |
|
| 135 |
replication_run = True |
| 136 |
msg = ' (replication enabled)' |
| 137 |
time.sleep(1) |
| 138 |
|
| 139 |
############################################################################ |
| 140 |
# Check replication, and data are in sync |
| 141 |
############################################################################ |
| 142 |
check_replicas(topology_m2) |
| 143 |
|
| 144 |
#unstable or unstatus tests, skipped for now |
| 145 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 146 |
def test_memory_corruption(topology_m2): |
| 147 |
"""Check the plugins for memory corruption issues while |
| 148 |
dynamic plugins option is enabled |
| 149 |
|
| 150 |
:id: 96136538-0151-4b09-9933-0e0cbf2c7862 |
| 151 |
:setup: 2 Supplier Instances |
| 152 |
:steps: |
| 153 |
1. Pause all replication |
| 154 |
2. Set nsslapd-dynamic-plugins to on |
| 155 |
3. Try to update LDBM config entry |
| 156 |
4. Restart the plugin many times in a linked list fashion |
| 157 |
restarting previous and preprevious plugins in the list of all plugins |
| 158 |
5. Run the functional test |
| 159 |
6. Repeat 4 and 5 steps for all plugins |
| 160 |
7. Resume replication |
| 161 |
8. Go through 4-6 steps once more |
| 162 |
9. Check that data in sync and replication is working |
| 163 |
:expectedresults: |
| 164 |
1. Success |
| 165 |
2. Success |
| 166 |
3. Success |
| 167 |
4. Success |
| 168 |
5. Success |
| 169 |
6. Success |
| 170 |
7. Success |
| 171 |
8. Success |
| 172 |
9. Success |
| 173 |
""" |
| 174 |
|
| 175 |
|
| 176 |
m1 = topology_m2.ms["supplier1"] |
| 177 |
msg = ' (no replication)' |
| 178 |
replication_run = False |
| 179 |
|
| 180 |
# First part of the test should be without replication |
| 181 |
topology_m2.pause_all_replicas() |
| 182 |
|
| 183 |
# First enable dynamic plugins |
| 184 |
m1.config.replace('nsslapd-dynamic-plugins', 'on') |
| 185 |
|
| 186 |
# Test that critical plugins can be updated even though the change might not be applied |
| 187 |
ldbm_config = LDBMConfig(m1) |
| 188 |
ldbm_config.replace('description', 'test') |
| 189 |
|
| 190 |
while True: |
| 191 |
# First run the tests with replication disabled, then rerun them with replication set up |
| 192 |
|
| 193 |
############################################################################ |
| 194 |
# Test the stability by exercising the internal lists, callabcks, and task handlers |
| 195 |
############################################################################ |
| 196 |
|
| 197 |
log.info('####################################################################') |
| 198 |
log.info('Testing Dynamic Plugins for Memory Corruption' + msg + '...') |
| 199 |
log.info('####################################################################\n') |
| 200 |
prev_plugin_test = None |
| 201 |
prev_prev_plugin_test = None |
| 202 |
|
| 203 |
for plugin_test in acceptance_test.func_tests: |
| 204 |
# |
| 205 |
# Restart the plugin several times (and prev plugins) - work that linked list |
| 206 |
# |
| 207 |
plugin_test(topology_m2, "restart") |
| 208 |
|
| 209 |
if prev_prev_plugin_test: |
| 210 |
prev_prev_plugin_test(topology_m2, "restart") |
| 211 |
|
| 212 |
plugin_test(topology_m2, "restart") |
| 213 |
|
| 214 |
if prev_plugin_test: |
| 215 |
prev_plugin_test(topology_m2, "restart") |
| 216 |
|
| 217 |
plugin_test(topology_m2, "restart") |
| 218 |
|
| 219 |
# Now run the functional test |
| 220 |
plugin_test(topology_m2, "dynamic") |
| 221 |
|
| 222 |
# Set the previous tests |
| 223 |
if prev_plugin_test: |
| 224 |
prev_prev_plugin_test = prev_plugin_test |
| 225 |
prev_plugin_test = plugin_test |
| 226 |
|
| 227 |
log.info('####################################################################') |
| 228 |
log.info('Successfully Tested Dynamic Plugins for Memory Corruption' + msg + '.') |
| 229 |
log.info('####################################################################\n') |
| 230 |
|
| 231 |
if replication_run: |
| 232 |
# We're done. |
| 233 |
break |
| 234 |
else: |
| 235 |
log.info('Resume replication and run everything one more time') |
| 236 |
topology_m2.resume_all_replicas() |
| 237 |
|
| 238 |
replication_run = True |
| 239 |
msg = ' (replication enabled)' |
| 240 |
time.sleep(1) |
| 241 |
|
| 242 |
############################################################################ |
| 243 |
# Check replication, and data are in sync |
| 244 |
############################################################################ |
| 245 |
check_replicas(topology_m2) |
| 246 |
|
| 247 |
#unstable or unstatus tests, skipped for now |
| 248 |
@pytest.mark.flaky(max_runs=2, min_passes=1) |
| 249 |
@pytest.mark.tier2 |
| 250 |
def test_stress(topology_m2): |
| 251 |
"""Test plugins while under a big load. Perform the test 5 times |
| 252 |
|
| 253 |
:id: 96136538-0151-4b09-9933-0e0cbf2c7863 |
| 254 |
:setup: 2 Supplier Instances |
| 255 |
:steps: |
| 256 |
1. Pause all replication |
| 257 |
2. Set nsslapd-dynamic-plugins to on |
| 258 |
3. Try to update LDBM config entry |
| 259 |
4. Do one run through all tests |
| 260 |
5. Enable Referential integrity and MemberOf plugins |
| 261 |
6. Launch three new threads to add a bunch of users |
| 262 |
7. While we are adding users restart the MemberOf and |
| 263 |
Linked Attributes plugins many times |
| 264 |
8. Wait for the 'adding' threads to complete |
| 265 |
9. Now launch three threads to delete the users |
| 266 |
10. Restart both the MemberOf, Referential integrity and |
| 267 |
Linked Attributes plugins during these deletes |
| 268 |
11. Wait for the 'deleting' threads to complete |
| 269 |
12. Now make sure both the MemberOf and Referential integrity plugins still work correctly |
| 270 |
13. Cleanup the stress tests (delete the group entry) |
| 271 |
14. Perform 4-13 steps five times |
| 272 |
15. Resume replication |
| 273 |
16. Go through 4-14 steps once more |
| 274 |
17. Check that data in sync and replication is working |
| 275 |
:expectedresults: |
| 276 |
1. Success |
| 277 |
2. Success |
| 278 |
3. Success |
| 279 |
4. Success |
| 280 |
5. Success |
| 281 |
6. Success |
| 282 |
7. Success |
| 283 |
8. Success |
| 284 |
9. Success |
| 285 |
10. Success |
| 286 |
11. Success |
| 287 |
12. Success |
| 288 |
13. Success |
| 289 |
14. Success |
| 290 |
15. Success |
| 291 |
16. Success |
| 292 |
17. Success |
| 293 |
""" |
| 294 |
|
| 295 |
m1 = topology_m2.ms["supplier1"] |
| 296 |
msg = ' (no replication)' |
| 297 |
replication_run = False |
| 298 |
stress_max_runs = 5 |
| 299 |
|
| 300 |
# First part of the test should be without replication |
| 301 |
topology_m2.pause_all_replicas() |
| 302 |
|
| 303 |
# First enable dynamic plugins |
| 304 |
m1.config.replace('nsslapd-dynamic-plugins', 'on') |
| 305 |
|
| 306 |
# Test that critical plugins can be updated even though the change might not be applied |
| 307 |
ldbm_config = LDBMConfig(m1) |
| 308 |
ldbm_config.replace('description', 'test') |
| 309 |
|
| 310 |
while True: |
| 311 |
# First run the tests with replication disabled, then rerun them with replication set up |
| 312 |
|
| 313 |
log.info('Do one run through all tests ' + msg + '...') |
| 314 |
acceptance_test.check_all_plugins(topology_m2) |
| 315 |
|
| 316 |
log.info('####################################################################') |
| 317 |
log.info('Stressing Dynamic Plugins' + msg + '...') |
| 318 |
log.info('####################################################################\n') |
| 319 |
|
| 320 |
stress_tests.configureMO(m1) |
| 321 |
stress_tests.configureRI(m1) |
| 322 |
|
| 323 |
stress_count = 0 |
| 324 |
while stress_count < stress_max_runs: |
| 325 |
log.info('####################################################################') |
| 326 |
log.info('Running stress test' + msg + '. Run (%d/%d)...' % (stress_count + 1, stress_max_runs)) |
| 327 |
log.info('####################################################################\n') |
| 328 |
|
| 329 |
# Launch three new threads to add a bunch of users |
| 330 |
add_users = stress_tests.AddUsers(m1, 'employee', True) |
| 331 |
add_users.start() |
| 332 |
add_users2 = stress_tests.AddUsers(m1, 'entry', True) |
| 333 |
add_users2.start() |
| 334 |
add_users3 = stress_tests.AddUsers(m1, 'person', True) |
| 335 |
add_users3.start() |
| 336 |
time.sleep(1) |
| 337 |
|
| 338 |
# While we are adding users restart the MO plugin and an idle plugin |
| 339 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 340 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 341 |
time.sleep(1) |
| 342 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 343 |
time.sleep(1) |
| 344 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 345 |
m1.plugins.disable(name=PLUGIN_LINKED_ATTRS) |
| 346 |
m1.plugins.enable(name=PLUGIN_LINKED_ATTRS) |
| 347 |
time.sleep(1) |
| 348 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 349 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 350 |
time.sleep(2) |
| 351 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 352 |
time.sleep(1) |
| 353 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 354 |
m1.plugins.disable(name=PLUGIN_LINKED_ATTRS) |
| 355 |
m1.plugins.enable(name=PLUGIN_LINKED_ATTRS) |
| 356 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 357 |
time.sleep(1) |
| 358 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 359 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 360 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 361 |
|
| 362 |
# Wait for the 'adding' threads to complete |
| 363 |
add_users.join() |
| 364 |
add_users2.join() |
| 365 |
add_users3.join() |
| 366 |
|
| 367 |
# Now launch three threads to delete the users |
| 368 |
del_users = stress_tests.DelUsers(m1, 'employee') |
| 369 |
del_users.start() |
| 370 |
del_users2 = stress_tests.DelUsers(m1, 'entry') |
| 371 |
del_users2.start() |
| 372 |
del_users3 = stress_tests.DelUsers(m1, 'person') |
| 373 |
del_users3.start() |
| 374 |
time.sleep(1) |
| 375 |
|
| 376 |
# Restart both the MO, RI plugins during these deletes, and an idle plugin |
| 377 |
m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY) |
| 378 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 379 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 380 |
m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY) |
| 381 |
time.sleep(1) |
| 382 |
m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY) |
| 383 |
time.sleep(1) |
| 384 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 385 |
time.sleep(1) |
| 386 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 387 |
time.sleep(1) |
| 388 |
m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY) |
| 389 |
m1.plugins.disable(name=PLUGIN_LINKED_ATTRS) |
| 390 |
m1.plugins.enable(name=PLUGIN_LINKED_ATTRS) |
| 391 |
m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY) |
| 392 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 393 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 394 |
m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY) |
| 395 |
time.sleep(2) |
| 396 |
m1.plugins.disable(name=PLUGIN_REFER_INTEGRITY) |
| 397 |
time.sleep(1) |
| 398 |
m1.plugins.disable(name=PLUGIN_MEMBER_OF) |
| 399 |
time.sleep(1) |
| 400 |
m1.plugins.enable(name=PLUGIN_MEMBER_OF) |
| 401 |
time.sleep(1) |
| 402 |
m1.plugins.enable(name=PLUGIN_REFER_INTEGRITY) |
| 403 |
m1.plugins.disable(name=PLUGIN_LINKED_ATTRS) |
| 404 |
m1.plugins.enable(name=PLUGIN_LINKED_ATTRS) |
| 405 |
|
| 406 |
# Wait for the 'deleting' threads to complete |
| 407 |
del_users.join() |
| 408 |
del_users2.join() |
| 409 |
del_users3.join() |
| 410 |
|
| 411 |
# Now make sure both the MO and RI plugins still work correctly |
| 412 |
acceptance_test.func_tests[8](topology_m2, "dynamic") # RI plugin |
| 413 |
acceptance_test.func_tests[5](topology_m2, "dynamic") # MO plugin |
| 414 |
|
| 415 |
# Cleanup the stress tests |
| 416 |
stress_tests.cleanup(m1) |
| 417 |
|
| 418 |
stress_count += 1 |
| 419 |
log.info('####################################################################') |
| 420 |
log.info('Successfully Stressed Dynamic Plugins' + msg + |
| 421 |
'. Completed (%d/%d)' % (stress_count, stress_max_runs)) |
| 422 |
log.info('####################################################################\n') |
| 423 |
|
| 424 |
if replication_run: |
| 425 |
# We're done. |
| 426 |
break |
| 427 |
else: |
| 428 |
log.info('Resume replication and run everything one more time') |
| 429 |
topology_m2.resume_all_replicas() |
| 430 |
|
| 431 |
replication_run = True |
| 432 |
msg = ' (replication enabled)' |
| 433 |
time.sleep(1) |
| 434 |
|
| 435 |
############################################################################ |
| 436 |
# Check replication, and data are in sync |
| 437 |
############################################################################ |
| 438 |
check_replicas(topology_m2) |
| 439 |
|
| 440 |
|
| 441 |
if __name__ == '__main__': |
| 442 |
# Run isolated |
| 443 |
# -s for DEBUG mode |
| 444 |
CURRENT_FILE = os.path.realpath(__file__) |
| 445 |
pytest.main("-s %s" % CURRENT_FILE) |