From 0c868d6f15ae0d6fab07846f1657d243e900c262 Mon Sep 17 00:00:00 2001 From: William Brown Date: Mon, 20 Nov 2017 17:40:12 +0100 Subject: [PATCH 1/3] Ticket 49461 - Improve db2index handling for test 49290 Bug Description: db2index has limited parameters we can accept, including the types of attributes we can index. Specificatlly, we must take an index name, else we do not re-index (look at ns-slapd, we require -t or -T, and if we do, we require them to have a value. Fix Description: Fix lib389 to match the assertions of ns-slapd with regard to db2index behaviour. https://pagure.io/389-ds-base/issue/49461 Author: wibrown Review by: ??? --- dirsrvtests/tests/tickets/ticket49290_test.py | 2 +- src/lib389/lib389/__init__.py | 46 +++++++++++++++++---------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/dirsrvtests/tests/tickets/ticket49290_test.py b/dirsrvtests/tests/tickets/ticket49290_test.py index 72ba9f9..fcf6b0e 100644 --- a/dirsrvtests/tests/tickets/ticket49290_test.py +++ b/dirsrvtests/tests/tickets/ticket49290_test.py @@ -52,7 +52,7 @@ def test_49290_range_unindexed_notes(topology_st): 'nsIndexType' : 'eq', }) topology_st.standalone.stop() - topology_st.standalone.db2index(DEFAULT_BENAME) + assert topology_st.standalone.db2index(DEFAULT_BENAME, attrs=['modifytimestamp'] ) topology_st.standalone.start() # Now run the modifyTimestamp range query again. Assert that there is no diff --git a/src/lib389/lib389/__init__.py b/src/lib389/lib389/__init__.py index 8a49df4..c4cff8f 100644 --- a/src/lib389/lib389/__init__.py +++ b/src/lib389/lib389/__init__.py @@ -2781,33 +2781,45 @@ class DirSrv(SimpleLDAPObject, object): @return - True if reindexing succeeded """ DirSrvTools.lib389User(user=DEFAULT_USER) - prog = os.path.join(self.ds_paths.sbin_dir, DB2INDEX) + prog = os.path.join(self.ds_paths.sbin_dir, 'ns-slapd') + + if self.status(): + log.error("db2index: Can not operate while directory server is running") + return False if not bename and not suffixes: log.error("db2index: missing required backend name or suffix") return False - cmd = '%s -Z %s' % (prog, self.serverid) + if not attrs: + log.error("db2index: Requires attrs to reindex") + return False + + cmd = [prog, + 'db2index', + '-D', self.get_config_dir() ] + if bename: - cmd = cmd + ' -n %s' % bename + cmd.append('-n') + cmd.append(bename) if suffixes: for suffix in suffixes: - cmd = cmd + ' -s %s' % suffix - if attrs: - for attr in attrs: - cmd = cmd + ' -t %s' % attr + cmd.append('-s') + cmd.append(suffix) + for attr in attrs: + cmd.append('-t') + cmd.append(attr) if vlvTag: - cmd = cmd + ' -T %s' % vlvTag + cmd.append('-T') + cmd.append(vlvTag) - self.stop(timeout=10) - log.info('Running script: %s' % cmd) - result = True - try: - os.system(cmd) - except: - log.error("db2index: error executing %s" % cmd) - result = False - self.start(timeout=10) + result = subprocess.check_output(cmd) + u_result = ensure_str(result) + + log.debug("db2index output: BEGIN") + for line in u_result.split("\n"): + log.debug(line) + log.debug("db2index output: END") return result -- 1.8.3.1