Alex Lourie has uploaded a new change for review. Change subject: packaging: setup: backup DB and WAR on upgrade ......................................................................
packaging: setup: backup DB and WAR on upgrade Change-Id: I97c4da7ff92619551515b652ec17734fced124af Bug-Url: https://bugzilla.redhat.com/1043314 Signed-off-by: Alex Lourie <alou...@redhat.com> --- M packaging/common_utils.py M packaging/ovirt-engine-reports-setup.py 2 files changed, 38 insertions(+), 27 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/80/22480/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index 011426b..cc33638 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -729,6 +729,7 @@ def dbExists(db_dict, TEMP_PGPASS): exists = False + empty = True owner = False logging.debug("checking if %s db already exists" % db_dict['dbname']) env = {'ENGINE_PGPASS': TEMP_PGPASS} @@ -747,15 +748,24 @@ sql_query="select 1", envDict=env, ) + if rc == 0: exists = True - if ( + output, rc = execSqlCmd( + db_dict=db_dict, + sql_query="CHECK THAT DB IS NOT EMPTY", + envDict=env, + ) + if rc == 0: + empty = False + + if exists and ( db_dict['username'] != db_dict['engine_user'] and db_dict != 'admin' ): owner = True - return exists, owner + return exists, empty, owner def getDbAdminUser(): """ @@ -841,15 +851,14 @@ def createDB(db_dict): - if localHost(db_dict['host']): - if not db_dict['engine_user'] == db_dict['username']: - createRole( - database=db_dict['dbname'], - username=db_dict['username'], - password=db_dict['password'], - engine=db_dict['engine_user'], - ) - createDatabase(db_dict['dbname'], db_dict['username']) + if not db_dict['engine_user'] == db_dict['username']: + createRole( + database=db_dict['dbname'], + username=db_dict['username'], + password=db_dict['password'], + engine=db_dict['engine_user'], + ) + createDatabase(db_dict['dbname'], db_dict['username']) def createLang(db_dict, TEMP_PGPASS): diff --git a/packaging/ovirt-engine-reports-setup.py b/packaging/ovirt-engine-reports-setup.py index c608dd6..a3994f5 100755 --- a/packaging/ovirt-engine-reports-setup.py +++ b/packaging/ovirt-engine-reports-setup.py @@ -75,6 +75,7 @@ OVIRT_REPORTS_TRUST_STORE_PASS="mypass" DB_EXIST = False +DB_EMPTY = True MUCK_PASSWORD="oVirtadmin2009!" PGDUMP_EXEC = "/usr/bin/pg_dump" FILE_TMP_SQL_DUMP = tempfile.mkstemp(suffix=".sql", dir="/tmp")[1] @@ -180,7 +181,7 @@ shutil.copyfile("/usr/share/java/postgresql-jdbc.jar", "%s/conf_source/db/postgresql/jdbc/postgresql-jdbc.jar" % REPORTS_SERVER_BUILDOMATIC_DIR) # create DB if it didn't exist: - if not DB_EXISTED: + if not DB_EXISTED and utils.localHost(db_dict['host']): logging.debug('Creating DB') utils.createDB(db_dict) utils.createLang(db_dict, TEMP_PGPASS) @@ -358,6 +359,7 @@ def getDBStatus(db_dict, TEMP_PGPASS): exists = owned = False + empty = True for dbdict in ( db_dict, { @@ -379,11 +381,11 @@ 'engine_pass': db_dict['engine_pass'], }, ): - exists, owned = utils.dbExists(dbdict, TEMP_PGPASS) + exists, empty, owned = utils.dbExists(dbdict, TEMP_PGPASS) if exists: break - return exists, owned + return exists, empty, owned def getDbCredentials( hostdefault='', @@ -920,6 +922,7 @@ global db_dict global DB_EXIST + global DB_EMPTY rc = 0 preserveReportsJobs = False pghba_updated = False @@ -971,7 +974,7 @@ 'reports.' ) - DB_EXIST, owned = getDBStatus(db_dict, TEMP_PGPASS) + DB_EXIST, DB_EMPTY, owned = getDBStatus(db_dict, TEMP_PGPASS) if dblocal: if DB_EXIST and not owned: logging.debug( @@ -991,14 +994,9 @@ ) elif not DB_EXIST: logging.debug( - ( - 'Remote database {database} found, ' - 'not owned by reports user' - ).format( - database=db_dict['dbname'] - ) + 'Setup could not connect to remote database server with ' + 'automatically detected credentials. ' ) - print 'Remote database found.' db_dict['host'] = options['REMOTE_DB_HOST'] db_dict['port'] = options['REMOTE_DB_PORT'] @@ -1031,7 +1029,7 @@ db_dict=db_dict, mode='own', ) - DB_EXIST, owned = getDBStatus( + DB_EXIST, DB_EMPTY, owned = getDBStatus( db_dict, TEMP_PGPASS, ) @@ -1075,6 +1073,10 @@ # Update reports datasource configuration setReportsDatasource(db_dict) + if not warUpdated and not DB_EMPTY: + backupWAR() + backupDB(db_dict, TEMP_PGPASS) + # Catch failures on configuration try: # Export reports if we had a previous installation @@ -1083,7 +1085,7 @@ if preserveReportsJobs: exportScheduale() - if DB_EXIST and ( + if not DB_EMPTY and ( warUpdated or isWarInstalled() ): savedDir = utils.exportUsers() @@ -1105,7 +1107,7 @@ editOvirtEngineAdminXml(adminPass) if ( - DB_EXIST and + not DB_EMPTY and savedDir is not None and ( warUpdated or isWarInstalled() @@ -1122,7 +1124,7 @@ # preserved as well as users passwords reset after importing # reports in previous step. if ( - DB_EXIST and + not DB_EMPTY and savedDir is not None and ( warUpdated or isWarInstalled() @@ -1174,7 +1176,7 @@ logging.error("Failed to complete the setup of the reports package!") logging.debug(traceback.format_exc()) logging.debug("Restoring previous version") - if not warUpdated and DB_EXIST: + if not warUpdated and not DB_EMPTY: restoreWAR() restoreDB(db_dict, TEMP_PGPASS) raise -- To view, visit http://gerrit.ovirt.org/22480 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I97c4da7ff92619551515b652ec17734fced124af Gerrit-PatchSet: 1 Gerrit-Project: ovirt-reports 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