freeipa/ipaserver/install/plugins/update_changelog_maxage.py
Mark Reynolds 44259e8e68 Issue 8407 - Support changelog integration into main database
Description: Add support for both the old and new replication changelogs.
             First try to get and update the new entry, if it's not found
             then we know we need to update the old global changelog entry.

Fixes: https://pagure.io/freeipa/issue/8407

Signed-off-by: Mark Reynolds <mreynolds@redhat.com>

Fix missing self, and missing arg

Fix copy/paste error

Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
2020-08-04 10:54:57 +03:00

52 lines
1.5 KiB
Python

#
# Copyright (C) 2020 FreeIPA Contributors see COPYING for license
#
import logging
from ipalib import Registry, errors
from ipalib import Updater
from ipapython.dn import DN
logger = logging.getLogger(__name__)
register = Registry()
@register()
class update_changelog_maxage(Updater):
"""
Update the changelog maxage if it is not set
"""
def update_entry(self, cl_entry, conn):
maxage = cl_entry.single_value.get('nsslapd-changelogmaxage')
if maxage is None:
cl_entry['nsslapd-changelogmaxage'] = '7d'
conn.update_entry(cl_entry)
def execute(self, **options):
ldap = self.api.Backend.ldap2
for backend in ('userroot', 'ipaca'):
dn = DN(
('cn', 'changelog'),
('cn', backend),
('cn', 'ldbm database'),
('cn', 'plugins'),
('cn', 'config'))
try:
cl_entry = ldap.get_entry(dn, ['nsslapd-changelogmaxage'])
self.update_entry(cl_entry, ldap)
except errors.NotFound:
# Try the old global changelog, and return
dn = DN(
('cn', 'changelog5'),
('cn', 'config'))
try:
cl_entry = ldap.get_entry(dn, ['nsslapd-changelogmaxage'])
self.update_entry(cl_entry, ldap)
except errors.NotFound:
logger.warning('Error retrieving: %s', str(dn))
return False, []
return False, []