Alex Lourie has uploaded a new change for review. Change subject: packaging: setup: configure pghba for use as postgres ......................................................................
packaging: setup: configure pghba for use as postgres Change-Id: I7244d9ec7a6b2dc4dbc2c3965b1f26e4b51b66ca Signed-off-by: Alex Lourie <[email protected]> --- M packaging/common_utils.py M packaging/ovirt-engine-dwh-setup.py 2 files changed, 60 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/36/18036/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index 64fb21b..5958efe 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -729,7 +729,7 @@ useShell=False, usePipeFiles=False, envDict=None - ): +): """ Run external shell command with 'shell=false' receives a list of arguments for command line execution @@ -1150,3 +1150,40 @@ with open(FILE_PG_HBA, 'w') as pghba: pghba.write('\n'.join(content)) + +def configHbaIdent(orig='md5', newval='ident'): + content = [] + logging.debug('Updating pghba postgres use') + contentline = ( + 'local ' + 'all ' + 'all ' + '{value}' + ) + + with open(FILE_PG_HBA, 'r') as pghba: + for line in pghba.read().splitlines(): + if line.startswith( + contentline.format(value=newval) + ): + return False + + if line.startswith( + contentline.format(value=orig) + ): + line=contentline.format(value=newval) + + content.append(line) + + with open(FILE_PG_HBA, 'w') as pghba: + pghba.write('\n'.join(content)) + + restartPostgres() + return True + +def setPgHbaIdent(): + return configHbaIdent() + +def restorePgHba(): + return configHbaIdent('ident', 'md5') + diff --git a/packaging/ovirt-engine-dwh-setup.py b/packaging/ovirt-engine-dwh-setup.py index d5e2671..754ffe8 100755 --- a/packaging/ovirt-engine-dwh-setup.py +++ b/packaging/ovirt-engine-dwh-setup.py @@ -32,7 +32,11 @@ FILE_ENGINE_CONF_DEFAULTS = "/usr/share/ovirt-engine/conf/engine.conf.defaults" FILE_ENGINE_CONF = "/etc/ovirt-engine/engine.conf" FILE_DATABASE_CONFIG = "/etc/ovirt-engine/engine.conf.d/10-setup-database.conf" -FILE_DATABASE_DWH_CONFIG = "/etc/ovirt-engine/engine.conf.d/10-setup-database-dwh.conf" +DIR_DATABASE_DWH_CONFIG = "/etc/ovirt-engine-dwh/engine-dwh.conf.d" +FILE_DATABASE_DWH_CONFIG = os.path.join( + DIR_DATABASE_DWH_CONFIG, + '10-setup-database-dwh.conf' +) DB_BACKUPS_DIR = "/var/lib/ovirt-engine/backups" DB_NAME = "ovirt_engine_history" DB_USER = 'engine_history' @@ -248,21 +252,20 @@ logging.debug("starting main()") db_dict = getDbDictFromOptions() - if not os.path.exists( - FILE_DATABASE_DWH_CONFIG - ): - with open(FILE_DATABASE_DWH_CONFIG, 'w') as fdwh: - fdwh.write( - ( - 'DWH_USER={user}\n' - 'DWH_PASSWORD={password}\n' - 'DWH_DATABASE={database}' - ).format( - user=db_dict['username'], - password=db_dict['password'], - database=db_dict['name'], - ) + if not os.path.exists(DIR_DATABASE_DWH_CONFIG): + os.mkdir(DIR_DATABASE_DWH_CONFIG, mode=0644) + with open(FILE_DATABASE_DWH_CONFIG, 'w') as fdwh: + fdwh.write( + ( + 'DWH_USER={user}\n' + 'DWH_PASSWORD={password}\n' + 'DWH_DATABASE={database}' + ).format( + user=db_dict['username'], + password=db_dict['password'], + database=db_dict['name'], ) + ) # Get minimal supported version from oVirt Engine minimalVersion = utils.getVDCOption("MinimalETLVersion") @@ -284,6 +287,7 @@ # Create/Upgrade DB PGPASS_TEMP = utils.createTempPgpass(db_dict) + pg_updated = utils.configHbaIdent() if dbExists(db_dict): try: doBackup = utils.performBackup(db_dict, DB_BACKUPS_DIR, PGPASS_TEMP) @@ -357,6 +361,9 @@ if os.path.exists(PGPASS_TEMP): os.remove(PGPASS_TEMP) + if pg_updated: + utils.restorePgHba() + return rc if __name__ == "__main__": -- To view, visit http://gerrit.ovirt.org/18036 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I7244d9ec7a6b2dc4dbc2c3965b1f26e4b51b66ca Gerrit-PatchSet: 1 Gerrit-Project: ovirt-dwh Gerrit-Branch: master Gerrit-Owner: Alex Lourie <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
