def exists(self): """ check if db exists """ logging.debug("verifying is db exists") # Making sure postgresql service is up postgresql = utils.Service("postgresql") postgresql.conditionalStart() try: # We want to make check if postgresql service is up logging.debug("making sure postgresql service is up") utils.retry(utils.checkIfRhevmDbIsUp, tries=5, timeout=15, sleep=3) except: # If we're here, it means something is wrong, either there is a real db error # or the db is not installed, let's check logging.debug("checking if db is already installed..") (out, rc) = utils.execSqlCommand(basedefs.DB_ADMIN, basedefs.DB_NAME, "select 1") if (rc != 0): if utils.verifyStringFormat(out,".*FATAL:\s*database\s*\"%s\"\s*does not exist" % (PREFIX)): # This means that the db is not installed, so we return false return False return True
def exists(self): """ check that db exists """ logging.debug("verifying that db '%s' exists" % (basedefs.DB_NAME)) # Making sure postgresql service is up - only on local installation if utils.localHost(DB_HOST): postgresql = utils.Service("postgresql") postgresql.conditionalStart() try: # We want to make check that we can connect to basedefs.DB_NAME DB logging.debug("making sure postgresql service is up") utils.retry(utils.checkIfDbIsUp, tries=5, timeout=15, sleep=3) except: # If we're here, it means something is wrong, either there is a real db error # or the db is not installed, let's check logging.debug("checking if db is already installed..") out, rc = utils.execRemoteSqlCommand(DB_ADMIN, DB_HOST, DB_PORT, basedefs.DB_NAME, "select 1") if rc != 0: if utils.verifyStringFormat( out, ".*FATAL:\s*database\s*\"%s\"\s*does not exist" % (PREFIX)): # This means that the db is not installed, so we return false return False return True
def restartPostgresql(): """ restart the postgresql service """ logging.debug("Restarting the postgresql service") postgresql = utils.Service("postgresql") postgresql.stop(True) postgresql.start(True) # We want to make sure the postgres service is up utils.retry(utils.checkIfRhevmDbIsUp, tries=10, timeout=30, sleep=3)
def validateOverrideHttpdConfAndChangePortsAccordingly(param, options=[]): """ This validation function is specific for the OVERRIDE_HTTPD_CONF param and it does more than validating the answer. It actually changes the default HTTP/S ports in case the user choose not to override the httpd configuration. """ logging.info("validateOverrideHttpdConfAndChangePortsAccordingly %s as part of %s"%(param, options)) retval = validateOptions(param, options) if retval and param.lower() == "no": logging.debug("Changing HTTP_PORT & HTTPS_PORT to the default jboss values (8700 & 8701)") controller = Controller() utils.setHttpPortsToNonProxyDefault(controller) elif retval: #stopping httpd service (in case it's up) when the configuration can be overridden logging.debug("stopping httpd service") utils.Service(basedefs.HTTPD_SERVICE_NAME).stop() return retval
def exists(self): """ check that db exists """ logging.debug("verifying that db '%s' exists" % (basedefs.DB_NAME)) # Checking whether pgpass file exists. If not, # we cannot cleanup DB, so return False. if not os.path.exists(basedefs.DB_PASS_FILE): logging.info(MSG_ERR_CANT_FIND_PGPASS_FILE) return False # Making sure postgresql service is up - only on local installation if utils.localHost(DB_HOST): postgresql = utils.Service("postgresql") postgresql.conditionalStart() try: # We want to make check that we can connect to basedefs.DB_NAME DB logging.debug("Checking that DB '%s' exists", basedefs.DB_NAME) utils.retry(utils.checkIfDbIsUp, tries=5, timeout=15, sleep=3) except: # If we're here, it means something is wrong, either there is a real db error # or the db is not installed, let's check logging.debug("checking if db is already installed..") out, rc = utils.execRemoteSqlCommand( userName=DB_ADMIN, dbHost=DB_HOST, dbPort=DB_PORT, dbName=basedefs.DB_NAME, sqlQuery="select 1", ) if rc != 0: if utils.verifyStringFormat( out, ".*FATAL:\s*database\s*\"%s\"\s*does not exist" % (PREFIX)): # This means that the db is not installed, so we return false return False else: raise Exception(MSG_ERROR_CONNECT_DB) return True
def startLibvirt(): """ Start service libvirt """ libvirtService = utils.Service("libvirtd") # Check status and return if up output, rc = libvirtService.status() if rc == 0: logging.info(INFO_LIBVIRT_START) return # Otherwise, start the service output, rc = libvirtService.start(True) cycle = 1 while cycle <= MAX_CYCLES: output, rc = libvirtService.status() if rc == 0: logging.info(INFO_LIBVIRT_START) return cycle += 1 time.sleep(PAUSE) raise Exception(ERROR_LIBVIRT_START)
def stopNotifier(): logging.debug("stoping engine-notifierd service.") notifier = utils.Service(basedefs.NOTIFIER_SERVICE_NAME) if notifier.isServiceAvailable(): notifier.stop(True)
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") # 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()