Skip to content

Commit

Permalink
Issue 4796 - Add support for nsslapd-state to CLI & UI
Browse files Browse the repository at this point in the history
Description:

Add support for nsslapd-state to lib389 and UI. Also added a check to prevent the changing of nsslapd-state for replicated suffixes.

Also did a little UI cleanup where a bottom margin was added to the bottom of pages instead of using "hr" to create the gap.

relates: #4796

Reviewed by: jchapman & spichugi(Thanks!)
  • Loading branch information
mreynolds389 committed Sep 11, 2021
1 parent 57b6480 commit 9d0c9b8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
31 changes: 31 additions & 0 deletions src/lib389/lib389/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,37 @@ def get_cos_classic_defs(self):
def get_cos_templates(self):
return CosTemplates(self._instance, self._dn).list()

def get_state(self):
suffix = self.get_attr_val_utf8('nsslapd-suffix')
try:
mt = self._mts.get(suffix)
except ldap.NO_SUCH_OBJECT:
raise ValueError("Backend missing mapping tree entry, unable to get state")
return mt.get_attr_val_utf8('nsslapd-state')

def set_state(self, new_state):
new_state = new_state.lower()
suffix = self.get_attr_val_utf8('nsslapd-suffix')
try:
mt = self._mts.get(suffix)
except ldap.NO_SUCH_OBJECT:
raise ValueError("Backend missing mapping tree entry, unable to set configuration")

if new_state not in ['backend', 'disabled', 'referral', 'referral on update']:
raise ValueError(f"Invalid backend state {new_state}, value must be one of the following: 'backend', 'disabled', 'referral', 'referral on update'")

# Can not change state of replicated backend
replicas = Replicas(self._instance)
try:
# Check if replication is enabled
replicas.get(suffix)
raise ValueError("Can not change the backend state of a replicated suffix")
except ldap.NO_SUCH_OBJECT:
pass

# Ok, change the state
mt.replace('nsslapd-state', new_state)


class Backends(DSLdapObjects):
"""DSLdapObjects that represents DN_LDBM base DN
Expand Down
18 changes: 16 additions & 2 deletions src/lib389/lib389/cli_conf/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
arg_to_attr = {
'lookthroughlimit': 'nsslapd-lookthroughlimit',
'mode': 'nsslapd-mode',
'state': 'nsslapd-state',
'idlistscanlimit': 'nsslapd-idlistscanlimit',
'directory': 'nsslapd-directory',
'dbcachesize': 'nsslapd-dbcachesize',
Expand Down Expand Up @@ -155,7 +156,18 @@ def backend_list(inst, basedn, log, args):

def backend_get(inst, basedn, log, args):
rdn = _get_arg(args.selector, msg="Enter %s to retrieve" % RDN)
_generic_get(inst, basedn, log.getChild('backend_get'), MANY, rdn, args)
be = _get_backend(inst, rdn)
be_state = be.get_state()
if args.json:
entry = be.get_all_attrs_json()
entry_dict = json.loads(entry)
entry_dict['attrs']['nsslapd-state'] = [be_state]
log.info(json.dumps(entry_dict, indent=4))
else:
entry = be.display()
updated_entry = entry[:-1] # remove \n
updated_entry += "nsslapd-state: " + be_state
log.info(updated_entry)


def backend_get_dn(inst, basedn, log, args):
Expand Down Expand Up @@ -482,6 +494,8 @@ def backend_set(inst, basedn, log, args):
be.set('nsslapd-require-index', 'on')
if args.ignore_index:
be.set('nsslapd-require-index', 'off')
if args.state:
be.set_state(args.state)
if args.enable:
be.enable()
if args.disable:
Expand Down Expand Up @@ -802,7 +816,6 @@ def backend_compact(inst, basedn, log, args):
raise ValueError("Failed to create Database Compaction Task")
log.info("Successfully started Database Compaction Task")


def create_parser(subparsers):
backend_parser = subparsers.add_parser('backend', help="Manage database suffixes and backends")
subcommands = backend_parser.add_subparsers(help="action")
Expand Down Expand Up @@ -849,6 +862,7 @@ def create_parser(subparsers):
set_backend_parser.add_argument('--cache-size', help='The maximum number of entries to keep in the entry cache')
set_backend_parser.add_argument('--cache-memsize', help='The maximum size in bytes that the entry cache can grow to')
set_backend_parser.add_argument('--dncache-memsize', help='The maximum size in bytes that the DN cache can grow to')
set_backend_parser.add_argument('--state', help='Change the backend state to: "database", "disabled", "referral", "referral on update"')
set_backend_parser.add_argument('be_name', help='The backend name or suffix to delete')

#########################################
Expand Down

0 comments on commit 9d0c9b8

Please sign in to comment.