def _checkPreRequisites(): # Verify httpd and mod_ssl are installed in the system logging.debug("Checking httpd and mod_ssl are installed as prerequisites") cmd = ["rpm","-q","httpd"] out, rc = utils.execCmd(cmd, None, True, output_messages.ERR_HTTPD_NOT_INSTALLED) cmd = ["rpm","-q","mod_ssl"] out, rc = utils.execCmd(cmd, None, True, output_messages.ERR_MOD_SSL_NOT_INSTALLED)
def restore(self): # run psql -U engine -h host -p port -d template1 -f <backup directory>/<backup_file> # If DB was renamed, restore it if self.updated or self.dbrenamed: logging.debug("DB Restore started") # If we're here, upgrade failed. Drop temp DB. cmd = [ basedefs.EXEC_DROPDB, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, self.name, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_DROP_DB) # Restore cmd = [ basedefs.EXEC_PSQL, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "-d", basedefs.DB_TEMPLATE, "-f", self.sqlfile, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_RESTORE_DB, envDict=utils.getPgPassEnv()) logging.debug("DB Restore completed successfully") else: logging.debug("No DB Restore needed")
def backup(self): """ Backup db using pg_dump """ # pg_dump -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U postgres --format=p -f $dir/$file dbname logging.debug("DB Backup started") # .pgpass update cmd = [ basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--disable-dollar-quoting", "--disable-triggers", "-U", DB_ADMIN, "-h", DB_HOST, "-p", DB_PORT, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME, ] utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_BACKUP_DB, envDict=self.env) logging.debug("DB Backup completed successfully")
def _startJbossService(): logging.debug("Enabling the JBoss service") try: cmd = ["/sbin/service","jboss-as","stop"] out, rc = utils.execCmd(cmd, None, True, output_messages.ERR_FAILED_STP_JBOSS_SERVICE) cmd = ["/sbin/service","jboss-as","start"] utils.execCmd(cmd, None, True, output_messages.ERR_FAILED_START_JBOSS_SERVICE) except: logging.error(traceback.format_exc()) raise Exception(output_messages.ERR_FAILED_TO_RESTART_JBOSS_SERVICE)
def setSELinuxContextForDir(path, contextName): logging.debug("setting selinux context for %s" % (path)) if path.endswith("/"): path = path[:-1] pattern = "%s(/.*)?" % (path,) # Run semanage cmd = [basedefs.EXEC_SEMANAGE, "fcontext", "-a", "-t", SELINUX_RW_LABEL, pattern] utils.execCmd(cmd, None, True, output_messages.ERR_SET_SELINUX_NFS_SHARE) cmd = [basedefs.EXEC_RESTORECON, "-r", path] utils.execCmd(cmd, None, True, output_messages.ERR_REFRESH_SELINUX_CONTEXT)
def _startHttpdService(): logging.debug("Enabling the httpd service") try: cmd = ["/sbin/chkconfig","httpd","on"] out, rc = utils.execCmd(cmd, None, True, output_messages.ERR_FAILED_CHKCFG_HTTPD) cmd = ["/sbin/service","httpd","stop"] out, rc = utils.execCmd(cmd, None, False) cmd = ["/sbin/service","httpd","start"] utils.execCmd(cmd, None, True, output_messages.ERR_RESTARTING_HTTPD_SERVICE) except: logging.error(traceback.format_exc()) raise Exception(output_messages.ERR_FAILED_TO_START_HTTPD_SERVICE)
def setSELinuxContextForDir(path, contextName): logging.debug("setting selinux context for %s" % (path)) if path.endswith("/"): path = path[:-1] pattern = "%s(/.*)?" % (path, ) # Run semanage cmd = [ basedefs.EXEC_SEMANAGE, "fcontext", "-a", "-t", SELINUX_RW_LABEL, pattern ] utils.execCmd(cmd, None, True, output_messages.ERR_SET_SELINUX_NFS_SHARE) cmd = [basedefs.EXEC_RESTORECON, "-r", path] utils.execCmd(cmd, None, True, output_messages.ERR_REFRESH_SELINUX_CONTEXT)
def restore(self): #psql -U postgres -h host -p port -f <backup directory>/<backup_file> if self.updated: logging.debug("DB Restore started") # If we're here, upgrade failed. Drop temp DB. cmd = [basedefs.EXEC_DROPDB, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, self.name] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_DROP_DB) # Restore cmd = [basedefs.EXEC_PSQL, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "-f", self.sqlfile] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_RESTORE_DB) logging.debug("DB Restore completed successfully") else: logging.debug("No DB Restore needed")
def checkAndSetHttpdPortPolicy(port): def parsePorts(portsStr): ports = [] for part in portsStr.split(","): part = part.strip().split("-") if len(part) > 1: for port in range(int(part[0]), int(part[1])): ports.append(port) else: ports.append(int(part[0])) return ports newPort = int(port) cmd = [ basedefs.EXEC_SEMANAGE, "port", "-l", ] out, rc = utils.execCmd(cmdList=cmd) #, "-t", "http_port_t"]) if rc: return False httpPortsList = [] pattern = re.compile("^http_port_t\s*tcp\s*([0-9, \-]*)$") for line in out.splitlines(): httpPortPolicy = re.match(pattern, line) if httpPortPolicy: httpPortsList = parsePorts(httpPortPolicy.groups()[0]) logging.debug("http_port_t = %s" % (httpPortsList)) if newPort in httpPortsList: return True else: cmd = [ basedefs.EXEC_SEMANAGE, "port", "-a", "-t", "http_port_t", "-p", "tcp", "%d" % (newPort), ] out, rc = utils.execCmd(cmdList=cmd, failOnError=False, usePipeFiles=True) if rc: logging.error(out) return False return True
def checkJbossService(): """ Ask user to stop jboss service before upgrading ovirt-engine returns: true if user choose to stop jboss false otherwise """ logging.debug("checking the status of jbossas service") cmd = [basedefs.EXEC_SERVICE, basedefs.JBOSS_SERVICE_NAME, "status"] output, rc = utils.execCmd(cmd, None, False) if rc == 0: logging.debug("jbossas service is up and running") print MSG_ALERT_STOP_JBOSS answer = askYesNo(INFO_Q_STOP_JBOSS) # If user choose yes -> return true (stop jbossas) if answer: return True else: logging.debug("User chose not to stop jboss") return False elif rc == 1: # Proc is dead, pid exists raise Exception(MSG_ERROR_JBOSS_PID) elif rc == 3: # If jboss is not running, we don't need to stop it return True else: raise Exception(MSG_ERR_FAILED_STATUS_JBOSS_SERVICE)
def backup(self): # pg_dump -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U postgres -h host -p port --format=p -f $dir/$file ovirt-engine logging.debug("DB Backup started") #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\ #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, self.sqlfile, basedefs.DB_NAME) cmd = [ basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--column-inserts", "--disable-dollar-quoting", "--disable-triggers", "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_BACKUP_DB) logging.debug("DB Backup completed successfully")
def update(self): cwd = os.getcwd() os.chdir(basedefs.DIR_DB_SCRIPTS) # Make sure we always returning to cwd try: self.updated = True logging.debug("DB Update started") # Perform the upgrade # ./upgrade.sh -s ${SERVERNAME} -p ${PORT} -u ${USERNAME} -d ${DATABASE}; dbupgrade = os.path.join(basedefs.DIR_DB_SCRIPTS, basedefs.FILE_DB_UPGRADE_SCRIPT) cmd = [ dbupgrade, "-s", SERVER_NAME, "-p", SERVER_PORT, "-u", SERVER_ADMIN, "-d", self.name, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_UPDATE_DB) logging.debug("DB Update completed successfully") finally: os.chdir(cwd)
def drop(self): """ Drops db using dropdb """ logging.debug("DB Drop started") # Block New connections and disconnect active ones - only on local installation. if utils.localHost(DB_HOST): utils.clearDbConnections(basedefs.DB_NAME) # Drop DBs - including the tempoarary ones created during upgrade operations # go over all dbs in the list of temp DBs and remove them for dbname in utils.listTempDbs(): cmd = [ basedefs.EXEC_DROPDB, "-w", "-U", DB_ADMIN, "-h", DB_HOST, "-p", DB_PORT, dbname, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=False, msg=MSG_ERROR_DROP_DB, envDict=self.env) if rc: logging.error(MSG_ERROR_DROP_DB % dbname) raise Exception(MSG_ERROR_DROP_DB % dbname) self.dropped = True logging.debug("DB Drop completed successfully")
def getLatestTid(self, updateOnly=False): logging.debug("Yum getLatestTid started") tid = None # Get the list cmd = [ YUM_EXEC, "history", "list", basedefs.ENGINE_RPM_NAME, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_YUM_HISTORY_LIST) # Parse last tid for line in output.splitlines(): lsplit = line.split("|") if len(lsplit) > 3: if updateOnly: if 'Update' in lsplit[3].split() or "U" in lsplit[3].split( ): tid = lsplit[0].strip() break else: if "Action" not in lsplit[3]: # Don't get header of output tid = lsplit[0].strip() break if tid is None: raise ValueError(MSG_ERROR_YUM_HISTORY_GETLAST) logging.debug("Found TID: %s" % (tid)) logging.debug("Yum getLatestTid completed successfully") return tid
def drop(self): """ Drops db using dropdb """ logging.debug("DB Drop started") # Block New connections and disconnect active ones - only on local installation. if utils.localHost(DB_HOST): utils.clearDbConnections(basedefs.DB_NAME) # Drop DBs - including the tempoarary ones created during upgrade operations # go over all dbs in the list of temp DBs and remove them for dbname in utils.listTempDbs(): cmd = [ basedefs.EXEC_DROPDB, "-w", "-U", DB_ADMIN, "-h", DB_HOST, "-p", DB_PORT, dbname ] output, rc = utils.execCmd(cmd, None, False, MSG_ERROR_DROP_DB) if rc: logging.error( "DB drop operation failed. Check that there are no active connection to the '%s' DB." % dbname) raise Exception(MSG_ERROR_DROP_DB) self.dropped = True logging.debug("DB Drop completed successfully")
def getLatestTid(self, updateOnly=False): logging.debug("Yum getLatestTid started") tid = None # Get the list cmd = [YUM_EXEC, "history", "list", basedefs.ENGINE_RPM_NAME] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_YUM_HISTORY_LIST) # Parse last tid for line in output.splitlines(): lsplit = line.split("|") if len(lsplit) > 3: if updateOnly: if 'Update' in lsplit[3].split() or "U" in lsplit[3].split(): tid = lsplit[0].strip() break else: if "Action" not in lsplit[3]: # Don't get header of output tid = lsplit[0].strip() break if tid is None: raise ValueError(MSG_ERROR_YUM_HISTORY_GETLAST) logging.debug("Found TID: %s" %(tid)) logging.debug("Yum getLatestTid completed successfully") return tid
def rollback(self): upgradeTid = self.getLatestTid(True) if int(upgradeTid) <= int(self.tid): logging.error( "Mismatch in yum TID, target TID (%s) is not higher than %s" % (upgradeTid, self.tid)) raise Exception(MSG_ERROR_YUM_TID) if self.updated: self._unlock() try: # yum history undo 17 # Do rollback only if update went well logging.debug("Yum rollback started") cmd = [ YUM_EXEC, "history", "-y", "undo", upgradeTid, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_YUM_HISTORY_UNDO) logging.debug("Yum rollback completed successfully") finally: self._lock() else: logging.debug("No rollback needed")
def backup(self): """ Backup db using pg_dump """ # pg_dump -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U postgres --format=p -f $dir/$file dbname logging.debug("DB Backup started") cmd = [basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--column-inserts", "--disable-dollar-quoting", "--disable-triggers", "-U", DB_ADMIN, "-h", DB_HOST, "-p", DB_PORT, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME] utils.execCmd(cmd, None, True, MSG_ERROR_BACKUP_DB, []) logging.debug("DB Backup completed successfully")
def stopJboss(): logging.debug("stopping jboss service.") cmd = [basedefs.EXEC_SERVICE, basedefs.JBOSS_SERVICE_NAME, "stop"] output, rc = utils.execCmd(cmd, None, True, MSG_ERR_FAILED_STP_JBOSS_SERVICE) # JBoss service sometimes return zero rc even if service is still up if "[FAILED]" in output and "Timeout: Shutdown command was sent, but process is still running" in output: raise OSError(MSG_ERR_FAILED_JBOSS_SERVICE_STILL_RUN)
def _validateRpmLockList(self): rpmLockList = [] for rpmName in basedefs.RPM_LOCK_LIST.split(): cmd = [basedefs.EXEC_RPM, "-q", rpmName] output, rc = utils.execCmd(cmd) if rc == 0: rpmLockList.append(rpmName) return rpmLockList
def stopJboss(): logging.debug("stoping jboss service.") cmd = [basedefs.EXEC_SERVICE, basedefs.JBOSS_SERVICE_NAME, "stop"] output, rc = utils.execCmd(cmd, None, True, MSG_ERR_FAILED_STP_JBOSS_SERVICE, []) # JBoss service sometimes return zero rc even if service is still up if "[FAILED]" in output and "Timeout: Shutdown command was sent, but process is still running" in output: raise OSError(MSG_ERR_FAILED_JBOSS_SERVICE_STILL_RUN)
def editPgpass(pgpass=""): """ Hack to replace engine database with * for user engine """ logging.debug("Editing file: " + pgpass) cmd = ["/bin/sed", "-i", "-e", "s/:engine:engine/:*:engine/", pgpass] output, rc = utils.execCmd(cmdList=cmd, failOnError=False)
def drop(self): """ Drops db using dropdb """ logging.debug("DB Drop started") cmd = [basedefs.EXEC_DROPDB, "-w", "-U", basedefs.DB_ADMIN, basedefs.DB_NAME] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_DROP_DB, []) self.dropped = True logging.debug("DB Drop completed successfully")
def backup(self): # pg_dump -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U postgres -h host -p port --format=p -f $dir/$file ovirt-engine logging.debug("DB Backup started") #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\ #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, self.sqlfile, basedefs.DB_NAME) cmd = [basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--column-inserts", "--disable-dollar-quoting", "--disable-triggers", "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_BACKUP_DB) logging.debug("DB Backup completed successfully")
def restore(self): # run psql -U engine -h host -p port -d template1 -f <backup directory>/<backup_file> # If DB was renamed, restore it if self.updated or self.dbrenamed: logging.debug("DB Restore started") # If we're here, upgrade failed. Drop temp DB. cmd = [ basedefs.EXEC_DROPDB, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, self.name, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_DROP_DB, envDict=utils.getPgPassEnv()) # Restore cmd = [ basedefs.EXEC_PSQL, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "-d", basedefs.DB_TEMPLATE, "-f", self.sqlfile, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_RESTORE_DB, envDict=utils.getPgPassEnv()) logging.debug("DB Restore completed successfully") else: logging.debug("No DB Restore needed")
def backup(self): """ Backup db using pg_dump """ # pg_dump -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U postgres --format=p -f $dir/$file dbname logging.debug("DB Backup started") cmd = [basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--column-inserts", "--disable-dollar-quoting", "--disable-triggers", "-U", basedefs.DB_ADMIN, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_BACKUP_DB, []) logging.debug("DB Backup completed successfully")
def startEngine(): logging.debug("starting jboss service.") cmd = [ basedefs.EXEC_SERVICE, basedefs.ENGINE_SERVICE_NAME, "start", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERR_FAILED_START_JBOSS_SERVICE)
def stopEngine(service=basedefs.ENGINE_SERVICE_NAME): logging.debug("stopping %s service.", service) cmd = [ basedefs.EXEC_SERVICE, service, "stop", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERR_FAILED_STP_JBOSS_SERVICE)
def restartHttpd(service=basedefs.HTTPD_SERVICE_NAME): logging.debug("restart %s service.", service) cmd = [ basedefs.EXEC_SERVICE, service, "restart", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg="Can't restart HTTPD service")
def checkAndSetHttpdPortPolicy(port): def parsePorts(portsStr): ports = [] for part in portsStr.split(","): part = part.strip().split("-") if len(part) > 1: for port in range(int(part[0]),int(part[1])): ports.append(port) else: ports.append(int(part[0])) return ports newPort = int(port) cmd = [ basedefs.EXEC_SEMANAGE, "port", "-l", ] out, rc = utils.execCmd(cmdList=cmd) #, "-t", "http_port_t"]) if rc: return False httpPortsList = [] pattern = re.compile("^http_port_t\s*tcp\s*([0-9, \-]*)$") for line in out.splitlines(): httpPortPolicy = re.match(pattern, line) if httpPortPolicy: httpPortsList = parsePorts(httpPortPolicy.groups()[0]) logging.debug("http_port_t = %s"%(httpPortsList)) if newPort in httpPortsList: return True else: cmd = [ basedefs.EXEC_SEMANAGE, "port", "-a", "-t", "http_port_t", "-p", "tcp", "%d"%(newPort), ] out, rc = utils.execCmd(cmdList=cmd, failOnError=False, usePipeFiles=True) if rc: logging.error(out) return False return True
def stopEngine(): logging.debug("stoping %s service." % basedefs.ENGINE_SERVICE_NAME) cmd = [ basedefs.EXEC_SERVICE, basedefs.ENGINE_SERVICE_NAME, "stop", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERR_FAILED_STP_ENGINE_SERVICE) # JBoss service sometimes return zero rc even if service is still up if "[FAILED]" in output and "Timeout: Shutdown command was sent, but process is still running" in output: raise OSError(MSG_ERR_FAILED_ENGINE_SERVICE_STILL_RUN)
def _lock(self): logging.debug("Yum lock started") # Create RPM lock list cmd = [ basedefs.EXEC_RPM, "-q", ] + self._validateRpmLockList() output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_YUM_LOCK) with open(basedefs.FILE_YUM_VERSION_LOCK, 'a') as yumlock: yumlock.write(output) logging.debug("Yum lock completed successfully")
def validatePing(param, options=[]): """ Check that provided host answers to ping """ if validateStringNotEmpty(param): out, rc = utils.execCmd(["/bin/ping", "-c 1", "%s" % param]) if rc == 0: return True print "\n" + output_messages.ERR_PING + ".\n" return False
def _lockRpmVersion(): """ Enters rpm versions into yum version-lock """ logging.debug("Locking rpms in yum-version-lock") cmd = [basedefs.EXEC_RPM, "-q"] + basedefs.RPM_LOCK_LIST.split() output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=output_messages.ERR_YUM_LOCK) with open(basedefs.FILE_YUM_VERSION_LOCK, "a") as f: for rpm in output.splitlines(): f.write(rpm + "\n")
def restore(self): #psql -U postgres -h host -p port -f <backup directory>/<backup_file> if self.updated: logging.debug("DB Restore started") # If we're here, upgrade failed. Drop temp DB. cmd = [ basedefs.EXEC_DROPDB, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, self.name ] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_DROP_DB) # Restore cmd = [ basedefs.EXEC_PSQL, "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "-f", self.sqlfile ] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_RESTORE_DB) logging.debug("DB Restore completed successfully") else: logging.debug("No DB Restore needed")
def update(self): self.tid = self.getLatestTid(False) self._unlock() try: # yum update ovirt-engine # TODO: Run test transaction logging.debug("Yum update started") cmd = [YUM_EXEC, "update", "-q", "-y"] + RPM_LIST.split() output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_YUM_UPDATE) logging.debug("Yum update completed successfully") self.updated = True finally: self._lock()
def _lockRpmVersion(): """ Enters rpm versions into yum version-lock """ logging.debug("Locking rpms in yum-version-lock") cmd = [ basedefs.EXEC_RPM, "-q", ] + basedefs.RPM_LOCK_LIST.split() output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=output_messages.ERR_YUM_LOCK) with open(basedefs.FILE_YUM_VERSION_LOCK, "a") as f: for rpm in output.splitlines(): f.write(rpm + "\n")
def validate_ping(param, options=None): """ Raises ParamValidationError if provided host does not answer to ICMP echo request. """ options = options or [] # TO-DO: to be more flexible, remove this and exit in case param is empty validate_not_empty(param) cmd = ["/bin/ping", "-c", "1", str(param)] out, rc = utils.execCmd(cmdList=cmd) if rc != 0: logging.debug('validate_ping(%s, options=%s) failed.' % (param, options)) msg = 'Given host is unreachable: %s' raise ParamValidationError(msg % param)
def deployDbAsyncTasks(dbName=basedefs.DB_NAME): # Deploy DB functionality first cmd = [ basedefs.EXEC_PSQL, "-U", SERVER_ADMIN, "-f", basedefs.FILE_DB_ASYNC_TASKS, "-d", dbName, ] out, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg="Error updating DB for getting async_tasks", envDict=utils.getPgPassEnv())
def backup(self): logging.debug("DB Backup started") #cmd = "%s -C -E UTF8 --column-inserts --disable-dollar-quoting --disable-triggers -U %s -h %s -p %s --format=p -f %s %s"\ #%(basedefs.EXEC_PGDUMP, SERVER_ADMIN, SERVER_HOST, SERVER_PORT, self.sqlfile, basedefs.DB_NAME) cmd = [ basedefs.EXEC_PGDUMP, "-C", "-E", "UTF8", "--disable-dollar-quoting", "--disable-triggers", "-U", SERVER_ADMIN, "-h", SERVER_NAME, "-p", SERVER_PORT, "--format=p", "-f", self.sqlfile, basedefs.DB_NAME, ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERROR_BACKUP_DB, envDict=utils.getPgPassEnv()) logging.debug("DB Backup completed successfully")
def update(self): cwd = os.getcwd() os.chdir(basedefs.DIR_DB_SCRIPTS) # Make sure we always returning to cwd try: self.updated = True logging.debug("DB Update started") # Perform the upgrade # ./upgrade.sh -s ${SERVERNAME} -p ${PORT} -u ${USERNAME} -d ${DATABASE}; dbupgrade = os.path.join(basedefs.DIR_DB_SCRIPTS, basedefs.FILE_DB_UPGRADE_SCRIPT) cmd = [dbupgrade, "-s", SERVER_NAME, "-p", SERVER_PORT, "-u", SERVER_ADMIN, "-d", self.name] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_UPDATE_DB) logging.debug("DB Update completed successfully") finally: os.chdir(cwd)
def wereHttpdConfFilesChanged(): logging.debug("checking whether HTTPD config files were changed") conf_files = [basedefs.FILE_HTTPD_SSL_CONFIG, basedefs.FILE_HTTPD_CONF] cmd = [ basedefs.EXEC_RPM, "-V", "--nomtime", "httpd", "mod_ssl", ] (output, rc) = utils.execCmd(cmdList=cmd) for line in output.split(os.linesep): if len(line) > 0: changed_file = line.split()[-1] if changed_file in conf_files: logging.debug("HTTPD config file %s was changed" %(changed_file)) return True return False
def rollback(self): upgradeTid = self.getLatestTid(True) if int(upgradeTid) <= int(self.tid): logging.error("Mismatch in yum TID, target TID (%s) is not higher than %s" %(upgradeTid, self.tid)) raise Exception(MSG_ERROR_YUM_TID) if self.updated: self._unlock() try: # yum history undo 17 # Do rollback only if update went well logging.debug("Yum rollback started") cmd = [YUM_EXEC, "history", "-y", "undo", upgradeTid] output, rc = utils.execCmd(cmd, None, True, MSG_ERROR_YUM_HISTORY_UNDO) logging.debug("Yum rollback completed successfully") finally: self._lock() else: logging.debug("No rollback needed")
def checkEngine(service=basedefs.ENGINE_SERVICE_NAME): """ Ask user to stop ovirt-engine service before upgrading ovirt-engine returns: true if user choose to stop ovirt-engine false otherwise """ logging.debug("checking the status of ovirt-engine service") cmd = [ basedefs.EXEC_SERVICE, service , "status", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=False) if rc == 0: logging.debug("ovirt-engine service is up and running") print MSG_ALERT_STOP_ENGINE answer = utils.askYesNo(INFO_Q_PROCEED) # If user choose yes -> return true (stop ovirt-engine) if answer: return True else: logging.debug("User chose not to stop ovirt-engine") return False elif rc == 1: # Proc is dead, pid exists raise Exception(MSG_ERROR_ENGINE_PID) elif rc == 3: # If ovirt-engine is not running, we don't need to stop it return True else: raise Exception(MSG_ERR_FAILED_STATUS_ENGINE_SERVICE)
def startJboss(): logging.debug("starting jboss service.") cmd = [basedefs.EXEC_SERVICE, basedefs.JBOSS_SERVICE_NAME, "start"] output, rc = utils.execCmd(cmd, None, True, MSG_ERR_FAILED_START_JBOSS_SERVICE)
def _configureSelinuxBoolean(): logging.debug("Enable httpd_can_network_connect boolean") cmd = ["setsebool","-P","httpd_can_network_connect","1"] out, rc = utils.execCmd(cmd, None, True, output_messages.ERR_FAILED_UPDATING_SELINUX_BOOLEAN)
def startEngine(): logging.debug("starting %s service.", basedefs.ENGINE_SERVICE_NAME) cmd = [ basedefs.EXEC_SERVICE, basedefs.ENGINE_SERVICE_NAME, "start", ] output, rc = utils.execCmd(cmdList=cmd, failOnError=True, msg=MSG_ERR_FAILED_START_ENGINE_SERVICE)