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 _validateString(string, minLen, maxLen, regex=".*"): """ Generic func to verify a string match its min/max length and doesn't contain illegal chars The func returns various return codes according to the error plus a default error message the calling func can decide if to use to default error msg or to use a more specific one according the RC. Return codes: 1 - string length is less than min 2 - string length is more tham max 3 - string contain illegal chars 0 - success """ # String length is less than minimum allowed if len(string) < minLen: msg = output_messages.INFO_STRING_LEN_LESS_THAN_MIN % (minLen) return(msg, 1) # String length is more than max allowed elif len(string) > maxLen: msg = output_messages.INFO_STRING_EXCEEDS_MAX_LENGTH % (maxLen) return(msg, 2) # String contains illegal chars elif not utils.verifyStringFormat(string, regex): return(output_messages.INFO_STRING_CONTAINS_ILLEGAL_CHARS, 3) else: # Success return (None, 0)
def stopDbRelatedServices(etlService, notificationService): """ shut down etl and notifier services in order to disconnect any open sessions to the db """ # If the ovirt-engine-etl service is installed, then try and stop it. if etlService.isServiceAvailable(): try: etlService.stop(True) except: logging.warn("Failed to stop ovirt-engine-etl") logging.warn(traceback.format_exc()) messages.append(MSG_ERR_FAILED_STOP_SERVICE % "ovirt-engine-etl") # If the ovirt-engine-notifierd service is up, then try and stop it. if notificationService.isServiceAvailable(): try: (status, rc) = notificationService.status() if utils.verifyStringFormat(status, ".*running.*"): logging.debug("stopping ovirt-engine-notifierd service..") notificationService.stop() except: logging.warn("Failed to stop ovirt-engine-notifierd service") logging.warn(traceback.format_exc()) messages.append(MSG_ERR_FAILED_STOP_SERVICE % "ovirt-engine-notifierd")
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 _validateString(string, minLen, maxLen, regex=".*"): """ Generic func to verify a string match its min/max length and doesn't contain illegal chars The func returns various return codes according to the error plus a default error message the calling func can decide if to use to default error msg or to use a more specific one according the RC. Return codes: 1 - string length is less than min 2 - string length is more tham max 3 - string contain illegal chars 0 - success """ # String length is less than minimum allowed if len(string) < minLen: msg = output_messages.INFO_STRING_LEN_LESS_THAN_MIN % (minLen) return (msg, 1) # String length is more than max allowed elif len(string) > maxLen: msg = output_messages.INFO_STRING_EXCEEDS_MAX_LENGTH % (maxLen) return (msg, 2) # String contains illegal chars elif not utils.verifyStringFormat(string, regex): return (output_messages.INFO_STRING_CONTAINS_ILLEGAL_CHARS, 3) else: # Success return (None, 0)
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)) # 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(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 else: raise Exception(MSG_ERROR_CONNECT_DB) return True
def _isPathInExportFs(path): if not os.path.exists(basedefs.FILE_ETC_EXPORTS): return False file = open(basedefs.FILE_ETC_EXPORTS) fileContent = file.readlines() file.close() for line in fileContent: if utils.verifyStringFormat(line, "^%s\s+.+" % (path)): return True return False
def isHealthPageUp(): """ check if project health page is and accesible will throw exception on error and not return a value """ health_url = JBOSS_HEALTH_URL % (controller.CONF["HOST_FQDN"], controller.CONF["HTTP_PORT"]) logging.debug("Checking JBoss status.") content = getUrlContent(health_url) if content and utils.verifyStringFormat(content, ".*DB Up.*"): logging.info("JBoss is up and running.") return True else: logging.error(ERROR_JBOSS_STATUS) raise Exception(ERROR_JBOSS_STATUS)
def validateMountPoint(path): logging.info("validating %s as a valid mount point" % (path)) if not utils.verifyStringFormat(path, "^\/[\w\_\-\s]+(\/[\w\_\-\s]+)*\/?$"): print output_messages.INFO_VAL_PATH_NAME_INVALID return False if _isPathInExportFs(path): print output_messages.INFO_VAL_PATH_NAME_IN_EXPORTS return False if os.path.exists(path) and len(os.listdir(path)): print output_messages.INFO_VAR_PATH_NOT_EMPTY % path return False if not _isPathWriteable(_getBasePath(path)): print output_messages.INFO_VAL_PATH_NOT_WRITEABLE return False return True
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 validateMountPoint(param, options=[]): logging.info("validating %s as a valid mount point" % (param)) if not utils.verifyStringFormat(param, "^\/[\w\_\-\s]+(\/[\w\_\-\s]+)*\/?$"): print output_messages.INFO_VAL_PATH_NAME_INVALID return False if _isPathInExportFs(param): print output_messages.INFO_VAL_PATH_NAME_IN_EXPORTS return False if os.path.exists(param) and len(os.listdir(param)): print output_messages.INFO_VAR_PATH_NOT_EMPTY % param return False basePath = _getBasePath(param) if not _isPathWriteable(basePath): print output_messages.INFO_VAL_PATH_NOT_WRITEABLE return False availableSpace = utils.getAvailableSpace(basePath) if availableSpace < basedefs.CONST_MINIMUM_SPACE_ISODOMAIN: print output_messages.INFO_VAL_PATH_SPACE % (str(availableSpace), str(basedefs.CONST_MINIMUM_SPACE_ISODOMAIN)) return False return True