Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: less strict parsing of pg_hba.conf ......................................................................
packaging: setup: less strict parsing of pg_hba.conf In addition to I374d578735c910451bc7698444a446728b33fd58, also use a regexp for matching the 'engine' lines. Change-Id: If43df5c1e22cd02a3ccd88acb36d35e1abbc6322 Bug-Url: https://bugzilla.redhat.com/1107850 Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/common_utils.py 1 file changed, 46 insertions(+), 36 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/87/28787/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index 22d7145..bdec2f2 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -1374,49 +1374,59 @@ database=db_dict['dbname'], ) -def updatePgHba(database, user): - content = [] - logging.debug('Updating pghba') - with open(FILE_PG_HBA, 'r') as pghba: - for line in pghba.read().splitlines(): - if user in line: - return - - if 'engine engine 0.0.0.0/0' in line: - for address in ('0.0.0.0/0', '::0/0'): - content.append( - ( - '{host:7} ' - '{database:15} ' - '{user:15} ' - '{address:23} ' - '{auth}' - ).format( - host='host', - user=user, - database='all', - address=address, - auth='md5', - ) - ) - - content.append(line) - - with open(FILE_PG_HBA, 'w') as pghba: - pghba.write('\n'.join(content)) - _RE_POSTGRES_PGHBA_LOCAL = re.compile( flags=re.VERBOSE, pattern=r""" ^ - (?P<host>local) + (?P<host>\w+) \s+ - .* + (?P<database>\w+) + \s+ + (?P<user>\w+) + \s+ + (?P<address>\S+) \s+ (?P<param>\w+) $ """, ) + +def updatePgHba(database, user): + content = [] + logging.debug('Updating pghba') + with open(FILE_PG_HBA, 'r') as pghba: + for line in pghba.read().splitlines(): + matcher = _RE_POSTGRES_PGHBA_LOCAL.match(line) + if matcher is not None: + if matcher.group('host') == 'host' and matcher.group('user') == user: + return + if ( + matcher.group('host') == 'host' and + matcher.group('database') == 'engine' and + matcher.group('user') == 'engine' and + matcher.group('address') == '0.0.0.0/0' + ): + for address in ('0.0.0.0/0', '::0/0'): + content.append( + ( + '{host:7} ' + '{database:15} ' + '{user:15} ' + '{address:23} ' + '{auth}' + ).format( + host='host', + user=user, + database='all', + address=address, + auth='md5', + ) + ) + + content.append(line) + + with open(FILE_PG_HBA, 'w') as pghba: + pghba.write('\n'.join(content) + '\n') def configHbaIdent(orig='md5', newval='ident'): content = [] @@ -1426,14 +1436,14 @@ for line in pghba.read().splitlines(): matcher = _RE_POSTGRES_PGHBA_LOCAL.match(line) if matcher is not None: - if matcher.group('param') == newval: + if matcher.group('host') == 'local' and matcher.group('param') == newval: return False - if matcher.group('param') == orig: + if matcher.group('host') == 'local' and matcher.group('param') == orig: line = line.replace(matcher.group('param'), newval) content.append(line) with open(FILE_PG_HBA, 'w') as pghba: - pghba.write('\n'.join(content)) + pghba.write('\n'.join(content) + '\n') restartPostgres(newval=='md5') return True -- To view, visit http://gerrit.ovirt.org/28787 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If43df5c1e22cd02a3ccd88acb36d35e1abbc6322 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-dwh Gerrit-Branch: ovirt-engine-dwh-3.3 Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches