Alex Lourie has uploaded a new change for review.

Change subject: packaging: updated loading of validator sp functions
......................................................................

packaging: updated loading of validator sp functions

This patch is an amendment to gerrit.ovirt.org:/12512
and it updates the method of loading stored procedure
functions to the engine database.

It is now performed separately, before executing generic
validator. It results in sp functions to be owned by
the application user (engine) which is the desired behavior.

Change-Id: Ie9f133fd43441a42c1d5817ed5bfbc6262123df4
Bug-Url: https://bugzilla.redhat.com/893459
Signed-off-by: Alex Lourie <[email protected]>
---
M backend/manager/tools/dbutils/fkvalidator.sh
M backend/manager/tools/dbutils/validatedb.sh
M packaging/fedora/setup/engine-upgrade.py
3 files changed, 42 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/03/14603/1

diff --git a/backend/manager/tools/dbutils/fkvalidator.sh 
b/backend/manager/tools/dbutils/fkvalidator.sh
index 106807d..71025b0 100755
--- a/backend/manager/tools/dbutils/fkvalidator.sh
+++ b/backend/manager/tools/dbutils/fkvalidator.sh
@@ -88,9 +88,6 @@
     esac
 done
 
-# Install fkvalidator procedures
-psql -w -U ${USERNAME} -h ${SERVERNAME} -p ${PORT} -f ./fkvalidator_sp.sql 
${DATABASE} > /dev/null
-
 if [[ "${FIXIT}" = "true" && ! "${QUIET}" = "true" ]]; then
     echo "Caution, this operation should be used with care. Please contact 
support prior to running this command"
     echo "Are you sure you want to proceed? [y/n]"
diff --git a/backend/manager/tools/dbutils/validatedb.sh 
b/backend/manager/tools/dbutils/validatedb.sh
index de0c116..0a2eca4 100755
--- a/backend/manager/tools/dbutils/validatedb.sh
+++ b/backend/manager/tools/dbutils/validatedb.sh
@@ -16,6 +16,8 @@
         server port to use to connect to the DB
     --fix
         run validation script in "fix" mode
+    --loadsp
+        load stored procedure function needed by validators
     --database=db
         database to connect to
 
@@ -24,6 +26,7 @@
 }
 
 error=0
+loadsp=false
 
 while [ -n "$1" ]; do
     x="$1"
@@ -48,6 +51,9 @@
         --fix*)
             extra_params="-f"
         ;;
+        --loadsp*)
+            loadsp=true
+        ;;
         --help)
             usage
         ;;
@@ -57,6 +63,14 @@
     esac
 done
 
+if [ loadsp ]; then
+    spfunctionslist="fkvalidator_sp.sql"
+    for func in ${spfunctionslist}; do
+            psql -U ${USERNAME} -h ${SERVERNAME} -p ${PORT} -d ${DATABASE} -f 
$dbutils/$func > /dev/null || error=1
+    done
+    exit ${error}
+fi
+
 validationlist="fkvalidator.sh encodingvalidator.sh"
 
 for script in ${validationlist}; do
diff --git a/packaging/fedora/setup/engine-upgrade.py 
b/packaging/fedora/setup/engine-upgrade.py
index cf3c924..39a0022 100755
--- a/packaging/fedora/setup/engine-upgrade.py
+++ b/packaging/fedora/setup/engine-upgrade.py
@@ -1072,6 +1072,31 @@
     if os.path.exists(basedefs.DIR_ENGINE_SYSCONFIG):
         shutil.rmtree(basedefs.DIR_ENGINE_SYSCONFIG)
 
+def loadDbFunctions():
+
+    cmd = [
+        basedefs.EXEC_DBVALIDATOR,
+        "--user={admin}".format(
+            admin=SERVER_ADMIN,
+        ),
+        "--host={host}".format(
+            host=SERVER_NAME
+        ),
+        "--port={port}".format(
+            port=SERVER_PORT
+        ),
+        "--database={database}".format(
+            database=basedefs.DB_NAME
+        ),
+        "--loadsp",
+    ]
+
+    utils.execCmd(
+        cmdList=cmd,
+        failOnError=True,
+        envDict=utils.getPgEnv(),
+    )
+
 def checkDb():
 
     header = "\n\n ======  Validating database '{dbname}' ====== \n".format(
@@ -1081,7 +1106,7 @@
     cmd = [
         basedefs.EXEC_DBVALIDATOR,
         "--user={admin}".format(
-            admin=utils.getDbAdminUser(),
+            admin=SERVER_ADMIN,
         ),
         "--host={host}".format(
             host=SERVER_NAME
@@ -1305,6 +1330,7 @@
 
                         try:
                             # Validate DB first
+                            loadDbFunctions()
                             violations, issues_found = checkDb()
 
                             # If violations found, show them
@@ -1312,7 +1338,7 @@
                             if issues_found:
                                 if utils.askYesNo(
                                     MSG_CLEAR_DB_INCONSISTENCIES % violations
-                                ) is True:
+                                ):
                                     fixDb()
                                 else:
                                     raise Exception(


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie9f133fd43441a42c1d5817ed5bfbc6262123df4
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alex Lourie <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to