Sandro Bonazzola has uploaded a new change for review.

Change subject: packaging: setup: force Apache proxy on upgrade
......................................................................

packaging: setup: force Apache proxy on upgrade

forcing migration to Apache proxy while upgrading
an existing instance.

Change-Id: Ib46bcf40acff860cd3e52634ade683d7a8836cf6
Bug-Url: https://bugzilla.redhat.com/905754
Signed-off-by: Sandro Bonazzola <[email protected]>
---
M packaging/fedora/setup/common_utils.py
M packaging/fedora/setup/engine-upgrade.py
2 files changed, 119 insertions(+), 15 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/15051/1

diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index b0a0cb5..11613c0 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -1035,6 +1035,17 @@
     else:
         return askYesNo(question)
 
+
+def askQuestion(question=None):
+    message = StringIO()
+    logging.debug('asking user: %s' % question)
+    message.write('%s: ' % question)
+    message.seek(0)
+    rawAnswer = raw_input(message.read())
+    logging.debug('user answered: %s' % rawAnswer)
+    return rawAnswer
+
+
 def retry(func, tries=None, timeout=None, sleep=1):
     """
     Retry a function. Wraps the retry logic so you don't have to
diff --git a/packaging/fedora/setup/engine-upgrade.py 
b/packaging/fedora/setup/engine-upgrade.py
index e72b6fd..f71ea78 100755
--- a/packaging/fedora/setup/engine-upgrade.py
+++ b/packaging/fedora/setup/engine-upgrade.py
@@ -18,6 +18,8 @@
 import output_messages
 from miniyum import MiniYum
 
+import engine_validators as validate
+
 # Consts
 
 # The following constants are used in maintenance mode for
@@ -165,6 +167,7 @@
 logFile = "ovirt-engine-upgrade.log"
 messages = []
 hostids = {}
+protocolsConfig = {}
 
 # Code
 def getOptions():
@@ -195,6 +198,21 @@
 
     parser.add_option("-n", "--no-space-check", help="Disable space check", 
action="store_true", default=False)
 
+    parser.add_option(
+        '--http-port',
+        help=output_messages.INFO_CONF_PARAMS_HTTP_PORT_USAGE,
+        action='store',
+        dest='http',
+        default='80'
+    )
+
+    parser.add_option(
+        '--https-port',
+        help=output_messages.INFO_CONF_PARAMS_HTTPS_PORT_USAGE,
+        action='store',
+        dest='https',
+        default='443'
+    )
 
     (options, args) = parser.parse_args()
     return (options, args)
@@ -236,6 +254,61 @@
 
     else:
         raise Exception(MSG_ERR_FAILED_STATUS_ENGINE_SERVICE)
+
+
+def checkHttpd(options):
+    handler = utils.TextConfigFileHandler(
+        basedefs.FILE_ENGINE_CONF_PROTOCOLS,
+        readExisting=True,
+    )
+    handler.open()
+    answer = False
+    haveConfig = False
+    proxyEnabled = handler.getParam('ENGINE_PROXY_ENABLED') == 'true'
+    if proxyEnabled:
+        logging.debug('oVirt engine Apache proxy was enabled')
+        answer = True
+    elif options.unattended_upgrade:
+        logging.debug(
+            'oVirt engine Apache proxy was disabled but '
+            'we are running in unattended mode'
+        )
+        answer = True
+    else:
+        logging.debug('oVirt engine Apache proxy was disabled')
+        print (
+            'The Apache service will be stopped and configured for '
+            'acting as proxy for the application'
+        )
+        answer = utils.askYesNo(INFO_Q_PROCEED)
+    if not answer:
+        logging.debug('User chose not to enable apache proxy')
+    else:
+        srv = utils.Service(basedefs.HTTPD_SERVICE_NAME)
+        srv.stop(False)
+        if proxyEnabled:
+            options.http = handler.getParam('ENGINE_PROXY_HTTP_PORT')
+            options.https = handler.getParam('ENGINE_PROXY_HTTPS_PORT')
+        if options.unattended_upgrade:
+            if (
+                options.http and validate.validatePort(options.http) and
+                options.https and validate.validatePort(options.https)
+            ):
+                haveConfig = True
+        else:
+            while not (options.http and validate.validatePort(options.http)):
+                options.http = utils.askQuestion(
+                    output_messages.INFO_CONF_PARAMS_HTTP_PORT_PROMPT
+                )
+            while not (options.https and validate.validatePort(options.https)):
+                options.https = utils.askQuestion(
+                    output_messages.INFO_CONF_PARAMS_HTTPS_PORT_PROMPT
+                )
+            haveConfig = True
+        srv.start(True)
+    handler.close()
+    return answer and haveConfig
+
 
 def initLogging():
     global logFile
@@ -1067,6 +1140,19 @@
             newFile = os.path.join(basedefs.DIR_ENGINE_CONF, fileName)
             shutil.copyfile(oldFile, newFile)
 
+    handler = utils.TextConfigFileHandler(
+        basedefs.FILE_ENGINE_CONF_PROTOCOLS,
+        readExisting=True
+    )
+    handler.open()
+    fqdn = handler.getParam('ENGINE_FQDN')
+    handler.close()
+    utils.editEngineSysconfigProtocols(
+        fqdn=fqdn,
+        http=options.http,
+        https=options.https,
+    )
+
 
 def deleteEngineSysconfig():
     # Delete the old configuration file and the backup made by RPM:
@@ -1158,10 +1244,10 @@
 
 def updateHttpdConf():
     """
-    Update httpd configuration if it's used by the existing setup.
-    Update root redirection if it's used by existing setup else
-    ask if root redirection should be enabled.
+    Update httpd configuration forcing proxy on upgrade.
     """
+    srv = utils.Service(basedefs.HTTPD_SERVICE_NAME)
+    srv.stop(False)
     if os.path.exists(basedefs.FILE_OVIRT_HTTPD_CONF_LEGACY):
         os.rename(
             basedefs.FILE_OVIRT_HTTPD_CONF_LEGACY,
@@ -1170,17 +1256,18 @@
                 utils.getCurrentDateTime(),
             ),
         )
-        utils.processTemplate(
-            basedefs.FILE_OVIRT_HTTPD_CONF_TEMPLATE,
-            basedefs.FILE_OVIRT_HTTPD_CONF,
-            {
-                '@JBOSS_AJP_PORT@': basedefs.JBOSS_AJP_PORT,
-            }
-        )
-        utils.copyFile(
-            basedefs.FILE_OVIRT_HTTPD_CONF_ROOT_TEMPLATE,
-            basedefs.FILE_OVIRT_HTTPD_CONF_ROOT,
-        )
+    utils.processTemplate(
+        basedefs.FILE_OVIRT_HTTPD_CONF_TEMPLATE,
+        basedefs.FILE_OVIRT_HTTPD_CONF,
+        {
+            '@JBOSS_AJP_PORT@': basedefs.JBOSS_AJP_PORT,
+        }
+    )
+    utils.copyFile(
+        basedefs.FILE_OVIRT_HTTPD_CONF_ROOT_TEMPLATE,
+        basedefs.FILE_OVIRT_HTTPD_CONF_ROOT,
+    )
+    srv.start(True)
 
 
 def updateDatabaseConf():
@@ -1353,7 +1440,13 @@
             # No rollback in this case
             try:
                 # We ask the user before stoping ovirt-engine or take command 
line option
-                if options.unattended_upgrade or checkEngine(engineService):
+                if (
+                    (
+                        options.unattended_upgrade or
+                        checkEngine(engineService)
+                    ) and
+                    checkHttpd(options)
+                ):
                     # Stopping engine
                     runFunc(stopEngineService, MSG_INFO_STOP_ENGINE % 
engineService)
                     if updateRelatedToDB:


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

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

Reply via email to