From 07a1080c79534703a0234a4b4739a536afffb6a7 Mon Sep 17 00:00:00 2001 From: Mark Reynolds Date: Mar 05 2020 15:03:17 +0000 Subject: Issue 50884 - Health check tool DSEldif check fails Bug Description: dsconf healthcheck was failing depending how the server id entered. Using "slapd-INSTANCE" vs "INSTANCE" produced different results. Fix Description: Normalize the instance name by always stripping off "slapd-". Also fixes similar issue when ~/.dsrc is used. Fixed the RI plugin lint report's inconsistent IDs Fixed issue how flipend was being called for read-nsstate. relates: https://pagure.io/389-ds-base/issue/50884 Reviewed by: spichugi & firstyear (Thanks!) Improve instance name handling robustness --- diff --git a/src/lib389/lib389/cli_base/__init__.py b/src/lib389/lib389/cli_base/__init__.py index 231ffe8..92b5640 100644 --- a/src/lib389/lib389/cli_base/__init__.py +++ b/src/lib389/lib389/cli_base/__init__.py @@ -150,6 +150,8 @@ def connect_instance(dsrc_inst, verbose, args): usercert=dsrc_inst['tls_cert'], userkey=dsrc_inst['tls_key'], starttls=dsrc_inst['starttls'], connOnly=True) + if ds.serverid is not None and ds.serverid.startswith("slapd-"): + ds.serverid = ds.serverid.replace("slapd-", "", 1) return ds @@ -247,7 +249,6 @@ def _generic_replace_attr(inst, basedn, log, manager_class, args=None): if "=" in myattr: [attr, val] = myattr.split("=", 1) mc.replace(attr, val) - print("MARK val: " + val) print("Successfully replaced \"{}\"".format(attr)) else: raise ValueError("You must specify a value to replace the attribute ({})".format(myattr)) diff --git a/src/lib389/lib389/cli_base/dsrc.py b/src/lib389/lib389/cli_base/dsrc.py index 20b240d..9cad234 100644 --- a/src/lib389/lib389/cli_base/dsrc.py +++ b/src/lib389/lib389/cli_base/dsrc.py @@ -8,7 +8,6 @@ import sys import os -import json import ldap from lib389.properties import (SER_LDAP_URL, SER_ROOT_DN, SER_LDAPI_ENABLED, SER_LDAPI_SOCKET, SER_LDAPI_AUTOBIND) @@ -94,7 +93,7 @@ def dsrc_to_ldap(path, instance_name, log): The file should be an ini file, and instance should identify a section. - The ini fileshould have the content: + The ini file should have the content: [instance] uri = ldaps://hostname:port @@ -108,13 +107,24 @@ def dsrc_to_ldap(path, instance_name, log): starttls = [true, false] """ config = _read_dsrc(path, log) + server_id = instance_name - # Does our section exist? - if not config.has_section(instance_name): - # If not, return none. - log.debug("dsrc no such section %s" % instance_name) + # Do we have an instance name to work with? + if instance_name is None: + log.debug("No instance name provided") return None + # Strip the prefix + if instance_name.startswith("slapd-"): + server_id = instance_name = instance_name.replace("slapd-", "", 1) + + if not config.has_section(instance_name): + # instance_name does not have a prefix, but dsrc might, so add it + instance_name = "slapd-" + instance_name + if not config.has_section(instance_name): + log.debug("dsrc no such section: %s" % instance_name) + return None + dsrc_inst = {} dsrc_inst['args'] = {} @@ -143,6 +153,7 @@ def dsrc_to_ldap(path, instance_name, log): dsrc_inst['pwdfile'] = None dsrc_inst['prompt'] = False # Now gather the args + dsrc_inst['args']['server-id'] = server_id dsrc_inst['args'][SER_LDAP_URL] = dsrc_inst['uri'] dsrc_inst['args'][SER_ROOT_DN] = dsrc_inst['binddn'] if dsrc_inst['uri'][0:8] == 'ldapi://': diff --git a/src/lib389/lib389/dseldif.py b/src/lib389/lib389/dseldif.py index 1cafaef..5378e6e 100644 --- a/src/lib389/lib389/dseldif.py +++ b/src/lib389/lib389/dseldif.py @@ -9,7 +9,6 @@ import copy import os -import sys import base64 import time from struct import pack, unpack @@ -218,12 +217,12 @@ class DSEldif(object): endian = "Little Endian" end = '<' if flip: - end = flipend(end) + end = self._flipend(end) elif pack('>h', 1) == pack('=h',1): endian = "Big Endian" end = '>' if flip: - end = flipend(end) + end = self._flipend(end) else: raise ValueError("Unknown endian, unable to proceed") @@ -250,7 +249,7 @@ class DSEldif(object): # if the sampled time is more than 20 years off, this is # probably the wrong endianness if wrongendian: - end = flipend(end) + end = self._flipend(end) fmtstr = end + base_fmtstr (rid, sampled_time, local_offset, remote_offset, seq_num) = unpack(fmtstr, nsstate) tdiff = now-sampled_time diff --git a/src/lib389/lib389/lint.py b/src/lib389/lib389/lint.py index 60af195..b5a305b 100644 --- a/src/lib389/lib389/lint.py +++ b/src/lib389/lib389/lint.py @@ -135,7 +135,7 @@ minimum version, but doing this affects the entire system: # RI plugin checks DSRILE0001 = { - 'dsle': 'DSRLE0001', + 'dsle': 'DSRILE0001', 'severity': 'LOW', 'items' : ['cn=referential integrity postoperation,cn=plugins,cn=config', ], 'detail': """The referential integrity plugin has an asynchronous processing mode. @@ -162,7 +162,7 @@ You must restart the Directory Server for this change to take effect.""" # Note - ATTR and BACKEND are replaced by the reporting function DSRILE0002 = { - 'dsle': 'DSRLE0002', + 'dsle': 'DSRILE0002', 'severity': 'HIGH', 'items' : ['cn=referential integrity postoperation,cn=plugins,cn=config'], 'detail': """The referential integrity plugin is configured to use an attribute (ATTR)