From 5b2622d5da910df972fcccadc41d2d8668f40000 Mon Sep 17 00:00:00 2001 From: Sankar Ramalingam Date: Thu, 14 Sep 2017 03:32:07 +0530 Subject: [PATCH] Ticket #48085 - CI tests - replication ruvstore Description: Adding ruvstore tests for replication. Test cases check if RUV details are backed up correctly and other test case checks, if memoryruv and databaseruv are synced. https://pagure.io/389-ds-base/issue/48085 Reviewed by: ? --- .../tests/suites/replication/ruvstore_test.py | 178 +++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100755 dirsrvtests/tests/suites/replication/ruvstore_test.py diff --git a/dirsrvtests/tests/suites/replication/ruvstore_test.py b/dirsrvtests/tests/suites/replication/ruvstore_test.py new file mode 100755 index 0000000..da46b1c --- /dev/null +++ b/dirsrvtests/tests/suites/replication/ruvstore_test.py @@ -0,0 +1,178 @@ +# --- BEGIN COPYRIGHT BLOCK --- +# Copyright (C) 2017 Red Hat, Inc. +# All rights reserved. +# +# License: GPL (version 3 or any later version). +# See LICENSE for details. +# --- END COPYRIGHT BLOCK --- +# +from lib389._constants import * +import os, ldap, logging, pytest +from lib389.replica import Replicas +from lib389.idm.user import UserAccounts +from lib389.topologies import topology_st as topo + +TEST_ENTRY_NAME = 'rep2lusr' +NEW_RDN_NAME = 'ruvusr' +DN_REPLICA = '{},cn="{}",{}'.format(RDN_REPLICA, DEFAULT_SUFFIX, DN_MAPPING_TREE) +RUV_LIST = ['dn: nsuniqueid=ffffffff', 'nsUniqueId: ffffffff', 'nsds50ruv: {replicageneration}', + 'nsds50ruv: {replica 3 ldap'] + +DEBUGGING = os.getenv('DEBUGGING', default=False) +if DEBUGGING: + logging.getLogger(__name__).setLevel(logging.DEBUG) +else: + logging.getLogger(__name__).setLevel(logging.INFO) +log = logging.getLogger(__name__) + + +@pytest.fixture(scope='module') +def configure_replica(topo, request): + """Configure replica for standalone instance""" + + log.info('Configure replica for standalone instance') + replicas = Replicas(topo.standalone) + replica = replicas.enable(suffix=DEFAULT_SUFFIX, role=ReplicaRole.MASTER, replicaID=3) + + def fin(): + log.info('Un-configure replica for standalone instance') + replicas.disable(DEFAULT_SUFFIX) + + request.addfinalizer(fin) + return replicas + + +def _compare_memoryruv_and_databaseruv(topo, operation_type): + """Compare the memoryruv and databaseruv for ldap operations""" + + log.info('Checking memory ruv for ldap-{} operation'.format(operation_type)) + entry = topo.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE, REPLICA_RUV_FILTER) + memory_ruv = entry[0].getValues('nsds50ruv') + log.info('Checking database ruv for ldap-{} operation'.format(operation_type)) + entry = topo.standalone.search_s(DN_REPLICA, ldap.SCOPE_BASE, 'objectClass=*', ['nsds50ruv']) + database_ruv = entry[0].getValues('nsds50ruv') + log.info('Memoryruv-{}, and databaseruv-{}'.format(memory_ruv, database_ruv)) + assert memory_ruv == database_ruv + + +def _perform_ldap_operations(topo): + """Add a test user, modify description, modrdn user and delete it""" + + log.info('Adding user {}'.format(TEST_ENTRY_NAME)) + users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) + user_properties = { + 'uid': TEST_ENTRY_NAME, + 'cn': TEST_ENTRY_NAME, + 'sn': TEST_ENTRY_NAME, + 'uidNumber': '1001', + 'gidNumber': '2001', + 'userpassword': PASSWORD, + 'description': 'userdesc', + 'homeDirectory': '/home/{}'.format(TEST_ENTRY_NAME)} + tuser = users.create(properties=user_properties) + tuser.replace('description', 'newdesc') + log.info('Modify RDN of user {}'.format(tuser.dn)) + try: + topo.standalone.modrdn_s(tuser.dn, 'uid={}'.format(NEW_RDN_NAME), 0) + except ldap.LDAPError as e: + log.fatal('Failed to modrdn entry {}'.format(tuser.dn)) + raise e + tuser = users.get(NEW_RDN_NAME) + log.info('Deleting user-{}'.format(tuser.dn)) + tuser.delete() + + +def test_ruv_entry_backup(topo, configure_replica): + """Check if db2ldif stores the RUV details in the backup file + + + :id: cbe2c473-8578-4caf-ac0a-841140e41e66 + :feature: Replication-ruvstore + :setup: Standalone instance with replica configured. + :steps: 1. Add user to server. + 2. Perform ldap modify, modrdn and delete operations. + 3. Stop the server and backup the database using db2ldif task. + 4. Start the server and check if correct RUV is stored in the backup file. + :expectedresults: + 1. Add user should PASS. + 2. Ldap operations should PASS. + 3. Database backup using db2ldif task should PASS. + 4. Backup file should contain the correct RUV details. + """ + + log.info('LDAP operations add, modify, modrdn and delete') + _perform_ldap_operations(topo) + + output_file = os.path.join(topo.standalone.get_ldif_dir(), '{}.ldif'.format(SERVERID_STANDALONE)) + log.info('Stopping the server instance to run db2ldif task') + topo.standalone.stop() + topo.standalone.db2ldif(bename=DEFAULT_BENAME, suffixes=[DEFAULT_SUFFIX], excludeSuffixes=[], encrypt=False, + repl_data=True, outputfile=output_file) + log.info('Starting the server after backup') + topo.standalone.start() + with open(output_file) as fh: + contents = fh.read() + for ruv in RUV_LIST: + if ruv in contents: + log.info('RUV entry is matching-{}'.format(ruv)) + else: + log.fatal('Failed to match RUV entries') + assert False + + +def test_memoryruv_sync_with_databaseruv(topo, configure_replica): + """Check if memory ruv and database ruv are synced + + :id: 5f38ac5f-6353-460d-bf60-49cafffda5b3 + :feature: Replication-ruvstore + :setup: Standalone instance with replica configured. + :steps: 1. Add user to server and compare memory ruv and database ruv. + 2. Modify description of user and compare memory ruv and database ruv. + 3. Modrdn of user and compare memory ruv and database ruv. + 4. Delete user and compare memory ruv and database ruv. + :expectedresults: + 1. For add user, the memory ruv and database ruv should be the same. + 2. For modify operation, the memory ruv and database ruv should be the same. + 3. For modrdn operation, the memory ruv and database ruv should be the same. + 4. For delete operation, the memory ruv and database ruv should be the same. + """ + + test_entry = 'test2ruv' + new_rdn = 'newrdn2usr' + log.info('Adding user {}'.format(test_entry)) + users = UserAccounts(topo.standalone, DEFAULT_SUFFIX) + user_properties = { + 'uid': test_entry, + 'cn': test_entry, + 'sn': test_entry, + 'uidNumber': '1001', + 'gidNumber': '2001', + 'userpassword': PASSWORD, + 'description': '{}-desc'.format(test_entry), + 'homeDirectory': '/home/{}'.format(test_entry)} + tuser = users.create(properties=user_properties) + _compare_memoryruv_and_databaseruv(topo, 'add') + + log.info('Modify user {} description'.format(test_entry)) + tuser.replace('description', 'newdesc') + _compare_memoryruv_and_databaseruv(topo, 'modify') + + log.info('Modify RDN of user {}'.format(tuser.dn)) + try: + topo.standalone.modrdn_s(tuser.dn, 'uid={}'.format(new_rdn), 0) + except ldap.LDAPError as e: + log.fatal('Failed to modrdn entry {}'.format(tuser.dn)) + raise e + _compare_memoryruv_and_databaseruv(topo, 'modrdn') + + tuser = users.get(new_rdn) + log.info('Delete user-{}'.format(tuser.dn)) + tuser.delete() + _compare_memoryruv_and_databaseruv(topo, 'delete') + + +if __name__ == '__main__': + # Run isolated + # -s for DEBUG mode + CURRENT_FILE = os.path.realpath(__file__) + pytest.main('-s {}'.format(CURRENT_FILE)) -- 2.7.5