zrhoffman / rpms / 389-ds-base

Forked from rpms/389-ds-base 3 years ago
Clone

Blame SOURCES/0075-Ticket-49460-replica_write_ruv-log-a-failure-even-wh.patch

b045b9
From a0c4a8d69735cb37e5b52b195ec632ce6d1f028f Mon Sep 17 00:00:00 2001
b045b9
From: Thierry Bordaz <tbordaz@redhat.com>
b045b9
Date: Tue, 21 Nov 2017 17:23:29 +0100
b045b9
Subject: [PATCH] Ticket 49460 - replica_write_ruv log a failure even when it
b045b9
 succeeds
b045b9
b045b9
Bug Description:
b045b9
	Minor issue
b045b9
	If the update of the DB RUV returns a success LDAP_SUCCESS (internal modify),
b045b9
	it however logs an error as if it failed
b045b9
b045b9
	side effect of https://pagure.io/389-ds-base/issue/48118
b045b9
b045b9
Fix Description:
b045b9
	Log a message only on failure
b045b9
b045b9
https://pagure.io/389-ds-base/issue/49460
b045b9
b045b9
Reviewed by: Ludwig Krispenz, William Brown
b045b9
b045b9
Platforms tested: F23
b045b9
b045b9
Flag Day: no
b045b9
b045b9
Doc impact: no
b045b9
---
b045b9
 dirsrvtests/tests/tickets/ticket49460_test.py    | 115 +++++++++++++++++++++++
b045b9
 ldap/servers/plugins/replication/repl5_replica.c |   3 +-
b045b9
 2 files changed, 116 insertions(+), 2 deletions(-)
b045b9
 create mode 100644 dirsrvtests/tests/tickets/ticket49460_test.py
