Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: fix updating pg_hba.conf
......................................................................

packaging: setup: fix updating pg_hba.conf

pg_hba.conf was not updated correctly e.g. on upgrade from 3.2.

Change-Id: I6b07a19245957a4bd8c2cd6dd3fc7d1a5b64610b
Signed-off-by: Yedidyah Bar David <[email protected]>
---
M packaging/common_utils.py
1 file changed, 28 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/11/30511/1

diff --git a/packaging/common_utils.py b/packaging/common_utils.py
index bdec2f2..10a12d6 100755
--- a/packaging/common_utils.py
+++ b/packaging/common_utils.py
@@ -1378,13 +1378,9 @@
     flags=re.VERBOSE,
     pattern=r"""
         ^
-        (?P<host>\w+)
+        (?P<host>local)
         \s+
-        (?P<database>\w+)
-        \s+
-        (?P<user>\w+)
-        \s+
-        (?P<address>\S+)
+        .*
         \s+
         (?P<param>\w+)
         $
@@ -1392,38 +1388,34 @@
 )
 
 def updatePgHba(database, user):
-    content = []
     logging.debug('Updating pghba')
+    content = []
+    updated = False
+    lines = [
+        (
+            '{host:7} '
+            '{database:15} '
+            '{user:15} '
+            '{address:23} '
+            '{auth}'
+        ).format(
+            host='host',
+            user=user,
+            database='all',
+            address=address,
+            auth='md5',
+        )
+        for address in ('0.0.0.0/0', '::0/0')
+    ]
     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',
-                            )
-                        )
+            if line not in lines:
+                content.append(line)
 
-            content.append(line)
+                # order is important, add after local
+                # so we be first
+                if line.lstrip().startswith('local'):
+                    content.extend(lines)
 
     with open(FILE_PG_HBA, 'w') as pghba:
         pghba.write('\n'.join(content) + '\n')
@@ -1436,9 +1428,9 @@
         for line in pghba.read().splitlines():
             matcher = _RE_POSTGRES_PGHBA_LOCAL.match(line)
             if matcher is not None:
-                if matcher.group('host') == 'local' and matcher.group('param') 
== newval:
+                if matcher.group('param') == newval:
                     return False
-                if matcher.group('host') == 'local' and matcher.group('param') 
== orig:
+                if matcher.group('param') == orig:
                     line = line.replace(matcher.group('param'), newval)
             content.append(line)
 


-- 
To view, visit http://gerrit.ovirt.org/30511
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b07a19245957a4bd8c2cd6dd3fc7d1a5b64610b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-dwh
Gerrit-Branch: ovirt-engine-dwh-3.3
Gerrit-Owner: Yedidyah Bar David <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to