Alex Lourie has uploaded a new change for review.

Change subject: packaging: Updating the usage of the new location of .pgpass
......................................................................

packaging: Updating the usage of the new location of .pgpass

Change-Id: I366282076f0f44602d5180837d5fb06bd61c11a3
Signed-off-by: Alex Lourie <alou...@redhat.com>
---
M data-warehouse/historydbscripts_postgres/dbcustomfunctions.sh
M data-warehouse/historydbscripts_postgres/ovirt-engine-history-db-install.sh
M packaging/common_utils.py
3 files changed, 28 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/74/7974/1

diff --git a/data-warehouse/historydbscripts_postgres/dbcustomfunctions.sh 
b/data-warehouse/historydbscripts_postgres/dbcustomfunctions.sh
index 26e9b0f..87bc9a1 100755
--- a/data-warehouse/historydbscripts_postgres/dbcustomfunctions.sh
+++ b/data-warehouse/historydbscripts_postgres/dbcustomfunctions.sh
@@ -19,6 +19,7 @@
     USERNAME="postgres"
     VERBOSE=false
     LOGFILE="$ME.log"
+    export PGPASSFILE="/etc/ovirt-engine/.pgpass"
 }
 
 #refreshes views
diff --git 
a/data-warehouse/historydbscripts_postgres/ovirt-engine-history-db-install.sh 
b/data-warehouse/historydbscripts_postgres/ovirt-engine-history-db-install.sh
index d84d9f6..ef322df 100755
--- 
a/data-warehouse/historydbscripts_postgres/ovirt-engine-history-db-install.sh
+++ 
b/data-warehouse/historydbscripts_postgres/ovirt-engine-history-db-install.sh
@@ -22,6 +22,7 @@
 REQUIRED_RPMS=(postgresql-server postgresql postgresql-libs postgresql-contrib 
uuid)
 
 #postgresql data dir
+ENGINE_PGPASS=/etc/ovirt-engine/.pgpass
 PGDATA=/var/lib/pgsql/data
 
 #location of ovirt db scripts
@@ -189,7 +190,7 @@
     for i in {1..20}
     do
        echo "[$SCRIPT_NAME] validating that postgres service is 
running...retry $i" >> $LOG_FILE
-       $PSQL -U $USER -d $DB -c "select 1">> $LOG_FILE 2>&1
+       PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $USER -d $DB -c "select 1">> 
$LOG_FILE 2>&1
        if [[ $? == 0 ]]
        then
             SERVICE_UP=1
@@ -257,12 +258,12 @@
 checkIfDBExists()
 {
     echo "[$SCRIPT_NAME] checking if $DB_NAME db exists already.." >> $LOG_FILE
-    $PSQL -U $DB_ADMIN -d $DB_NAME -c "select 1">> $LOG_FILE 2>&1
+    PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -d $DB_NAME -c "select 
1">> $LOG_FILE 2>&1
     if [[ $? -eq 0 ]]
     then
         echo "[$SCRIPT_NAME] $DB_NAME db already exists on $DB_HOST." >> 
$LOG_FILE
         echo " [$SCRIPT_NAME] verifying $TABLE_NAME table exists..." >> 
$LOG_FILE
-        RES=`echo "SELECT count(*) FROM pg_tables WHERE 
tablename='$TABLE_NAME'" | $PSQL -U $DB_ADMIN -d $DB_NAME -t`
+        RES=`echo "SELECT count(*) FROM pg_tables WHERE 
tablename='$TABLE_NAME'" | PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -d 
$DB_NAME -t`
         if [[ $RES -eq 1 ]]
         then
             echo "[$SCRIPT_NAME] $TABLE_NAME table exists in $DB_NAME" >> 
$LOG_FILE
@@ -284,19 +285,19 @@
     echo "[$SCRIPT_NAME] updating admin user credentials" >> $LOG_FILE
 
     #update user postgres password
-    $PSQL -U $DB_ADMIN -c "ALTER ROLE $DB_ADMIN WITH ENCRYPTED PASSWORD 
'$DB_PASS'" >> /dev/null  2>&1
+    PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -c "ALTER ROLE $DB_ADMIN 
WITH ENCRYPTED PASSWORD '$DB_PASS'" >> /dev/null  2>&1
     _verifyRC $? "failed updating user $DB_ADMIN password"
 
     #drop ovirt ROLE if exists
-    $PSQL -U $DB_ADMIN -c "DROP ROLE IF EXISTS $DB_USER" >> $LOG_FILE 2>&1
+    PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -c "DROP ROLE IF EXISTS 
$DB_USER" >> $LOG_FILE 2>&1
     _verifyRC $? "failed updating user $DB_USER password"
 
     #create user ovirt + password
-    $PSQL -U $DB_ADMIN -c "CREATE ROLE $DB_USER WITH LOGIN SUPERUSER ENCRYPTED 
PASSWORD '$DB_PASS'" >> /dev/null 2>&1
+    PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -c "CREATE ROLE $DB_USER 
WITH LOGIN SUPERUSER ENCRYPTED PASSWORD '$DB_PASS'" >> /dev/null 2>&1
     _verifyRC $? "failed updating user $DB_USER password"
 
     #grant all permissions to user ovirt to db ovirt
-    $PSQL -U $DB_ADMIN -c "GRANT ALL PRIVILEGES ON DATABASE $DB_NAME to 
$DB_USER " >> $LOG_FILE 2>&1
+    PGPASSFILE="${ENGINE_PGPASS}" $PSQL -U $DB_ADMIN -c "GRANT ALL PRIVILEGES 
ON DATABASE $DB_NAME to $DB_USER " >> $LOG_FILE 2>&1
     _verifyRC $? "failed updating user $DB_USER privileges"
 }
 
