summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Basti <mbasti@redhat.com>2014-06-13 10:15:23 +0200
committerMartin Kosek <mkosek@redhat.com>2014-06-27 14:54:35 +0200
commitc1f3fd6831c47a2672f37e12db149be1b1122d75 (patch)
tree98e92dcfae590e6c608fb2691a4505f79841560e
parent5568e357d103bafaf9e2f7f1ba1fd507c89e0538 (diff)
downloadfreeipa-c1f3fd6831c47a2672f37e12db149be1b1122d75.tar.gz
freeipa-c1f3fd6831c47a2672f37e12db149be1b1122d75.tar.xz
freeipa-c1f3fd6831c47a2672f37e12db149be1b1122d75.zip
Added upgrade step executed before schmema is upgraded
Class PreSchemaUpdate is executed before ldap schema update This is required by ticket: https://fedorahosted.org/freeipa/ticket/3210 Reviewed-By: Martin Kosek <mkosek@redhat.com>
-rw-r--r--ipaserver/install/ipa_ldap_updater.py14
-rw-r--r--ipaserver/install/ldapupdate.py15
-rw-r--r--ipaserver/install/plugins/__init__.py1
-rw-r--r--ipaserver/install/plugins/baseupdate.py15
-rw-r--r--ipaserver/install/upgradeinstance.py17
5 files changed, 54 insertions, 8 deletions
diff --git a/ipaserver/install/ipa_ldap_updater.py b/ipaserver/install/ipa_ldap_updater.py
index e8ef2b576..fbbef142a 100644
--- a/ipaserver/install/ipa_ldap_updater.py
+++ b/ipaserver/install/ipa_ldap_updater.py
@@ -191,12 +191,6 @@ class LDAPUpdater_NonUpgrade(LDAPUpdater):
modified = False
- if options.update_schema:
- modified = schemaupdate.update_schema(
- options.schema_files,
- dm_password=self.dirman_password,
- live_run=not options.test) or modified
-
ld = LDAPUpdate(
dm_password=self.dirman_password,
sub_dict={},
@@ -204,6 +198,14 @@ class LDAPUpdater_NonUpgrade(LDAPUpdater):
ldapi=options.ldapi,
plugins=options.plugins or self.run_plugins)
+ modified = ld.pre_schema_update(ordered=True)
+
+ if options.update_schema:
+ modified = schemaupdate.update_schema(
+ options.schema_files,
+ dm_password=self.dirman_password,
+ live_run=not options.test) or modified
+
if not self.files:
self.files = ld.get_all_files(UPDATES_DIR)
diff --git a/ipaserver/install/ldapupdate.py b/ipaserver/install/ldapupdate.py
index ecdf8e6e1..b6c6d2b90 100644
--- a/ipaserver/install/ldapupdate.py
+++ b/ipaserver/install/ldapupdate.py
@@ -42,7 +42,8 @@ from ipalib import api
from ipaplatform.paths import paths
from ipapython.dn import DN
from ipapython.ipa_log_manager import *
-from ipaserver.install.plugins import PRE_UPDATE, POST_UPDATE
+from ipaserver.install.plugins import (PRE_UPDATE, POST_UPDATE,
+ PRE_SCHEMA_UPDATE)
from ipaserver.plugins import ldap2
UPDATES_DIR=paths.UPDATES_DIR
@@ -794,6 +795,18 @@ class LDAPUpdate:
for dn, update in sorted_updates:
self._delete_record(update)
+ def pre_schema_update(self, ordered=False):
+ """Execute the update before the LDPA schema is updated.
+ """
+ if self.plugins:
+ self.info('PRE_SCHEMA_UPDATE')
+ all_updates = {}
+ updates = api.Backend.updateclient.update(PRE_SCHEMA_UPDATE, self.dm_password, self.ldapi, self.live_run)
+ self.merge_updates(all_updates, updates)
+ self._run_updates(all_updates)
+
+ return self.modified
+
def update(self, files, ordered=False):
"""Execute the update. files is a list of the update files to use.
diff --git a/ipaserver/install/plugins/__init__.py b/ipaserver/install/plugins/__init__.py
index 49bef4df8..210c56ef7 100644
--- a/ipaserver/install/plugins/__init__.py
+++ b/ipaserver/install/plugins/__init__.py
@@ -20,6 +20,7 @@
"""
Provide a separate api for updates.
"""
+PRE_SCHEMA_UPDATE = 0
PRE_UPDATE = 1
POST_UPDATE = 2
diff --git a/ipaserver/install/plugins/baseupdate.py b/ipaserver/install/plugins/baseupdate.py
index a480a8ee2..dc6672ac5 100644
--- a/ipaserver/install/plugins/baseupdate.py
+++ b/ipaserver/install/plugins/baseupdate.py
@@ -20,7 +20,8 @@
from ipalib import api
from ipalib import Updater, Object
from ipaserver.install import service
-from ipaserver.install.plugins import PRE_UPDATE, POST_UPDATE, MIDDLE
+from ipaserver.install.plugins import (PRE_UPDATE, POST_UPDATE,
+ PRE_SCHEMA_UPDATE, MIDDLE)
class DSRestart(service.Service):
"""
@@ -55,6 +56,18 @@ class update(Object):
api.register(update)
+
+class PreSchemaUpdate(Updater):
+ """
+ Base class for updates that run after file processing.
+ """
+ updatetype = PRE_SCHEMA_UPDATE
+ order = MIDDLE
+
+ def __init__(self):
+ super(PreSchemaUpdate, self).__init__()
+
+
class PreUpdate(Updater):
"""
Base class for updates that run prior to file processing.
diff --git a/ipaserver/install/upgradeinstance.py b/ipaserver/install/upgradeinstance.py
index 66eafa8cc..062d5da22 100644
--- a/ipaserver/install/upgradeinstance.py
+++ b/ipaserver/install/upgradeinstance.py
@@ -78,6 +78,7 @@ class IPAUpgrade(service.Service):
self.step("saving configuration", self.__save_config)
self.step("disabling listeners", self.__disable_listeners)
self.step("starting directory server", self.__start_nowait)
+ self.step("preparing server upgrade", self.__pre_schema_upgrade)
if self.schema_files:
self.step("updating schema", self.__update_schema)
self.step("upgrading server", self.__upgrade)
@@ -115,6 +116,22 @@ class IPAUpgrade(service.Service):
installutils.set_directive(self.filename, 'nsslapd-ldapientrysearchbase',
None, quotes=False, separator=':')
+ def __pre_schema_upgrade(self):
+ try:
+ ld = ldapupdate.LDAPUpdate(dm_password='', ldapi=True, live_run=self.live_run, plugins=True)
+ self.modified = (ld.pre_schema_update(ordered=True) or
+ self.modified)
+ except ldapupdate.BadSyntax, e:
+ root_logger.error('Bad syntax in pre schema upgrade %s' % str(e))
+ self.modified = False
+ self.badsyntax = True
+ except Exception, e:
+ # Bad things happened, return gracefully
+ self.modified = False
+ self.upgradefailed = True
+ root_logger.error('Pre schema upgrade failed with %s' % str(e))
+ root_logger.debug('%s', traceback.format_exc())
+
def __update_schema(self):
self.modified = schemaupdate.update_schema(
self.schema_files,