b045b9
b045b9
diff --git a/dirsrvtests/tests/tickets/ticket49460_test.py b/dirsrvtests/tests/tickets/ticket49460_test.py
b045b9
new file mode 100644
b045b9
index 000000000..296b3c9aa
b045b9
--- /dev/null
b045b9
+++ b/dirsrvtests/tests/tickets/ticket49460_test.py
b045b9
@@ -0,0 +1,115 @@
b045b9
+import time
b045b9
+import ldap
b045b9
+import logging
b045b9
+import pytest
b045b9
+import os
b045b9
+import re
b045b9
+from lib389._constants import *
b045b9
+from lib389.config import Config
b045b9
+from lib389 import DirSrv, Entry
b045b9
+from lib389.topologies import topology_m3 as topo
b045b9
+
b045b9
+DEBUGGING = os.getenv("DEBUGGING", default=False)
b045b9
+if DEBUGGING:
b045b9
+    logging.getLogger(__name__).setLevel(logging.DEBUG)
b045b9
+else:
b045b9
+    logging.getLogger(__name__).setLevel(logging.INFO)
b045b9
+log = logging.getLogger(__name__)
b045b9
+
b045b9
+USER_CN="user"
b045b9
+
b045b9
+def add_user(server, no, desc='dummy', sleep=True):
b045b9
+    cn = '%s%d' % (USER_CN, no)
b045b9
+    dn = 'cn=%s,ou=people,%s' % (cn, SUFFIX)
b045b9
+    log.fatal('Adding user (%s): ' % dn)
b045b9
+    server.add_s(Entry((dn, {'objectclass': ['top', 'person', 'inetuser', 'userSecurityInformation'],
b045b9
+                             'sn': ['_%s' % cn],
b045b9
+                             'description': [desc]})))
b045b9
+    time.sleep(1)
b045b9
+
b045b9
+def check_user(server, no, timeout=10):
b045b9
+
b045b9
+    cn = '%s%d' % (USER_CN, no)
b045b9
+    dn = 'cn=%s,ou=people,%s' % (cn, SUFFIX)
b045b9
+    found = False
b045b9
+    cpt = 0
b045b9
+    while cpt < timeout:
b045b9
+        try:
b045b9
+            server.getEntry(dn, ldap.SCOPE_BASE, "(objectclass=*)")
b045b9
+            found = True
b045b9
+            break
b045b9
+        except ldap.NO_SUCH_OBJECT:
b045b9
+            time.sleep(1)
b045b9
+            cpt += 1
b045b9
+    return found
b045b9
+
b045b9
+def pattern_errorlog(server, log_pattern):
b045b9
+    file_obj = open(server.errlog, "r")
b045b9
+
b045b9
+    found = None
b045b9
+    # Use a while true iteration because 'for line in file: hit a
b045b9
+    while True:
b045b9
+        line = file_obj.readline()
b045b9
+        found = log_pattern.search(line)
b045b9
+        if ((line == '') or (found)):
b045b9
+            break
b045b9
+
b045b9
+    return found
b045b9
+
b045b9
+def test_ticket_49460(topo):
b045b9
+    """Specify a test case purpose or name here
b045b9
+
b045b9
+    :id: d1aa2e8b-e6ab-4fc6-9c63-c6f622544f2d
b045b9
+    :setup: Fill in set up configuration here
b045b9
+    :steps:
b045b9
+        1. Enable replication logging
b045b9
+        2. Do few updates to generatat RUV update
b045b9
+    :expectedresults:
b045b9
+        1. No report of failure when the RUV is updated
b045b9
+    """
b045b9
+
b045b9
+    M1 = topo.ms["master1"]
b045b9
+    M2 = topo.ms["master2"]
b045b9
+    M3 = topo.ms["master3"]
b045b9
+
b045b9
+    for i in (M1, M2, M3):
b045b9
+        i.config.loglevel(vals=[256 + 4], service='access')
b045b9
+        i.config.loglevel(vals=[LOG_REPLICA, LOG_DEFAULT], service='error')
b045b9
+
b045b9
+    add_user(M1, 11, desc="add to M1")
b045b9
+    add_user(M2, 21, desc="add to M2")
b045b9
+    add_user(M3, 31, desc="add to M3")
b045b9
+
b045b9
+    for i in (M1, M2, M3):
b045b9
+            assert check_user(i, 11)
b045b9
+            assert check_user(i, 21)
b045b9
+            assert check_user(i, 31)
b045b9
+
b045b9
+    time.sleep(10)
b045b9
+
b045b9
+    #M1.tasks.cleanAllRUV(suffix=SUFFIX, replicaid='3',
b045b9
+    #                    force=False, args={TASK_WAIT: True})
b045b9
+    #time.sleep(10)
b045b9
+    regex = re.compile(".*Failed to update RUV tombstone.*LDAP error - 0")
b045b9
+    assert not pattern_errorlog(M1, regex)
b045b9
+    assert not pattern_errorlog(M2, regex)
b045b9
+    assert not pattern_errorlog(M3, regex)
b045b9
+
b045b9
+    # If you need any test suite initialization,
b045b9
+    # please, write additional fixture for that (including finalizer).
b045b9
+    # Topology for suites are predefined in lib389/topologies.py.
b045b9
+
b045b9
+    # If you need host, port or any other data about instance,
b045b9
+    # Please, use the instance object attributes for that (for example, topo.ms["master1"].serverid)
b045b9
+
b045b9
+    if DEBUGGING:
b045b9
+        # Add debugging steps(if any)...
b045b9
+        pass
b045b9
+
b045b9
+
b045b9
+if __name__ == '__main__':
b045b9
+    # Run isolated
b045b9
+    # -s for DEBUG mode
b045b9
+    CURRENT_FILE = os.path.realpath(__file__)
b045b9
+    pytest.main("-s %s" % CURRENT_FILE)
b045b9
+
b045b9
diff --git a/ldap/servers/plugins/replication/repl5_replica.c b/ldap/servers/plugins/replication/repl5_replica.c
b045b9
index e3ddd783d..c6d6ee746 100644
b045b9
--- a/ldap/servers/plugins/replication/repl5_replica.c
b045b9
+++ b/ldap/servers/plugins/replication/repl5_replica.c
b045b9
@@ -2829,8 +2829,7 @@ replica_write_ruv(Replica *r)
b045b9
         /* this includes an internal operation - but since this only happens
b045b9
            during server startup - its ok that we have lock around it */
b045b9
         rc = _replica_configure_ruv(r, PR_TRUE);
b045b9
-    } else /* error */
b045b9
-    {
b045b9
+    } else if (rc != LDAP_SUCCESS) { /* error */
b045b9
         slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
b045b9
                       "replica_write_ruv - Failed to update RUV tombstone for %s; "
b045b9
                       "LDAP error - %d\n",
b045b9
-- 
b045b9
2.13.6
b045b9