diff --git a/packaging/common_utils.py b/packaging/common_utils.py
index e77a41a..08e3ac0 100755
--- a/packaging/common_utils.py
+++ b/packaging/common_utils.py
@@ -24,7 +24,7 @@
 
 # CONST
 EXEC_IP = "/sbin/ip"
-FILE_PG_PASS="/root/.pgpass"
+FILE_PG_PASS="/etc/ovirt-engine/.pgpass"
 PGPASS_FILE_USER_LINE = "DB USER credentials"
 PGPASS_FILE_ADMIN_LINE = "DB ADMIN credentials"
 
@@ -192,7 +192,7 @@
     cmd = "/usr/bin/psql --pset=tuples_only=on --set ON_ERROR_STOP=1 --dbname 
%s" % db_dict["name"]
     cmd = addPsqlParams(cmd, db_dict)
     cmd = cmd + " -c \"%s\"" % (sql_query)
-    return execExternalCmd(cmd, fail_on_error, err_msg)
+    return execCmd(cmdList=cmd, failOnError=fail_on_error, msg=err_msg)
 
 def isJbossUp():
     '''
@@ -468,7 +468,7 @@
     return False
 
 #TODO: Move all execution commands to execCmd
-def execCmd(cmdList, cwd=None, failOnError=False, msg=ERR_RC_CODE, 
maskList=[], useShell=False, usePipeFiles=False):
+def execCmd(cmdList, cwd=None, failOnError=False, msg=ERR_RC_CODE, 
maskList=[], useShell=False, usePipeFiles=False, envDict={}):
     """
     Run external shell command with 'shell=false'
     receives a list of arguments for command line execution
@@ -487,10 +487,23 @@
         (stdOutFD, stdOutFile) = tempfile.mkstemp(dir="/tmp")
         (stdInFD, stdInFile) = tempfile.mkstemp(dir="/tmp")
 
-    # We use close_fds to close any file descriptors we have so it won't be 
copied to forked childs
-    proc = subprocess.Popen(cmd, stdout=stdOutFD,
-            stderr=stdErrFD, stdin=stdInFD, cwd=cwd, shell=useShell, 
close_fds=True)
+    # Update os.environ with env if provided
+    env = os.environ.copy()
+    if not "PGPASSFILE" in env.keys():
+        env["PGPASSFILE"] = FILE_PG_PASS
+    env.update(envDict)
 
+    # We use close_fds to close any file descriptors we have so it won't be 
copied to forked childs
+    proc = subprocess.Popen(
+        cmd,
+        stdout=stdOutFD,
+        stderr=stdErrFD,
+        stdin=stdInFD,
+        cwd=cwd,
+        shell=useShell,
+        close_fds=True,
+        env=env,
+    )
     out, err = proc.communicate()
     if usePipeFiles:
         with open(stdErrFile, 'r') as f:


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

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