2015-04-02 07:14:15 -05:00
|
|
|
#
|
|
|
|
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
|
|
|
#
|
|
|
|
|
2015-05-21 07:40:22 -05:00
|
|
|
import os
|
2015-04-02 07:14:15 -05:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import krbV
|
|
|
|
|
|
|
|
from ipalib import api
|
|
|
|
from ipaplatform.paths import paths
|
|
|
|
from ipapython import admintool, ipautil
|
2015-05-21 07:40:22 -05:00
|
|
|
from ipaserver.install import dsinstance
|
2015-04-02 07:14:15 -05:00
|
|
|
from ipaserver.install import installutils
|
2015-05-22 10:38:16 -05:00
|
|
|
from ipaserver.install.server import upgrade_configuration
|
2015-04-02 07:14:15 -05:00
|
|
|
from ipaserver.install.upgradeinstance import IPAUpgrade
|
2015-05-12 06:31:57 -05:00
|
|
|
from ipaserver.install.ldapupdate import BadSyntax
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
class ServerUpgrade(admintool.AdminTool):
|
|
|
|
log_file_name = paths.IPAUPGRADE_LOG
|
|
|
|
command_name = 'ipa-server-upgrade'
|
|
|
|
|
|
|
|
usage = "%prog [options]"
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add_options(cls, parser):
|
2015-04-10 08:42:58 -05:00
|
|
|
super(ServerUpgrade, cls).add_options(parser)
|
|
|
|
parser.add_option("--force", action="store_true",
|
|
|
|
dest="force", default=False,
|
|
|
|
help="force upgrade (alias for --skip-version-check)")
|
|
|
|
parser.add_option("--skip-version-check", action="store_true",
|
|
|
|
dest="skip_version_check", default=False,
|
|
|
|
help="skip version check. WARNING: this may break "
|
|
|
|
"your system")
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
def validate_options(self):
|
|
|
|
super(ServerUpgrade, self).validate_options(needs_root=True)
|
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if self.options.force:
|
|
|
|
self.options.skip_version_check = True
|
|
|
|
|
2015-04-02 07:14:15 -05:00
|
|
|
try:
|
|
|
|
installutils.check_server_configuration()
|
|
|
|
except RuntimeError as e:
|
|
|
|
print unicode(e)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
def setup_logging(self):
|
|
|
|
super(ServerUpgrade, self).setup_logging(log_file_mode='a')
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
super(ServerUpgrade, self).run()
|
|
|
|
|
|
|
|
api.bootstrap(in_server=True, context='updates')
|
|
|
|
api.finalize()
|
|
|
|
|
|
|
|
options = self.options
|
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
if not options.skip_version_check:
|
|
|
|
# check IPA version and data version
|
|
|
|
try:
|
|
|
|
installutils.check_version()
|
|
|
|
except (installutils.UpgradePlatformError,
|
|
|
|
installutils.UpgradeDataNewerVersionError) as e:
|
|
|
|
raise admintool.ScriptError(
|
|
|
|
'Unable to execute IPA upgrade: %s' % e, 1)
|
|
|
|
except installutils.UpgradeMissingVersionError as e:
|
|
|
|
self.log.info("Missing version: %s", e)
|
|
|
|
except installutils.UpgradeVersionError:
|
|
|
|
# Ignore other errors
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.log.info("Skipping version check")
|
|
|
|
self.log.warning("Upgrade without version check may break your "
|
|
|
|
"system")
|
|
|
|
|
2015-04-02 07:14:15 -05:00
|
|
|
realm = krbV.default_context().default_realm
|
2015-05-21 07:40:22 -05:00
|
|
|
schema_files = [os.path.join(ipautil.SHARE_DIR, f) for f
|
|
|
|
in dsinstance.ALL_SCHEMA_FILES]
|
|
|
|
data_upgrade = IPAUpgrade(realm, schema_files=schema_files)
|
2015-04-02 07:14:15 -05:00
|
|
|
|
2015-05-12 06:31:57 -05:00
|
|
|
try:
|
|
|
|
data_upgrade.create_instance()
|
|
|
|
except BadSyntax:
|
2015-04-02 07:14:15 -05:00
|
|
|
raise admintool.ScriptError(
|
|
|
|
'Bad syntax detected in upgrade file(s).', 1)
|
2015-05-12 06:31:57 -05:00
|
|
|
except RuntimeError:
|
2015-04-02 07:14:15 -05:00
|
|
|
raise admintool.ScriptError('IPA upgrade failed.', 1)
|
|
|
|
else:
|
2015-05-12 06:31:57 -05:00
|
|
|
if data_upgrade.modified:
|
|
|
|
self.log.info('Update complete')
|
|
|
|
else:
|
|
|
|
self.log.info('Update complete, no data were modified')
|
2015-04-02 07:14:15 -05:00
|
|
|
|
2015-04-10 08:42:58 -05:00
|
|
|
# store new data version after upgrade
|
|
|
|
installutils.store_version()
|
|
|
|
|
2015-05-22 10:38:16 -05:00
|
|
|
print 'Upgrading IPA services'
|
|
|
|
self.log.info('Upgrading the configuration of the IPA services')
|
|
|
|
upgrade_configuration()
|
|
|
|
self.log.info('The IPA services were upgraded')
|
2015-04-02 07:14:15 -05:00
|
|
|
|
|
|
|
def handle_error(self, exception):
|
|
|
|
return installutils.handle_error(exception, self.log_file_name)
|