Alex Lourie has uploaded a new change for review.

Change subject: packaging: setup: detect existing DB in remote flows
......................................................................

packaging: setup: detect existing DB in remote flows

Change-Id: Iee813572cab7e0afcf5f5dfa97e4121334c3aa5b
Bug-Url: https://bugzilla.redhat.com/1026947
Signed-off-by: Alex Lourie <alou...@redhat.com>
---
M packaging/common_utils.py
M packaging/ovirt-engine-dwh-setup.py
2 files changed, 60 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/46/22546/1

diff --git a/packaging/common_utils.py b/packaging/common_utils.py
index f9d6ba0..1dd31a7 100755
--- a/packaging/common_utils.py
+++ b/packaging/common_utils.py
@@ -622,29 +622,39 @@
     output, rc = execCmd(cmdList=cmd, failOnError=True, msg="Failed to get 
package version & release")
     return output.rstrip()
 
+
 def dbExists(db_dict, TEMP_PGPASS):
 
     exists = False
     owner = False
     logging.debug("checking if %s db already exists" % db_dict['dbname'])
     env = {'ENGINE_PGPASS': TEMP_PGPASS}
-    output, rc = execSqlCmd(
-        db_dict=db_dict,
-        sql_query="select 1",
-        envDict=env,
-    )
+    if (
+        db_dict['username'] == 'admin' and
+        db_dict['password'] == 'dummy'
+    ):
+        if localHost(db_dict['host']):
+            output, rc = runPostgresSuQuery(
+                query='"select 1;"',
+                database=db_dict['dbname'],
+                failOnError=False,
+            )
+    else:
+        output, rc = execSqlCmd(
+            db_dict=db_dict,
+            sql_query="select 1",
+            envDict=env,
+        )
     if rc == 0:
         exists = True
-        if db_dict['username'] != db_dict['engine_user']:
+        if (
+            db_dict['username'] != db_dict['engine_user'] and
+            (
+                db_dict['password'] != 'dummy' and
+                db_dict['username'] != 'admin'
+            )
+        ):
             owner = True
-    else:
-        output, rc = runPostgresSuQuery(
-            query='"select 1;"',
-            database=db_dict['dbname'],
-            failOnError=False,
-        )
-        if rc == 0:
-            exists = True
 
     return exists, owner
 
@@ -1061,16 +1071,17 @@
             (
                 '# DB USER credentials.\n'
                 '{host}:{port}:{database}:{user}:{password}\n'
-                '{host}:{port}:{engine_db}:{engine_user}:{engine_password}\n'
+                '{host}:{port}:{database}:{engine_user}:{engine_pass}\n'
+                '{host}:{port}:{engine_db}:{engine_user}:{engine_pass}\n'
             ).format(
                 host=db_dict['host'],
                 port=db_dict['port'],
                 database='*' if mode == 'all' else db_dict['dbname'],
+                engine_db=db_dict['engine_db'],
                 user=db_dict['username'],
                 password=db_dict['password'],
                 engine_user=db_dict['engine_user'],
-                engine_db=db_dict['engine_db'],
-                engine_password=db_dict['engine_pass'],
+                engine_pass=db_dict['engine_pass'],
             ),
         )
 
diff --git a/packaging/ovirt-engine-dwh-setup.py 
b/packaging/ovirt-engine-dwh-setup.py
index f1a5595..b2ceebe 100755
--- a/packaging/ovirt-engine-dwh-setup.py
+++ b/packaging/ovirt-engine-dwh-setup.py
@@ -282,6 +282,37 @@
 
     return db_dict
 
+def getDBStatus(db_dict, TEMP_PGPASS):
+    exists = owned = False
+    for dbdict in (
+        db_dict,
+        {
+            'dbname': DB_NAME,
+            'host': db_dict['host'],
+            'port': db_dict['port'],
+            'username': db_dict['engine_user'],
+            'password': db_dict['engine_pass'],
+            'engine_user': db_dict['engine_user'],
+            'engine_pass': db_dict['engine_pass'],
+        },
+        {
+            'dbname': DB_NAME,
+            'host': db_dict['host'],
+            'port': db_dict['port'],
+            'username': 'admin',
+            'password': 'dummy',
+            'engine_user': db_dict['engine_user'],
+            'engine_pass': db_dict['engine_pass'],
+        },
+    ):
+        exists, owned = utils.dbExists(dbdict, TEMP_PGPASS)
+        if exists:
+            db_dict['username'] = dbdict['username']
+            db_dict['password'] = dbdict['password']
+            break
+
+    return exists, owned
+
 
 @transactionDisplay("Setting DB connectivity")
 def setDbPass(db_dict):
@@ -447,7 +478,7 @@
                 readonly=db_dict['readonly'],
             )
 
-            dbExists, owned = utils.dbExists(db_dict, PGPASS_TEMP)
+            dbExists, owned = getDBStatus(db_dict, PGPASS_TEMP)
             if dbExists:
                 try:
                     if utils.localHost(db_dict['host']) and not owned:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iee813572cab7e0afcf5f5dfa97e4121334c3aa5b
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-dwh
Gerrit-Branch: ovirt-3.3
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