Alon Bar-Lev has uploaded a new change for review.

Change subject: packaging: use conf.d notation for setup settings
......................................................................

packaging: use conf.d notation for setup settings

Currently we store setup generated file at /etc/sysconfig/ovirt-engine,
this makes it difficult to manage as user may edit the file as-well.

The service supports /etc/sysconfig/ovirt-engine.d, so we can leverage
this and store setup generated configurations.

User can override these at files with higher index.

Change-Id: Ib05f8c3b21c2b1146bda5b257e347a91d0521bce
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M packaging/fedora/setup/basedefs.py
M packaging/fedora/setup/common_utils.py
M packaging/fedora/setup/engine-setup.py
3 files changed, 52 insertions(+), 31 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/66/12666/1

diff --git a/packaging/fedora/setup/basedefs.py 
b/packaging/fedora/setup/basedefs.py
index 4a823e7..0a5c98b 100644
--- a/packaging/fedora/setup/basedefs.py
+++ b/packaging/fedora/setup/basedefs.py
@@ -117,6 +117,15 @@
 FILE_ENGINE_CONF="/etc/ovirt-engine/engine.conf"
 DIR_ENGINE_CONF="%s.d" % FILE_ENGINE_CONF
 
+# File containing the setup generated database configuration of the engine:
+FILE_ENGINE_CONF_DATABASE="%s/50-setup-database.conf" % DIR_ENGINE_CONF
+
+# File containing the setup generated protocols configuration of the engine:
+FILE_ENGINE_CONF_PROTOCOLS="%s/50-setup-protocols.conf" % DIR_ENGINE_CONF
+
+# File containing the setup generated java configuration of the engine:
+FILE_ENGINE_CONF_JAVA="%s/50-setup-java.conf" % DIR_ENGINE_CONF
+
 # This file will be automatically created when the engine goes into
 # maintenance mode during upgrades and automatically removed when the
 # engine goes back into normal mode once the upgrade is finished:
diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index 7acd19a..45e9e02 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -104,16 +104,18 @@
         pass
 
 class TextConfigFileHandler(ConfigFileHandler):
-    def __init__(self, filepath, sep="=", comment="#"):
+    def __init__(self, filepath, sep="=", comment="#", readExisting=True):
         ConfigFileHandler.__init__(self, filepath)
         self.data = []
         self.sep = sep
         self.comment = comment
+        self.readExisting = readExisting
 
     def open(self):
-        fd = file(self.filepath)
-        self.data = fd.readlines()
-        fd.close()
+        if self.readExisting:
+            fd = file(self.filepath)
+            self.data = fd.readlines()
+            fd.close()
 
     def close(self):
         fd = file(self.filepath, 'w')
@@ -1170,18 +1172,11 @@
         return basedefs.CONST_DEFAULT_MAC_RANGE
 
 
-def editEngineSysconfig(proxyEnabled, dbUrl, dbUser, fqdn, http, https, 
javaHome):
+def editEngineSysconfigProtocols(proxyEnabled, fqdn, http, https):
     # Load the file:
     logging.debug("Loading text file handler")
-    handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF)
+    handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF_PROTOCOLS, 
readExisting=False)
     handler.open()
-
-    # Save the Java home:
-    handler.editParam("JAVA_HOME", javaHome)
-
-    handler.editParam("ENGINE_DB_DRIVER", "org.postgresql.Driver")
-    handler.editParam("ENGINE_DB_URL", dbUrl)
-    handler.editParam("ENGINE_DB_USER", dbUser)
 
     # Put FQDN for use by other components
     handler.editParam("ENGINE_FQDN", fqdn)
@@ -1202,6 +1197,19 @@
         handler.editParam("ENGINE_HTTPS_ENABLED", "true")
         handler.editParam("ENGINE_HTTPS_PORT", https)
         handler.editParam("ENGINE_AJP_ENABLED", "false")
+
+    # Save and close the file:
+    logging.debug("Engine has been configured")
+    handler.close()
+
+def editEngineSysconfigJava(javaHome):
+    # Load the file:
+    logging.debug("Loading text file handler")
+    handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF_JAVA, 
readExisting=False)
+    handler.open()
+
+    # Save the Java home:
+    handler.editParam("JAVA_HOME", javaHome)
 
     # Save and close the file:
     logging.debug("Engine has been configured")
@@ -1228,15 +1236,18 @@
     else:
         raise Exception(output_messages.ERR_ENCRYPT_TOOL_NOT_FOUND)
 
-def configEncryptedPass(password):
+def editEngineSysconfigDatabase(dbUrl, password):
     """
     Push the encrypted password into the local configuration file.
     """
     logging.debug("Encrypting database password.")
-    handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF)
+    handler = TextConfigFileHandler(basedefs.FILE_ENGINE_CONF_DATABASE, 
readExisting=False)
     handler.open()
     handler.editParam("ENGINE_DB_USER", getDbUser())
     handler.editParam("ENGINE_DB_PASSWORD", password)
+    handler.editParam("ENGINE_DB_DRIVER", "org.postgresql.Driver")
+    handler.editParam("ENGINE_DB_URL", dbUrl)
+
     handler.close()
 
 # TODO: Support SystemD services
diff --git a/packaging/fedora/setup/engine-setup.py 
b/packaging/fedora/setup/engine-setup.py
index b77caac..f30e8e4 100755
--- a/packaging/fedora/setup/engine-setup.py
+++ b/packaging/fedora/setup/engine-setup.py
@@ -117,11 +117,11 @@
                         'steps'           : [ { 'title'     : 
output_messages.INFO_CONFIG_OVIRT_ENGINE,
                                                 'functions' : 
[setMaxSharedMemory] },
                                               { 'title'     : 
output_messages.INFO_FIND_JAVA,
-                                                'functions' : [_findJavaHome]},
+                                                'functions' : [_findJavaHome, 
_editSysconfigJava]},
                                               { 'title'     : 
output_messages.INFO_CREATE_CA,
                                                 'functions' : [_createCA]},
                                               { 'title'     : 
output_messages.INFO_UPD_ENGINE_CONF,
-                                                'functions' : [_editSysconfig] 
},
+                                                'functions' : 
[_editSysconfigProtocols] },
                                               { 'title'     : 
output_messages.INFO_SET_DB_CONFIGURATION,
                                                 'functions' : 
[_updatePgPassFile]}]
                        },
@@ -129,7 +129,7 @@
                         'condition'       : [_isDbAlreadyInstalled],
                         'condition_match' : [True],
                         'steps'           : [ { 'title'     : 
output_messages.INFO_SET_DB_SECURITY,
-                                                'functions' : [_encryptDBPass, 
_configEncryptedPass] },
+                                                'functions' : [_encryptDBPass, 
_editSysconfigDatabase] },
                                               {  'title'     : 
output_messages.INFO_UPGRADE_DB,
                                                 'functions' : 
[stopRhevmDbRelatedServices, _upgradeDB, _setApplicationMode, 
startRhevmDbRelatedServices]} ]
                        },
@@ -137,7 +137,7 @@
                         'condition'       : [_isDbAlreadyInstalled],
                         'condition_match' : [False],
                         'steps'           : [ { 'title'     : 
output_messages.INFO_SET_DB_SECURITY,
-                                                'functions' : [_encryptDBPass, 
_configEncryptedPass]},
+                                                'functions' : [_encryptDBPass, 
_editSysconfigDatabase]},
                                               { 'title'     : 
output_messages.INFO_CREATE_DB,
                                                 'functions' : [_createDB,  
_updateVDCOptions, _setApplicationMode]},
                                               { 'title'     : 
output_messages.INFO_UPD_DC_TYPE,
@@ -2050,33 +2050,34 @@
         logging.warn("Failed to start rhevm-notifierd")
         controller.MESSAGES.append(output_messages.ERR_FAILED_START_SERVICE % 
"rhevm-notifierd")
 
-def _configEncryptedPass():
+def _editSysconfigDatabase():
     """
     Push the encrypted password into the local configuration file.
     """
     try:
-        utils.configEncryptedPass(controller.CONF["ENCRYPTED_DB_PASS"])
+        dbUrl = "jdbc:postgresql://" + getDbHostName() + ":" + getDbPort() + 
"/" + basedefs.DB_NAME
+        if "DB_SECURE_CONNECTION" in controller.CONF.keys() and 
controller.CONF["DB_SECURE_CONNECTION"] == "yes":
+            dbUrl = dbUrl + 
"?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"
+
+        utils.editEngineSysconfigDatabase(dbUrl=dbUrl, 
password=controller.CONF["ENCRYPTED_DB_PASS"])
     except:
         logging.error("ERROR Editing engine local configuration file.")
         logging.error(traceback.format_exc())
         raise Exception(output_messages.ERR_EXP_FAILED_CONFIG_ENGINE)
 
-def _editSysconfig():
+def _editSysconfigProtocols():
     """
     Update the local configuration file.
     """
-    dbUrl = "jdbc:postgresql://" + getDbHostName() + ":" + getDbPort() + "/" + 
basedefs.DB_NAME
-    if "DB_SECURE_CONNECTION" in controller.CONF.keys() and 
controller.CONF["DB_SECURE_CONNECTION"] == "yes":
-        dbUrl = dbUrl + 
"?ssl=true&sslfactory=org.postgresql.ssl.NonValidatingFactory"
-
     proxyEnabled = 
utils.compareStrIgnoreCase(controller.CONF["OVERRIDE_HTTPD_CONFIG"], "yes")
-    utils.editEngineSysconfig(proxyEnabled=proxyEnabled,
-                              dbUrl=dbUrl,
-                              dbUser=utils.getDbUser(),
+    utils.editEngineSysconfigProtocols(proxyEnabled=proxyEnabled,
                               fqdn=controller.CONF["HOST_FQDN"],
                               http=controller.CONF["HTTP_PORT"],
-                              https=controller.CONF["HTTPS_PORT"],
-                              javaHome=controller.CONF["JAVA_HOME"])
+                              https=controller.CONF["HTTPS_PORT"])
+
+def _editSysconfigJava():
+    utils.editEngineSysconfigJava(
+      javaHome=controller.CONF["JAVA_HOME"])
 
 def startRhevmDbRelatedServices():
     """


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

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

Reply via email to