Skip to content

Commit

Permalink
Issue 50884 - Health check tool DSEldif check fails
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mreynolds389 committed Mar 5, 2020
1 parent f479c20 commit 610d2f5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
3 changes: 2 additions & 1 deletion src/lib389/lib389/cli_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))
Expand Down
23 changes: 17 additions & 6 deletions src/lib389/lib389/cli_base/dsrc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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'] = {}

Expand Down Expand Up @@ -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://':
Expand Down
7 changes: 3 additions & 4 deletions src/lib389/lib389/dseldif.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import copy
import os
import sys
import base64
import time
from struct import pack, unpack
Expand Down Expand Up @@ -218,12 +217,12 @@ def _getGenState(self, dn, replica_suffix, nsstate, flip):
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")

Expand All @@ -250,7 +249,7 @@ def _getGenState(self, dn, replica_suffix, nsstate, flip):
# 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
Expand Down
4 changes: 2 additions & 2 deletions src/lib389/lib389/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

# 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.
Expand All @@ -162,7 +162,7 @@

# 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)
Expand Down

0 comments on commit 610d2f5

Please sign in to comment.