def initLogging (debug): global logFile try: #in order to use UTC date for the log file, send True to getCurrentDateTime(True) logFilename = "openstack-setup_%s.log" %(utils.getCurrentDateTime()) logFile = os.path.join(basedefs.DIR_LOG,logFilename) if not os.path.isdir(os.path.dirname(logFile)): os.makedirs(os.path.dirname(logFile)) hdlr = logging.FileHandler (filename = logFile, mode='w') if (debug): level = logging.DEBUG else: level = logging.WARNING fmts='%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)s:: %(message)s' dfmt='%Y-%m-%d %H:%M:%S' fmt = logging.Formatter(fmts, dfmt) hdlr.setFormatter(fmt) logging.root.addHandler(hdlr) logging.root.setLevel(level) except: logging.error(traceback.format_exc()) raise Exception(output_messages.ERR_EXP_FAILED_INIT_LOGGER)
def __init__(self): date = utils.getCurrentDateTime() self.sqlfile = "%s/%s_%s.sql" % (basedefs.DIR_DB_BACKUPS, BACKUP_FILE, date) self.updated = False self.dbrenamed = False self.name = basedefs.DB_NAME
def backup(self): """ Backup slimmed JBoss profile """ logging.debug("Slimmed profile backup started") now = utils.getCurrentDateTime() # Backup profile under /var if os.path.exists(VAR_SLIMMED_DIR): backupDir = os.path.join(JBOSS_SERVER_DIR, "%s-%s" % (basedefs.JBOSS_PROFILE_NAME, now)) logging.debug("Copy %s to %s", VAR_SLIMMED_DIR, backupDir) shutil.copytree(VAR_SLIMMED_DIR, backupDir, True) else: logging.debug("%s doesn't exists", VAR_SLIMMED_DIR) # Backup profile under /etc if os.path.exists(ETC_SLIMMED_DIR): backupDir = os.path.join(ETC_JBOSS_DIR, "%s-%s" % (basedefs.JBOSS_PROFILE_NAME, now)) logging.debug("Copy %s to %s", ETC_SLIMMED_DIR, backupDir) shutil.copytree(ETC_SLIMMED_DIR, backupDir, True) else: logging.debug("%s doesn't exists", ETC_SLIMMED_DIR) logging.debug("Slimmed profile backup completed successfully")
def backup(self): logging.debug("CA backup started") if not os.path.isdir(PKI_BACKUP_DIR): os.mkdir(PKI_BACKUP_DIR) # Do backup now = utils.getCurrentDateTime() backupDir = os.path.join(PKI_BACKUP_DIR, "%s-%s" % (BASE_NAME, now)) logging.debug("Copy %s to %s", PKI_DIR, backupDir) shutil.copytree(PKI_DIR, backupDir, True) logging.debug("CA backup completed successfully")
def cleanPgpass(): ''' This function cleans engine entries from pgpass file ''' # Nothing to do if the .pgpass file doesn't exist: if not os.path.exists(basedefs.DB_PASS_FILE): logging.debug("The %s file doesn't exist." % basedefs.DB_PASS_FILE) return backupFile = None # Cleaning .pgpass try: backupFile = "%s.%s" % (basedefs.DB_PASS_FILE, utils.getCurrentDateTime()) logging.debug("Found %s file, backing current to %s" % (basedefs.DB_PASS_FILE, backupFile)) shutil.copyfile(basedefs.DB_PASS_FILE, backupFile) lines = [] with open(basedefs.DB_PASS_FILE, 'r') as f: lines = f.read().split('\n') inEngine = None newLines = lines[:] for line in newLines: if basedefs.PGPASS_FILE_HEADER_LINE.split('\n')[0] in line: inEngine = True if basedefs.PGPASS_FILE_CLOSING_LINE in line: lines.remove(line) inEngine = False if inEngine: lines.remove(line) with open(basedefs.DB_PASS_FILE, 'w') as f: for line in lines: f.write("%s\n" % line) except: logging.error("Failed to clean %s" % basedefs.DB_PASS_FILE) logging.debug("Restoring original %s file from backup %s" % (basedefs.DB_PASS_FILE, backupFile)) shutil.copyfile(backupFile, basedefs.DB_PASS_FILE) raise Exception("Failed to clean %s" % basedefs.DB_PASS_FILE) # if cleaning ok, remove backup logging.debug("Removing %s" % backupFile) os.remove(backupFile) logging.debug("Cleaning %s completed successfully" % basedefs.DB_PASS_FILE)
def cleanPgpass(): ''' This function cleans engine entries from pgpass file ''' # Nothing to do if the .pgpass file doesn't exist: if not os.path.exists(basedefs.DB_PASS_FILE): logging.debug("The %s file doesn't exist." % basedefs.DB_PASS_FILE) return backupFile = None # Cleaning .pgpass try: backupFile = "%s.%s" % (basedefs.DB_PASS_FILE, utils.getCurrentDateTime()) logging.debug("Found %s file, backing current to %s" % (basedefs.DB_PASS_FILE, backupFile)) shutil.copyfile(basedefs.DB_PASS_FILE, backupFile) lines = [] with open(basedefs.DB_PASS_FILE, 'r') as f: lines = f.read().split('\n') inEngine = None newLines = lines[:] for line in newLines: if basedefs.PGPASS_FILE_HEADER_LINE.split('\n')[0] in line: inEngine=True if basedefs.PGPASS_FILE_CLOSING_LINE in line: lines.remove(line) inEngine=False if inEngine: lines.remove(line) with open(basedefs.DB_PASS_FILE, 'w') as f: for line in lines: f.write("%s\n" % line) except: logging.error("Failed to clean %s" % basedefs.DB_PASS_FILE) logging.debug("Restoring original %s file from backup %s" % (basedefs.DB_PASS_FILE, backupFile)) shutil.copyfile(backupFile, basedefs.DB_PASS_FILE) raise Exception("Failed to clean %s" % basedefs.DB_PASS_FILE) # if cleaning ok, remove backup logging.debug("Removing %s" % backupFile) os.remove(backupFile) logging.debug("Cleaning %s completed successfully" % basedefs.DB_PASS_FILE)
def initLogging(): global LOG_FILE try: if not os.path.isdir(LOG_PATH): os.makedirs(LOG_PATH) LOG_FILE = "%s/ovirt-engine-upgrade_%s.log"%(LOG_PATH, utils.getCurrentDateTime()) level = logging.DEBUG # TODO: Move to mode="a"? hdlr = logging.FileHandler(filename = LOG_FILE, mode='w') fmts='%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)s:: %(message)s' dfmt='%Y-%m-%d %H:%M:%S' fmt = logging.Formatter(fmts, dfmt) hdlr.setFormatter(fmt) logging.root.addHandler(hdlr) logging.root.setLevel(level) except: logging.error(traceback.format_exc()) raise Exception("Failed to initiate logger")
def initLogging(): global LOG_FILE try: if not os.path.isdir(LOG_PATH): os.makedirs(LOG_PATH) LOG_FILE = "%s/%s-cleanup_%s.log" % (LOG_PATH, PREFIX, utils.getCurrentDateTime()) level = logging.DEBUG # TODO: Move to mode="a"? hdlr = logging.FileHandler(filename = LOG_FILE, mode='w') fmts = '%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)s:: %(message)s' dfmt = '%Y-%m-%d %H:%M:%S' fmt = logging.Formatter(fmts, dfmt) hdlr.setFormatter(fmt) logging.root.addHandler(hdlr) logging.root.setLevel(level) except: logging.error(traceback.format_exc()) raise Exception("Failed to initiate logger")
def initLogging(level='INFO'): global logFile try: #in order to use UTC date for the log file, send True to getCurrentDateTime(True) logFilename = "openstack-setup_%s.log" % (utils.getCurrentDateTime()) logFile = os.path.join(basedefs.DIR_LOG, logFilename) if not os.path.isdir(os.path.dirname(logFile)): os.makedirs(os.path.dirname(logFile)) level = getattr(logging, level) hdlr = logging.FileHandler(filename=logFile, mode='w') fmts = '%(asctime)s::%(levelname)s::%(module)s::%(lineno)d::%(name)s:: %(message)s' dfmt = '%Y-%m-%d %H:%M:%S' fmt = logging.Formatter(fmts, dfmt) hdlr.setFormatter(fmt) logging.root.addHandler(hdlr) logging.root.setLevel(level) except: logging.error(traceback.format_exc()) raise Exception(output_messages.ERR_EXP_FAILED_INIT_LOGGER)
def _createTempPgPass(dbAdminUser, dbHost, dbPort, dbPass): """docstring for _createTempPgPass""" #backup existing .pgpass backupFile = "%s.%s" % (basedefs.DB_PASS_FILE, utils.getCurrentDateTime()) try: if (os.path.exists(basedefs.DB_PASS_FILE)): logging.debug("found existing pgpass file, backing current to %s for validation" % (backupFile)) os.rename(basedefs.DB_PASS_FILE, backupFile) with open(basedefs.DB_PASS_FILE, "w") as pgPassFile: pgPassFile.write("%s:%s:*:%s:%s" % (dbHost, dbPort, dbAdminUser, dbPass)) #make sure the file has still 0600 mod os.chmod(basedefs.DB_PASS_FILE, 0600) return backupFile except: # Restore original file os.rename(backupFile, basedefs.DB_PASS_FILE) raise Exception(output_messages.ERR_BACKUP_PGPASS % backupFile)
def main(options): rhyum = MYum() db = DB() DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime()) # Check for upgrade, else exit print MSG_INFO_CHECK_UPDATE if not rhyum.updateAvailable(): logging.debug(MSG_INFO_NO_UPGRADE_AVAIL) print MSG_INFO_NO_UPGRADE_AVAIL sys.exit(0) else: updates = rhyum.getUpdateCandidates() print MSG_INFO_UPGRADE_AVAIL % (len(updates)) for package in updates: print " * %s" % package if options.check_update: sys.exit(100) # Check for setup package if rhyum.isCandidateForUpdate(RPM_SETUP) and not options.force_current_setup_rpm: logging.debug(MSG_ERROR_NEW_SETUP_AVAIL) print MSG_ERROR_NEW_SETUP_AVAIL sys.exit(3) # Make sure we will be able to rollback if not rhyum.rollbackAvailable() and options.yum_rollback: logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL) print MSG_ERROR_NO_ROLLBACK_AVAIL print MSG_ERROR_CHECK_LOG%(LOG_FILE) sys.exit(2) # No rollback in this case try: # We ask the user before stoping jboss or take command line option if options.unattended_upgrade or checkJbossService(): # Stopping jboss runFunc([stopJboss], MSG_INFO_STOP_JBOSS) else: # This means that user chose not to stop jboss logging.debug("exiting gracefully") print MSG_INFO_STOP_INSTALL_EXIT sys.exit(0) # Backup DB if isUpdateRelatedToDb(rhyum): runFunc([db.backup], MSG_INFO_BACKUP_DB) runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB) except Exception as e: print e raise # In case of failure, do rollback try: # yum update runFunc([rhyum.update], MSG_INFO_YUM_UPDATE) # define db connections services etlService = utils.Service("ovirt-engine-etl") notificationService = utils.Service("ovirt-engine-notifierd") # check if update is relevant to db update if isUpdateRelatedToDb(rhyum): stopDbRelatedServices(etlService, notificationService) # Update the db and restore its name back runFunc([db.update], MSG_INFO_DB_UPDATE) runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB) # Bring up any services we shut down before db upgrade startDbRelatedServices(etlService, notificationService) # post install conf runFunc([runPost], MSG_INFO_RUN_POST) except: logging.error(traceback.format_exc()) logging.error("Rolling back update") print MSG_ERROR_UPGRADE print MSG_INFO_REASON%(sys.exc_info()[1]) # db restore if isUpdateRelatedToDb(rhyum): runFunc([db.restore], MSG_INFO_DB_RESTORE) # yum rollback if options.yum_rollback: runFunc([rhyum.rollback], MSG_INFO_YUM_ROLLBACK) else: print MSG_INFO_NO_YUM_ROLLBACK logging.debug("Skipping yum rollback") raise finally: # start jboss runFunc([startJboss], MSG_INFO_START_JBOSS) # Print log location on success addAdditionalMessages(etlService.isServiceAvailable()) print "\n%s\n" % MSG_INFO_UPGRADE_OK printMessages()
def __init__(self): date = utils.getCurrentDateTime() self.sqlfile = "%s/%s_%s.sql" % (BACKUP_DIR, BACKUP_FILE, date) self.updated = False self.name = basedefs.DB_NAME
def main(options): rhyum = MYum() db = DB() DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime()) # Check for upgrade, else exit print MSG_INFO_CHECK_UPDATE if not rhyum.updateAvailable(): logging.debug(MSG_INFO_NO_UPGRADE_AVAIL) print MSG_INFO_NO_UPGRADE_AVAIL sys.exit(0) else: updates = rhyum.getUpdateCandidates() print MSG_INFO_UPGRADE_AVAIL % (len(updates)) for package in updates: print " * %s" % package if options.check_update: sys.exit(100) # Check for setup package if rhyum.isCandidateForUpdate( RPM_SETUP) and not options.force_current_setup_rpm: logging.debug(MSG_ERROR_NEW_SETUP_AVAIL) print MSG_ERROR_NEW_SETUP_AVAIL sys.exit(3) # Make sure we will be able to rollback if not rhyum.rollbackAvailable() and options.yum_rollback: logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL) print MSG_ERROR_NO_ROLLBACK_AVAIL print MSG_ERROR_CHECK_LOG % (LOG_FILE) sys.exit(2) # No rollback in this case try: # We ask the user before stoping jboss or take command line option if options.unattended_upgrade or checkJbossService(): # Stopping engine runFunc([stopEngine], MSG_INFO_STOP_JBOSS) else: # This means that user chose not to stop jboss logging.debug("exiting gracefully") print MSG_INFO_STOP_INSTALL_EXIT sys.exit(0) # Backup DB if isUpdateRelatedToDb(rhyum): runFunc([db.backup], MSG_INFO_BACKUP_DB) runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB) except Exception as e: print e raise # In case of failure, do rollback try: # yum update runFunc([rhyum.update], MSG_INFO_YUM_UPDATE) # define db connections services etlService = utils.Service("ovirt-engine-etl") notificationService = utils.Service("ovirt-engine-notifierd") # check if update is relevant to db update if isUpdateRelatedToDb(rhyum): stopDbRelatedServices(etlService, notificationService) # Update the db and restore its name back runFunc([db.update], MSG_INFO_DB_UPDATE) runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB) # Bring up any services we shut down before db upgrade startDbRelatedServices(etlService, notificationService) # post install conf runFunc([runPost], MSG_INFO_RUN_POST) except: logging.error(traceback.format_exc()) logging.error("Rolling back update") print MSG_ERROR_UPGRADE print MSG_INFO_REASON % (sys.exc_info()[1]) # db restore if isUpdateRelatedToDb(rhyum): runFunc([db.restore], MSG_INFO_DB_RESTORE) # yum rollback if options.yum_rollback: runFunc([rhyum.rollback], MSG_INFO_YUM_ROLLBACK) else: print MSG_INFO_NO_YUM_ROLLBACK logging.debug("Skipping yum rollback") raise finally: # start jboss runFunc([startEngine], MSG_INFO_START_JBOSS) # Print log location on success addAdditionalMessages(etlService.isServiceAvailable()) print "\n%s\n" % MSG_INFO_UPGRADE_OK printMessages()
def main(options): # BEGIN: PROCESS-INITIALIZATION miniyumsink = utils.MiniYumSink() MiniYum.setup_log_hook(sink=miniyumsink) extraLog = open(logFile, "a") miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog) miniyum.selinux_role() # END: PROCESS-INITIALIZATION # we do not wish to be interrupted signal.signal(signal.SIGINT, signal.SIG_IGN) rhyum = MYum(miniyum) db = DB() ca = CA() DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime()) # Handle pgpass if not os.path.exists(basedefs.DB_PASS_FILE): if not os.path.exists(basedefs.ORIG_PASS_FILE): logging.error(MSG_ERROR_PGPASS) print MSG_ERROR_PGPASS sys.exit(1) else: logging.info("Info: Found .pgpass file at old location. Moving it to a new location.") # Create directory if needed dbPassFileDirectory = os.path.dirname(basedefs.DB_PASS_FILE) if not os.path.exists(dbPassFileDirectory): os.makedirs(dbPassFileDirectory) shutil.copy(basedefs.ORIG_PASS_FILE, basedefs.DB_PASS_FILE) # File is copied/created by root, so no need to verify the owner. os.chmod(basedefs.DB_PASS_FILE, 0600) else: logging.info("Info: %s file found. Continue.", basedefs.DB_PASS_FILE) # Functions/parameters definitions stopEngineService = [stopEngine] preupgradeFunc = [preupgradeUUIDCheck] upgradeFunc = [rhyum.update] postFunc = [modifyUUIDs, ca.commit, runPost] engineService = basedefs.ENGINE_SERVICE_NAME # define db connections services etlService = utils.Service(basedefs.ETL_SERVICE_NAME) notificationService = utils.Service(basedefs.NOTIFIER_SERVICE_NAME) if unsupportedVersionsPresent(): print MSG_ERROR_INCOMPATIBLE_UPGRADE raise Exception(MSG_ERROR_INCOMPATIBLE_UPGRADE) rhyum.clean() with rhyum.transaction(): # Check for upgrade, else exit runFunc([rhyum.begin], MSG_INFO_CHECK_UPDATE) if rhyum.emptyTransaction: logging.debug(MSG_INFO_NO_UPGRADE_AVAIL) print MSG_INFO_NO_UPGRADE_AVAIL sys.exit(0) packages = rhyum.getPackages() name_packages = [p['name'] for p in packages] print MSG_INFO_UPGRADE_AVAIL % (len(packages)) for p in packages: print " * %s" % p['display_name'] if options.check_update: sys.exit(100) if RPM_SETUP in name_packages and not options.force_current_setup_rpm: logging.debug(MSG_ERROR_NEW_SETUP_AVAIL) print MSG_ERROR_NEW_SETUP_AVAIL sys.exit(3) # Make sure we will be able to rollback if not rhyum.rollbackAvailable(packages) and options.yum_rollback: logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL) print MSG_ERROR_NO_ROLLBACK_AVAIL print MSG_ERROR_CHECK_LOG % logFile sys.exit(2) # Update is related to database if: # 1. database related package is updated # 2. CA upgrade is going to alter parameters within database # 3. UUID update will take place updateRelatedToDB = False for package in RPM_BACKEND, RPM_DBSCRIPTS: if package in name_packages: updateRelatedToDB = True logging.debug("related to database package %s" % package) updateRelatedToDB = updateRelatedToDB or ca.mayUpdateDB() updateRelatedToDB = updateRelatedToDB or hostids # No rollback in this case try: # We ask the user before stoping ovirt-engine or take command line option if options.unattended_upgrade or checkEngine(engineService): # Stopping engine runFunc(stopEngineService, MSG_INFO_STOP_ENGINE) if updateRelatedToDB: runFunc([[stopDbRelatedServices, etlService, notificationService]], MSG_INFO_STOP_DB) else: # This means that user chose not to stop ovirt-engine logging.debug("exiting gracefully") print MSG_INFO_STOP_INSTALL_EXIT sys.exit(0) # Preupgrade checks runFunc(preupgradeFunc, MSG_INFO_PREUPGRADE) # Backup DB if updateRelatedToDB: runFunc([db.backup], MSG_INFO_BACKUP_DB) runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB) except Exception as e: print e raise # In case of failure, do rollback try: # yum update runFunc(upgradeFunc, MSG_INFO_YUM_UPDATE) # check if update is relevant to db update if updateRelatedToDB: # Update the db and restore its name back runFunc([db.update], MSG_INFO_DB_UPDATE) runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB) # Bring up any services we shut down before db upgrade startDbRelatedServices(etlService, notificationService) # CA restore runFunc([ca.prepare], MSG_INFO_PKI_PREPARE) # post install conf runFunc(postFunc, MSG_INFO_RUN_POST) except: logging.error(traceback.format_exc()) logging.error("Rolling back update") print MSG_ERROR_UPGRADE print MSG_INFO_REASON%(sys.exc_info()[1]) # CA restore runFunc([ca.rollback], MSG_INFO_PKI_ROLLBACK) # allow db restore if updateRelatedToDB: try: runFunc([db.restore], MSG_INFO_DB_RESTORE) except: # This Exception have already been logged, so just pass along pass raise finally: # start engine runFunc([startEngine], MSG_INFO_START_ENGINE) # Print log location on success addAdditionalMessages(etlService.isServiceAvailable()) print "\n%s\n" % MSG_INFO_UPGRADE_OK printMessages()
def main(options): # BEGIN: PROCESS-INITIALIZATION miniyumsink = utils.MiniYumSink() MiniYum.setup_log_hook(sink=miniyumsink) extraLog = open(logFile, "a") # Place getEngineVersion here or new version can't be detected startVersion = utils.getEngineVersion() logging.debug("Start version is %s ", startVersion) miniyum = MiniYum(sink=miniyumsink, extraLog=extraLog) miniyum.selinux_role() # END: PROCESS-INITIALIZATION # we do not wish to be interrupted signal.signal(signal.SIGINT, signal.SIG_IGN) rhyum = MYum(miniyum) db = DB() ca = CA() DB_NAME_TEMP = "%s_%s" % (basedefs.DB_NAME, utils.getCurrentDateTime()) # Handle pgpass if not os.path.exists(basedefs.DB_PASS_FILE): if not os.path.exists(basedefs.ORIG_PASS_FILE): logging.error(MSG_ERROR_PGPASS) print MSG_ERROR_PGPASS sys.exit(1) else: logging.info( "Info: Found .pgpass file at old location. Moving it to a new location." ) # Create directory if needed dbPassFileDirectory = os.path.dirname(basedefs.DB_PASS_FILE) if not os.path.exists(dbPassFileDirectory): os.makedirs(dbPassFileDirectory) shutil.copy(basedefs.ORIG_PASS_FILE, basedefs.DB_PASS_FILE) # Edit .pgpass editPgpass(basedefs.DB_PASS_FILE) # File is copied/created by root, so no need to verify the owner. os.chmod(basedefs.DB_PASS_FILE, 0600) else: logging.info("Info: %s file found. Continue.", basedefs.DB_PASS_FILE) # Functions/parameters definitions currentDbName = basedefs.DB_NAME stopEngineService = [stopEngine] startEngineService = [startEngine] preupgradeFunc = [preupgradeUUIDCheck] upgradeFunc = [rhyum.update] postFunc = [modifyUUIDs, ca.commit, runPost] engineService = basedefs.ENGINE_SERVICE_NAME # define db connections services etlService = utils.Service(basedefs.ETL_SERVICE_NAME) notificationService = utils.Service(basedefs.NOTIFIER_SERVICE_NAME) # Check for the available free space in required locations: # 1. DB backups location # 2. Yum cache location (for downloading packages) # 3. /usr/share location (for installing jboss and engine) if not options.no_space_check: # The second part of the map is the space required in each location for # the successfull upgrade. required_folders_map = { basedefs.DIR_DB_BACKUPS: basedefs.CONST_DB_SIZE, basedefs.DIR_YUM_CACHE: basedefs.CONST_DOWNLOAD_SIZE_MB, basedefs.DIR_PKGS_INSTALL: basedefs.CONST_INSTALL_SIZE_MB, } utils.checkAvailableSpace( required=required_folders_map, dbName=currentDbName, dbFolder=basedefs.DIR_DB_BACKUPS, msg=output_messages.MSG_STOP_UPGRADE_SPACE, ) # Check minimal supported versions of installed components if unsupportedVersionsPresent(dbName=currentDbName): print MSG_ERROR_INCOMPATIBLE_UPGRADE raise Exception(MSG_ERROR_INCOMPATIBLE_UPGRADE) rhyum.clean() with rhyum.transaction(): # Check for upgrade, else exit runFunc([rhyum.begin], MSG_INFO_CHECK_UPDATE) if rhyum.emptyTransaction: logging.debug(MSG_INFO_NO_UPGRADE_AVAIL) print MSG_INFO_NO_UPGRADE_AVAIL sys.exit(0) packages = rhyum.getPackages() name_packages = [p['name'] for p in packages] print MSG_INFO_UPGRADE_AVAIL % (len(packages)) for p in packages: print " * %s" % p['display_name'] if options.check_update: sys.exit(100) if RPM_SETUP in name_packages and not options.force_current_setup_rpm: logging.debug(MSG_ERROR_NEW_SETUP_AVAIL) print MSG_ERROR_NEW_SETUP_AVAIL sys.exit(3) # Make sure we will be able to rollback if not rhyum.rollbackAvailable(packages) and options.yum_rollback: logging.debug(MSG_ERROR_NO_ROLLBACK_AVAIL) print MSG_ERROR_NO_ROLLBACK_AVAIL print MSG_ERROR_CHECK_LOG % logFile sys.exit(2) # Update is related to database if: # 1. database related package is updated # 2. CA upgrade is going to alter parameters within database # 3. UUID update will take place updateRelatedToDB = False for package in RPM_BACKEND, RPM_DBSCRIPTS: if package in name_packages: updateRelatedToDB = True logging.debug("related to database package %s" % package) updateRelatedToDB = updateRelatedToDB or ca.mayUpdateDB() updateRelatedToDB = updateRelatedToDB or hostids # No rollback in this case try: # We ask the user before stoping ovirt-engine or take command line option if options.unattended_upgrade or checkEngine(engineService): # Stopping engine runFunc(stopEngineService, MSG_INFO_STOP_ENGINE % engineService) if updateRelatedToDB: runFunc([[ stopDbRelatedServices, etlService, notificationService ]], MSG_INFO_STOP_DB) if not options.ignore_tasks: # Check that there are no running tasks/compensations try: checkRunningTasks() # If something went wrong, restart DB services and the engine except: runFunc([[ startDbRelatedServices, etlService, notificationService ]], MSG_INFO_START_DB) runFunc(startEngineService, MSG_INFO_START_ENGINE % engineService) raise else: # This means that user chose not to stop ovirt-engine logging.debug("exiting gracefully") print MSG_INFO_STOP_INSTALL_EXIT sys.exit(0) # Preupgrade checks runFunc(preupgradeFunc, MSG_INFO_PREUPGRADE) # Backup DB if updateRelatedToDB: runFunc([db.backup], MSG_INFO_BACKUP_DB) runFunc([[db.rename, DB_NAME_TEMP]], MSG_INFO_RENAME_DB) except Exception as e: print e raise # In case of failure, do rollback try: # yum update runFunc(upgradeFunc, MSG_INFO_YUM_UPDATE) # check if update is relevant to db update if updateRelatedToDB: # Update the db and restore its name back runFunc([db.update], MSG_INFO_DB_UPDATE) runFunc([[db.rename, basedefs.DB_NAME]], MSG_INFO_RESTORE_DB) # Bring up any services we shut down before db upgrade startDbRelatedServices(etlService, notificationService) if startVersion.startswith("3.1"): runFunc([utils.updateEngineSysconfig], MSG_INFO_UPDATE_ENGINE_SYSCONFIG) messages.append(MSG_OVIRT_ENGINE_RECREATED) # CA restore runFunc([ca.prepare], MSG_INFO_PKI_PREPARE) # post install conf runFunc(postFunc, MSG_INFO_RUN_POST) except: logging.error(traceback.format_exc()) logging.error("Rolling back update") print MSG_ERROR_UPGRADE print MSG_INFO_REASON % (sys.exc_info()[1]) # CA restore runFunc([ca.rollback], MSG_INFO_PKI_ROLLBACK) # allow db restore if updateRelatedToDB: try: runFunc([db.restore], MSG_INFO_DB_RESTORE) except: # This Exception have already been logged, so just pass along pass raise finally: # start engine runFunc([startEngine], MSG_INFO_START_ENGINE % engineService) # restart httpd runFunc([restartHttpd], "Restarting web server") # Print log location on success addAdditionalMessages(etlService.isServiceAvailable()) print "\n%s\n" % MSG_INFO_UPGRADE_OK printMessages()