source: trunk/server/common/patches/389-ds-indirect-cos.patch @ 2834

Last change on this file since 2834 was 2761, checked in by achernya, 8 years ago
Add a 389-ds-base patch for the CoS cache The version of 389-ds-base Scripts is currently running is sometimes duplciating entries on queries. We suspect that this is https://fedorahosted.org/389/ticket/47921 -- this change applies the suggested patch.
File size: 10.1 KB
  • new file dirsrvtests/tickets/ticket47921_test.py

    From a9cd2ffd227c19a458b27415dedaaf4a6b4778ec Mon Sep 17 00:00:00 2001
    From: Mark Reynolds <mreynolds@redhat.com>
    Date: Thu, 11 Jun 2015 12:28:07 -0400
    Subject: [PATCH] Ticket 47921 - indirect cos does not reflect changes in the
     cos attribute
    
    Bug Description:  Indirect cos results are incorrectly cached, so any changes
                      to entries that are indirect are not returned to the client.
    
    Fix Description:  Do not cache the vattr result if it came from a indirect cos
                      definition.
    
    https://fedorahosted.org/389/ticket/47921
    
    Reviewed by: ?
    ---
     dirsrvtests/tickets/ticket47921_test.py | 155 ++++++++++++++++++++++++++++++++
     ldap/servers/plugins/cos/cos_cache.c    |  26 ++++--
     2 files changed, 174 insertions(+), 7 deletions(-)
     create mode 100644 dirsrvtests/tickets/ticket47921_test.py
    
    diff --git a/dirsrvtests/tickets/ticket47921_test.py b/dirsrvtests/tickets/ticket47921_test.py
    new file mode 100644
    index 0000000..951d33b
    - +  
     1import os
     2import sys
     3import time
     4import ldap
     5import logging
     6import pytest
     7from lib389 import DirSrv, Entry, tools, tasks
     8from lib389.tools import DirSrvTools
     9from lib389._constants import *
     10from lib389.properties import *
     11from lib389.tasks import *
     12from lib389.utils import *
     13
     14logging.getLogger(__name__).setLevel(logging.DEBUG)
     15log = logging.getLogger(__name__)
     16
     17installation1_prefix = None
     18
     19
     20class TopologyStandalone(object):
     21    def __init__(self, standalone):
     22        standalone.open()
     23        self.standalone = standalone
     24
     25
     26@pytest.fixture(scope="module")
     27def topology(request):
     28    global installation1_prefix
     29    if installation1_prefix:
     30        args_instance[SER_DEPLOYED_DIR] = installation1_prefix
     31
     32    # Creating standalone instance ...
     33    standalone = DirSrv(verbose=False)
     34    args_instance[SER_HOST] = HOST_STANDALONE
     35    args_instance[SER_PORT] = PORT_STANDALONE
     36    args_instance[SER_SERVERID_PROP] = SERVERID_STANDALONE
     37    args_instance[SER_CREATION_SUFFIX] = DEFAULT_SUFFIX
     38    args_standalone = args_instance.copy()
     39    standalone.allocate(args_standalone)
     40    instance_standalone = standalone.exists()
     41    if instance_standalone:
     42        standalone.delete()
     43    standalone.create()
     44    standalone.open()
     45
     46    # Clear out the tmp dir
     47    standalone.clearTmpDir(__file__)
     48
     49    return TopologyStandalone(standalone)
     50
     51
     52def test_ticket47921(topology):
     53    '''
     54    Test that indirect cos reflects the current value of the indirect entry
     55    '''
     56
     57    INDIRECT_COS_DN = 'cn=cos definition,' + DEFAULT_SUFFIX
     58    MANAGER_DN = 'uid=my manager,ou=people,' + DEFAULT_SUFFIX
     59    USER_DN = 'uid=user,ou=people,' + DEFAULT_SUFFIX
     60
     61    # Add COS definition
     62    try:
     63        topology.standalone.add_s(Entry((INDIRECT_COS_DN,
     64            {'objectclass': 'top cosSuperDefinition cosIndirectDefinition ldapSubEntry'.split(),
     65             'cosIndirectSpecifier': 'manager',
     66             'cosAttribute': 'roomnumber'
     67            })))
     68    except ldap.LDAPError, e:
     69        log.fatal('Failed to add cos defintion, error: ' + e.message['desc'])
     70        assert False
     71
     72    # Add manager entry
     73    try:
     74        topology.standalone.add_s(Entry((MANAGER_DN,
     75            {'objectclass': 'top extensibleObject'.split(),
     76             'uid': 'my manager',
     77             'roomnumber': '1'
     78            })))
     79    except ldap.LDAPError, e:
     80        log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
     81        assert False
     82
     83    # Add user entry
     84    try:
     85        topology.standalone.add_s(Entry((USER_DN,
     86            {'objectclass': 'top person organizationalPerson inetorgperson'.split(),
     87             'sn': 'last',
     88             'cn': 'full',
     89             'givenname': 'mark',
     90             'uid': 'user',
     91             'manager': MANAGER_DN
     92            })))
     93    except ldap.LDAPError, e:
     94        log.fatal('Failed to add manager entry, error: ' + e.message['desc'])
     95        assert False
     96
     97    # Test COS is working
     98    try:
     99        entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
     100                                             "uid=user",
     101                                             ['roomnumber'])
     102        if entry:
     103            if entry[0].getValue('roomnumber') != '1':
     104                log.fatal('COS is not working.')
     105                assert False
     106        else:
     107            log.fatal('Failed to find user entry')
     108            assert False
     109    except ldap.LDAPError, e:
     110        log.error('Failed to search for user entry: ' + e.message['desc'])
     111        assert False
     112
     113    # Modify manager entry
     114    try:
     115        topology.standalone.modify_s(MANAGER_DN, [(ldap.MOD_REPLACE, 'roomnumber', '2')])
     116    except ldap.LDAPError, e:
     117        log.error('Failed to modify manager entry: ' + e.message['desc'])
     118        assert False
     119
     120    # Confirm COS is returning the new value
     121    try:
     122        entry = topology.standalone.search_s(DEFAULT_SUFFIX, ldap.SCOPE_SUBTREE,
     123                                             "uid=user",
     124                                             ['roomnumber'])
     125        if entry:
     126            if entry[0].getValue('roomnumber') != '2':
     127                log.fatal('COS is not working after manager update.')
     128                assert False
     129        else:
     130            log.fatal('Failed to find user entry')
     131            assert False
     132    except ldap.LDAPError, e:
     133        log.error('Failed to search for user entry: ' + e.message['desc'])
     134        assert False
     135
     136    log.info('Test complete')
     137
     138
     139def test_ticket47921_final(topology):
     140    topology.standalone.delete()
     141    log.info('Testcase PASSED')
     142
     143
     144def run_isolated():
     145    global installation1_prefix
     146    installation1_prefix = None
     147
     148    topo = topology(True)
     149    test_ticket47921(topo)
     150    test_ticket47921_final(topo)
     151
     152
     153if __name__ == '__main__':
     154    run_isolated()
     155
  • ldap/servers/plugins/cos/cos_cache.c

    diff --git a/ldap/servers/plugins/cos/cos_cache.c b/ldap/servers/plugins/cos/cos_cache.c
    index 7d8e877..fa2b6b5 100644
    a b void cos_cache_backend_state_change(void *handle, char *be_name, 
    284284static int cos_cache_vattr_get(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_ValueSet** results,int *type_name_disposition, char** actual_type_name, int flags, int *free_flags, void *hint);
    285285static int cos_cache_vattr_compare(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_Value *test_this, int* result, int flags, void *hint);
    286286static int cos_cache_vattr_types(vattr_sp_handle *handle,Slapi_Entry *e,vattr_type_list_context *type_context,int flags);
    287 static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context, Slapi_Entry *e, char *type, Slapi_ValueSet **out_attr, Slapi_Value *test_this, int *result, int *ops);
     287static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context, Slapi_Entry *e, char *type, Slapi_ValueSet **out_attr, Slapi_Value *test_this, int *result, int *ops, int *indirect_cos);
    288288
    289289/*
    290290        compares s2 to s1 starting from end of string until the beginning of either
    static int cos_cache_attrval_exists(cosAttrValue *pAttrs, const char *val) 
    20962096
    20972097static int cos_cache_vattr_get(vattr_sp_handle *handle, vattr_context *c, Slapi_Entry *e, char *type, Slapi_ValueSet** results,int *type_name_disposition, char** actual_type_name, int flags, int *free_flags, void *hint)
    20982098{
    2099         int ret = -1;
    21002099        cos_cache *pCache = 0;
     2100        int indirect_cos = 0;
     2101        int ret = -1;
    21012102
    21022103        LDAPDebug( LDAP_DEBUG_TRACE, "--> cos_cache_vattr_get\n",0,0,0);
    21032104       
    static int cos_cache_vattr_get(vattr_sp_handle *handle, vattr_context *c, Slapi_ 
    21082109                goto bail;
    21092110        }
    21102111
    2111         ret = cos_cache_query_attr(pCache, c, e, type, results, NULL, NULL, NULL);
     2112        ret = cos_cache_query_attr(pCache, c, e, type, results, NULL, NULL, NULL, &indirect_cos);
    21122113        if(ret == 0)
    21132114        {
    2114         *free_flags = SLAPI_VIRTUALATTRS_RETURNED_COPIES | SLAPI_VIRTUALATTRS_VALUES_CACHEABLE;
     2115                if(indirect_cos){
     2116                        /* we can't cache indirect cos */
     2117                        *free_flags = SLAPI_VIRTUALATTRS_RETURNED_COPIES;
     2118                } else {
     2119                        *free_flags = SLAPI_VIRTUALATTRS_RETURNED_COPIES | SLAPI_VIRTUALATTRS_VALUES_CACHEABLE;
     2120                }
    21152121        *actual_type_name = slapi_ch_strdup(type);
    21162122                *type_name_disposition = SLAPI_VIRTUALATTRS_TYPE_NAME_MATCHED_EXACTLY_OR_ALIAS;
    21172123        }
    static int cos_cache_vattr_compare(vattr_sp_handle *handle, vattr_context *c, Sl 
    21382144                goto bail;
    21392145        }
    21402146
    2141         ret = cos_cache_query_attr(pCache, c, e, type, NULL, test_this, result, NULL);
     2147        ret = cos_cache_query_attr(pCache, c, e, type, NULL, test_this, result, NULL, NULL);
    21422148
    21432149        cos_cache_release(pCache);
    21442150
    static int cos_cache_vattr_types(vattr_sp_handle *handle,Slapi_Entry *e, 
    21792185                        lastattr = pCache->ppAttrIndex[index]->pAttrName;
    21802186
    21812187                        if(1 == cos_cache_query_attr(pCache, NULL, e, lastattr, NULL, NULL,
    2182                                                                                          NULL, &props))
     2188                                                                                         NULL, &props, NULL))
    21832189                        {
    21842190                                /* entry contains this attr */
    21852191                                vattr_type_thang thang = {0};
    bail: 
    22232229        overriding and allow the DS logic to pick it up by denying knowledge
    22242230        of attribute
    22252231*/
    2226 static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context, Slapi_Entry *e, char *type, Slapi_ValueSet **out_attr, Slapi_Value *test_this, int *result, int *props)
     2232static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context,
     2233                                Slapi_Entry *e, char *type, Slapi_ValueSet **out_attr,
     2234                                Slapi_Value *test_this, int *result, int *props,
     2235                                int *indirect_cos)
    22272236{
    22282237        int ret = -1;
    22292238        cosCache *pCache = (cosCache*)ptheCache;
    static int cos_cache_query_attr(cos_cache *ptheCache, vattr_context *context, Sl 
    24202429                                                                if (cos_cache_follow_pointer( context, (char*)slapi_value_get_string(indirectdn),
    24212430                                                                        type, &tmp_vals, test_this, result, pointer_flags) == 0)
    24222431                                                                {
     2432                                                                        if(indirect_cos){
     2433                                                                                *indirect_cos = 1;
     2434                                                                        }
    24232435                                                                        hit = 1;
    24242436                                                                        /* If the caller requested values, set them.  We need
    24252437                                                                         * to append values when we follow multiple pointers DNs. */
Note: See TracBrowser for help on using the repository browser.