Alex Lourie has uploaded a new change for review.

Change subject: packaging: Validating DB encoding during setup
......................................................................

packaging: Validating DB encoding during setup

This patch adds template1 DB encoding validation during
setup on remote DBs. There's no need to validate the default
encoding on local installation because on local installation
we perform initdb, which creates template1 with a default
desired encoding utf8.

Change-Id: I2f08ac82d14d85c4ff2054b0b433bb59feeddf7a
Bug-Url: https://bugzilla.redhat.com/920565
Signed-off-by: Alex Lourie <[email protected]>
---
M packaging/fedora/setup/engine_validators.py
M packaging/fedora/setup/output_messages.py
2 files changed, 43 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/76/14676/1

diff --git a/packaging/fedora/setup/engine_validators.py 
b/packaging/fedora/setup/engine_validators.py
index e2b4721..96ae424 100644
--- a/packaging/fedora/setup/engine_validators.py
+++ b/packaging/fedora/setup/engine_validators.py
@@ -317,6 +317,9 @@
         # DB Create check
         _checkCreateDbPrivilege(param["DB_ADMIN"], param["DB_HOST"], 
param["DB_PORT"])
 
+        # DB Encoding check
+        _checkDbEncoding(param["DB_ADMIN"], param["DB_HOST"], param["DB_PORT"])
+
         # Delete DB check
         _checkDropDbPrivilege(param["DB_ADMIN"], param["DB_HOST"], 
param["DB_PORT"])
 
@@ -505,8 +508,46 @@
     else:
         logging.info("Successfully created temp database on server %s." % 
dbHost)
 
+def _checkDbEncoding(dbAdminUser, dbHost, dbPort):
+    """ _checkDbEncoding checks DB default encoding on DB server"""
+
+    logging.info("Checking encoding of the database 'ovirt_engine_test' on 
remote server.")
+    out, rc = utils.execRemoteSqlCommand(
+        username=dbAdminUser,
+        dbHost=dbHost,
+        dbPort=dbPort,
+        dbName=basedefs.DB_POSTGRES,
+        sqlQuery=(
+            "SELECT pg_encoding_to_char(encoding) "
+            "FROM pg_database WHERE datname = 'ovirt_engine_test';"
+        )
+    )
+
+    # Error in looking for encoding, meaning we don't have enough privileges
+    # to enquire it.
+    if rc:
+        logging.error(output_messages.ERR_DB_CHECK_ENCODING, dbHost)
+        raise Exception("\n" + output_messages.ERR_DB_CHECK_ENCODING % dbHost 
+ "\n")
+    elif (
+        not "utf8" in out and
+        not "UTF8" in out
+    ):
+        logging.info(
+            "Found incorrect default encoding %s "
+            "on the server %s. Template1 database "
+            "should have a UTF8 encoding for engine "
+            "installation."% (out, dbHost)
+        )
+        raise Exception(
+            "\nFound incorrect default encoding %s "
+            "on the server %s. Template1 database "
+            "should have a UTF8 encoding for engine "
+            "installation.\n"% (out, dbHost)
+        )
+
+
 def _checkDropDbPrivilege(dbAdminUser, dbHost, dbPort):
-    """ _checkCreateDbPrivilege checks CREATE DB privilege on DB server"""
+    """ _checkDropDbPrivilege checks DROP DB privilege on DB server"""
 
     logging.info("Deleting the test database from the remote server")
     out, rc = utils.execRemoteSqlCommand(dbAdminUser, dbHost, dbPort,
diff --git a/packaging/fedora/setup/output_messages.py 
b/packaging/fedora/setup/output_messages.py
index 9ae84a5..30c496f 100644
--- a/packaging/fedora/setup/output_messages.py
+++ b/packaging/fedora/setup/output_messages.py
@@ -251,6 +251,7 @@
 ERR_DB_GET_SPACE = "Error: Failed to get %s database size."
 ERR_DB_CONNECTION = "Could not connect to host %s with provided credentials. 
Check that your settings are correct."
 ERR_DB_CREATE_PRIV = "Couldn't create temp database on server %s. Check 
provided credentials."
+ERR_DB_CHECK_ENCODING = "Couldn't check temp database encoding on server %s. 
Check provided credentials."
 ERR_DB_DROP_PRIV = "Couldn't drop temp database on server %s. Check provided 
credentials."
 ERR_DB_CONNECTIONS_BLOCK = "Error: failed to block new DB connections"
 ERR_DB_CONNECTIONS_CLEAR = "Error: failed to clear active DB connections"


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I2f08ac82d14d85c4ff2054b0b433bb59feeddf7a
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