Alex Lourie has uploaded a new change for review. Change subject: packaging: Added checking DB state before upgrade ......................................................................
packaging: Added checking DB state before upgrade This patch uses the fkvalidator.sh utility to check possible problems with DB before upgrading. If the utility finds inconsistencies, it will suggest user to clear them. Change-Id: Ief0e65231bb42b569734cdd2fa6491b645491f98 Bug-Url: https://bugzilla.redhat.com/893459 Signed-off-by: Alex Lourie <alou...@redhat.com> --- M packaging/fedora/setup/basedefs.py M packaging/fedora/setup/engine-upgrade.py 2 files changed, 66 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/12/12512/1 diff --git a/packaging/fedora/setup/basedefs.py b/packaging/fedora/setup/basedefs.py index 2957fb7..59dcf85 100644 --- a/packaging/fedora/setup/basedefs.py +++ b/packaging/fedora/setup/basedefs.py @@ -162,6 +162,7 @@ EXEC_SEMANAGE="/usr/sbin/semanage" EXEC_KEYTOOL="/usr/bin/keytool" EXEC_TASK_CLEANER = "%s/ovirt-engine/scripts/taskcleaner/taskcleaner.sh" % DIR_USR_SHARE +EXEC_FKVALIDATOR = "%s/ovirt-engine/scripts/taskcleaner/fkvalidator.sh" % DIR_USR_SHARE CONST_BASE_MAC_ADDR="00:1A:4A" CONST_DEFAULT_MAC_RANGE="00:1a:4a:16:84:02-00:1a:4a:16:84:fd" diff --git a/packaging/fedora/setup/engine-upgrade.py b/packaging/fedora/setup/engine-upgrade.py index f1e5835..0f80f6d 100755 --- a/packaging/fedora/setup/engine-upgrade.py +++ b/packaging/fedora/setup/engine-upgrade.py @@ -49,6 +49,10 @@ UNSUPPORTED_VERSION = "2.2" #MSGS +MSG_ERROR_GET_DB_CONSISTENCY = "Error: Couldn't get db consistency status" +MSG_ERROR_CLEAR_DB = "Error: Couldn't clear db inconsistencies." +MSG_CLEAR_DB_INCONSISTENCIES = "INFO: DB seems to contain inconsistent data. Would\ +you like to clear the DB before upgrading?\n(Answering 'no' will stop the upgrade)" MSG_TASKS_COMPENSATIONS = "\n\nSystem Tasks:\n%s\n%s\n\n" MSG_STOP_RUNNING_TASKS = "\nInfo: The following tasks have been found running \ in the system: %s%sWould you like to proceed and try to stop tasks automatically?\ @@ -815,6 +819,57 @@ raise Exception(output_messages.ERR_CANT_CLEAR_ZOMBIE_TASKS) +def db_validation_fails(): + ''' + Check db for inconsistencies + ''' + cmd = [ + basedefs.EXEC_FKVALIDATOR, + "-u", SERVER_ADMIN, + "-s", SERVER_NAME, + "-p", SERVER_PORT, + "-d", basedefs.DB_NAME, + ] + + out, rc = utils.execCmd( + cmdList=cmd, + failOnError=True, + msg=MSG_ERROR_GET_DB_CONSISTENCY, + envDict=utils.getPgEnv(), + ) + + # Check the content of the output + # If it's not empty, return True + if len(out): + for line in out.split('\n'): + if len(line.strip()): + return True + + # If we're here, output contains nothing + return False + + +def clear_db_inconsistencies(): + ''' + Clear db inconsistencies + ''' + cmd = [ + basedefs.EXEC_FKVALIDATOR, + "-u", SERVER_ADMIN, + "-s", SERVER_NAME, + "-p", SERVER_PORT, + "-d", basedefs.DB_NAME, + "-f", + ] + + out, rc = utils.execCmd( + cmdList=cmd, + failOnError=False, + msg=MSG_ERROR_CLEAR_DB, + envDict=utils.getPgEnv(), + ) + + def deployDbAsyncTasks(dbName=basedefs.DB_NAME): # Deploy DB functionality first cmd = [ @@ -1087,6 +1142,16 @@ if updateRelatedToDB: runFunc([[stopDbRelatedServices, etlService, notificationService]], MSG_INFO_STOP_DB) + if db_validation_fails(): + answer = utils.askYesNo(MSG_CLEAR_DB_INCONSISTENCIES) + if answer: + clear_db_inconsistencies() + else: + logging.debug("User chose not to clear db. Exiting") + runFunc([[startDbRelatedServices, etlService, notificationService]], MSG_INFO_START_DB) + runFunc(startEngineService, MSG_INFO_START_ENGINE % engineService) + raise + if not options.ignore_tasks: # Check that there are no running tasks/compensations try: -- To view, visit http://gerrit.ovirt.org/12512 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ief0e65231bb42b569734cdd2fa6491b645491f98 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alex Lourie <alou...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches