Alex Lourie has uploaded a new change for review.

Change subject: packaging: setup: added a test on postgres status
......................................................................

packaging: setup: added a test on postgres status

This new implementation adds an actual test with the
postgres server to verify it responds to sql queries.

It covers for cases where the postgresql service reports
status up but the server is not ready to receive connections.
In such cases the setup fails on DB operations.

Change-Id: I1907f0f5a7f20225128a875e2a84c5e8de11e6c3
Bug-Url: https://bugzilla.redhat.com/1029969
Signed-off-by: Alex Lourie <alou...@redhat.com>
---
M packaging/common_utils.py
1 file changed, 24 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/72/21272/1

diff --git a/packaging/common_utils.py b/packaging/common_utils.py
index 02bec14..fba9c71 100755
--- a/packaging/common_utils.py
+++ b/packaging/common_utils.py
@@ -10,6 +10,7 @@
 import grp
 import traceback
 import datetime
+import time
 import re
 from StringIO import StringIO
 import subprocess
@@ -28,6 +29,9 @@
 ENGINE_SERVICE_NAME = "ovirt-engine"
 
 # CONST
+
+POSTGRES_START_CYCLES = 5
+
 EXEC_IP = "/sbin/ip"
 EXEC_PSQL = '/usr/bin/psql'
 EXEC_SU = '/bin/su'
@@ -507,7 +511,17 @@
     logging.debug("checking the status of postgresql")
     postgres_service = Service('postgresql')
     postgres_service.status()
-    return postgres_service.lastStateUp
+
+    output, rc = runPostgresSuQuery(
+        query='"select 1;"',
+        database='template1',
+        failOnError=False,
+    )
+
+    return (
+        postgres_service.lastStateUp and
+        rc == 0
+    )
 
 def startPostgres():
     '''
@@ -516,6 +530,15 @@
     if not isPostgresUp():
         startPostgresService()
 
+    for i in range(0, POSTGRES_START_CYCLES):
+        if isPostgresUp():
+            break
+        time.sleep(2)
+    else:
+        raise RuntimeError(
+            'Error: postgresql service couldn\'t be started. Stopping.'
+        )
+
 def stopPostgres():
     '''
     stops the postgresql service


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1907f0f5a7f20225128a875e2a84c5e8de11e6c3
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-dwh
Gerrit-Branch: ovirt-3.3.1
Gerrit-Owner: Alex Lourie <alou...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to