From e56410ad4c03fb376adb6956817cfc1299b742d5 Mon Sep 17 00:00:00 2001 From: Sankar Ramalingam Date: Tue, 26 Sep 2017 18:34:16 +0530 Subject: [PATCH] Ticket #48085 - CI tests - replication state tests Description: Adding replication state tests to check attribute value and operational attributes after each operation. https://pagure.io/389-ds-base/issue/48085 Reviewed by: ? --- dirsrvtests/tests/suites/replication/state_test.py | 122 +++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 dirsrvtests/tests/suites/replication/state_test.py diff --git a/dirsrvtests/tests/suites/replication/state_test.py b/dirsrvtests/tests/suites/replication/state_test.py new file mode 100644 index 000000000..e41c6723b --- /dev/null +++ b/dirsrvtests/tests/suites/replication/state_test.py @@ -0,0 +1,122 @@ +# --- 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 --- +# +import os +import logging +import ldap +import pytest +from lib389.idm.user import UserAccounts, TEST_USER_PROPERTIES +from lib389.topologies import topology_m2 as topo +from lib389._constants import * + +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__) + + +def _perform_ldap_operation(topo, tuser, oper_type, user_attr, attr_value): + """Perform the required ldap operation for a given entry""" + + log.info('Perform required ldap operation for the given entry') + if 'attr-add' in oper_type: + tuser.add(user_attr, attr_value) + elif 'attr-replace' in oper_type: + tuser.set(user_attr, attr_value) + elif 'attr-delete' in oper_type: + tuser.remove(user_attr, attr_value) + + +def _check_user_oper_attrs_exist(topo, tuser, oper_type, user_attr, attr_value, exp_values, oper_attr): + """Check if list of attributes present for a given entry""" + + log.info('Check if list of attributes are present for a given entry') + attr_list = tuser.get_attr_vals(user_attr) + assert attr_list == exp_values + + log.info('Checking for vucsn, adcsn and vdcsn operational attributes') + entryid = topo.ms["master1"].search_ext(tuser.dn, ldap.SCOPE_BASE, + 'objectclass=*', ['nscpentrywsi']) + rtype, rdata, rmsgid = topo.ms["master1"].result2(entryid) + for entry in str(rdata).split(','): + if user_attr in entry: + if not 'delete' in oper_type: + assert any(attr in entry for attr in exp_values) and oper_attr in entry + else: + assert 'deleted' in entry and oper_attr in entry and attr_value in entry + + +@pytest.mark.parametrize("oper_type, user_attr, attr_value, exp_values, oper_attr", + [('attr-add', 'description', 'Test1user1', ['Test1user1'], 'vucsn'), + ('attr-add', 'description', 'Test1user2', ['Test1user1', 'Test1user2'], + 'vucsn'), + ('attr-add', 'description', 'Test1user3', ['Test1user1', 'Test1user2', + 'Test1user3'], 'vucsn'), + ('attr-replace', 'description', 'Test1user4', ['Test1user4'], 'adcsn'), + ('attr-delete', 'description', 'Test1user4', [], 'vdcsn')]) +def test_check_desc_attr_state(topo, oper_type, user_attr, attr_value, exp_values, oper_attr): + """Add/replace/delete user's description attribute and check if description attribute + added/modified/deleted and operational attributes vucsn, adcsn and vdcsn are present. + + :id: f25107fc-4e0d-4d03-a492-bea0acf65158 + :setup: Replication with two masters. + :steps: 1. Add user to Master1 without description attribute. + 2. Add description attribute to user. + 3. Check if only one description attribute exist. + 4. Check if operational attribute vucsn exist. + 5. Add second description attribute to user. + 6. Check if two description attributes exist. + 7. Check if operational attribute vucsn exist for each description attribute. + 8. Add second description attribute to user. + 9. Check if two description attributes exist. + 10. Check if operational attribute vucsn exist for each description attribute. + 11. Replace description attribute for the user. + 12. Check if only one description attribute exist. + 13. Check if operational attribute vucsn exist. + 14. Delete description attribute for the user. + 15. Check if no description attribute exist. + 16. Check if no operational attribute vucsn exist. + :expectedresults: + 1. Add user to M1 should PASS. + 2. Adding description attribute should PASS + 3. Only one description attribute should be present. + 4. Vucsn attribute value should be present. + 5. Adding a new description attribute should PASS + 6. Two description attribute should be present. + 7. Vucsn attribute value should be present. + 8. Adding a new description attribute should PASS + 9. Three description attribute should be present. + 10. Vucsn attribute value should be present. + 11. Replacing new description attribute should PASS + 12. Only one description attribute should be present. + 13. Adcsn attribute value should be present. + 14. Deleting description attribute should PASS + 15. No description attribute should be present. + 16. Vdcsn attribute value should be present. + """ + + test_entry = 'state1test' + log.info('Add users and perform required ldap operation for the given entry') + users = UserAccounts(topo.ms['master1'], DEFAULT_SUFFIX) + try: + tuser = users.get(test_entry) + except ldap.NO_SUCH_OBJECT: + TEST_USER_PROPERTIES.update(dict.fromkeys(['uid', 'cn'], test_entry)) + tuser = users.create(properties=TEST_USER_PROPERTIES) + _perform_ldap_operation(topo, tuser, oper_type, user_attr, attr_value) + _check_user_oper_attrs_exist(topo, tuser, oper_type, user_attr, attr_value, + exp_values, oper_attr) + + +if __name__ == '__main__': + # Run isolated + # -s for DEBUG mode + CURRENT_FILE = os.path.realpath(__file__) + pytest.main("-s {}".format(CURRENT_FILE)) -- 2.13.5