Alex Lourie has uploaded a new change for review. Change subject: packaging: Updated pgpass config to avoid password prompts ......................................................................
packaging: Updated pgpass config to avoid password prompts * Updating pgpass entry for the engine user so it can connect to any database. This will help to avoid password prompts for connection during upgrades. Change-Id: Ica62fe601536d3de92e163a9262f5754b89873ed Bug-Url: https://bugzilla.redhat.com/906270 Signed-off-by: Alex Lourie <[email protected]> --- M packaging/fedora/setup/common_utils.py M packaging/fedora/setup/engine-upgrade.py 2 files changed, 48 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/18/11818/1 diff --git a/packaging/fedora/setup/common_utils.py b/packaging/fedora/setup/common_utils.py index 841eed5..10ececc 100755 --- a/packaging/fedora/setup/common_utils.py +++ b/packaging/fedora/setup/common_utils.py @@ -832,6 +832,49 @@ return False +def updatePgPass(): + + logging.debug("Info: checking if pgpass needs an update") + + # Replace engine:engine in pgpass to *:engine, so that + # engine user can work with any DB, not just 'engine' + pattern = "(^.+):(.+):%s:%s:(.+)" % (basedefs.DB_NAME, + basedefs.DB_USER) + newlines = [] + changed = False + with open(basedefs.DB_PASS_FILE, 'r') as pgpass: + for line in pgpass.read().split('\n'): + result = re.match(pattern, line) + if result: + line = "%s:%s:*:%s:%s" % ( + result.group(1), + result.group(2), + basedefs.DB_USER, + result.group(3), + ) + changed = True + + newlines.append(line) + + # If nothing changed, just return + if not changed: + return + + # Found changes, log it + logging.debug("INFO: pgpass needs to be updated. Updating.") + + # Backup the pgpass + backupFile = "%s.%s" % (basedefs.DB_PASS_FILE, getCurrentDateTime()) + logging.debug("INFO: found existing pgpass file, backing current to %s" % (backupFile)) + os.rename(basedefs.DB_PASS_FILE, backupFile) + + # Create with updated values + with open(basedefs.DB_PASS_FILE, 'w') as pgpass: + pgpass.write('\n'.join(newlines)) + + logging.debug("INFO: pgpass file was updated.") + + def backupDB(db, backup_file, env, user, host="localhost", port="5432"): """ Backup postgres db diff --git a/packaging/fedora/setup/engine-upgrade.py b/packaging/fedora/setup/engine-upgrade.py index 06cf70a..e54375d 100755 --- a/packaging/fedora/setup/engine-upgrade.py +++ b/packaging/fedora/setup/engine-upgrade.py @@ -978,6 +978,11 @@ else: logging.info("Info: %s file found. Continue.", basedefs.DB_PASS_FILE) + + # update pgpass if needed + logging.debug("Info: checking if pgpass needs an update") + utils.updatePgPass() + # Functions/parameters definitions currentDbName = basedefs.DB_NAME stopEngineService = [stopEngine] -- To view, visit http://gerrit.ovirt.org/11818 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ica62fe601536d3de92e163a9262f5754b89873ed Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Alex Lourie <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
