Alex Lourie has uploaded a new change for review.

Change subject: packaging: cleaning zombie tasks before the upgrade
......................................................................

packaging: cleaning zombie tasks before the upgrade

* Added a use of utility that checks the system and finds
zombie async tasks. If such tasks are found, we clean them,
including the related compensasions.

* Updated the implementaion of the maintenance mode. Now
instead of starting the engine with different ports we use
the "real" maintenance mode provided by the engine and implemented
with the commit [1].

[1] SHA 9173096a1a6324045d13429ce9d704b7cc97d2ef
    Patch: http://gerrit.ovirt.org/#/c/8669
    Bug-URL: https://bugzilla.redhat.com/868639

Change-Id: Iad4fdd62493085b7ecb4d51fb54e8057418075e1
Signed-off-by: Alex Lourie <[email protected]>
---
M packaging/fedora/setup/basedefs.py
M packaging/fedora/setup/common_utils.py
M packaging/fedora/setup/engine-upgrade.py
M packaging/fedora/setup/output_messages.py
4 files changed, 69 insertions(+), 8 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/59/11159/1

diff --git a/packaging/fedora/setup/basedefs.py 
b/packaging/fedora/setup/basedefs.py
index f8b03a2..46fd912 100644
--- a/packaging/fedora/setup/basedefs.py
+++ b/packaging/fedora/setup/basedefs.py
@@ -157,6 +157,7 @@
 EXEC_SETSEBOOL="/usr/sbin/setsebool"
 EXEC_SEMANAGE="/usr/sbin/semanage"
 EXEC_KEYTOOL="/usr/bin/keytool"
+EXEC_TASK_CLEANER = "/usr/share/ovirt-engine/dbscripts/taskcleaner.sh"
 
 CONST_BASE_MAC_ADDR="00:1A:4A"
 CONST_DEFAULT_MAC_RANGE="00:1a:4a:16:84:02-00:1a:4a:16:84:fd"
diff --git a/packaging/fedora/setup/common_utils.py 
b/packaging/fedora/setup/common_utils.py
index e5c1e06..0aad189 100755
--- a/packaging/fedora/setup/common_utils.py
+++ b/packaging/fedora/setup/common_utils.py
@@ -1485,23 +1485,24 @@
     # If everything went fine, return the original value
     return originalTimeout
 
+
 def configureEngineForMaintenance():
     # Try to reconfigure the engine and raise an exception if it fails
     try:
-        if not os.path.exists(basedefs.DIR_ENGINE_SYSCONFIG):
-            os.mkdir(basedefs.DIR_ENGINE_SYSCONFIG)
-        with open(basedefs.FILE_ENGINE_SYSCONFIG_MAINTENANCE, "w") as 
configFile:
-            configFile.write("ENGINE_HTTP_ENABLED=false\n")
-            configFile.write("ENGINE_HTTPS_ENABLED=false\n")
-            configFile.write("ENGINE_AJP_ENABLED=false\n")
+        updateVDCOption(key="EngineMode", value="MaintenanceMode")
     except:
         logging.error(traceback.format_exc())
         restoreEngineFromMaintenance()
         raise
 
+
 def restoreEngineFromMaintenance():
-    if os.path.exists(basedefs.FILE_ENGINE_SYSCONFIG_MAINTENANCE):
-        os.remove(basedefs.FILE_ENGINE_SYSCONFIG_MAINTENANCE)
+    try:
+        # Try to restore the regular state.
+        updateVDCOption(key="EngineMode", value="Regular")
+    except:
+        logging.error(traceback.format_exc())
+        raise
 
 # Returns db size in MB
 def getDbSize(dbname):
diff --git a/packaging/fedora/setup/engine-upgrade.py 
b/packaging/fedora/setup/engine-upgrade.py
index 6bc4b3b..88d4081 100755
--- a/packaging/fedora/setup/engine-upgrade.py
+++ b/packaging/fedora/setup/engine-upgrade.py
@@ -758,6 +758,54 @@
             MSG_ERROR_CONNECT_DB
         )
 
+
+def zombieTasksFound():
+    """
+    Fetching and cleaning zombie async tasks
+    """
+    cmd = [
+        basedefs.EXEC_TASK_CLEANER,
+        "-u", SERVER_ADMIN,
+        "-d", basedefs.DB_NAME,
+        "-z",
+    ]
+
+    tasks, rc = utils.execCmd(cmdList=cmd,
+                              failOnError=False,
+                              msg="Can't get zombie async tasks",
+                             )
+
+    if rc > 1:
+        raise Exception(output_messages.ERR_CANT_GET_ZOMBIE_TASKS)
+
+    # If tasks has content and exit status 0, return True
+    return (tasks and not rc)
+
+
+def clearZombieTasks():
+    """
+    Clear zombie tasks, raise Exception if it fails.
+    """
+    cmd = [
+        basedefs.EXEC_TASK_CLEANER,
+        "-u", SERVER_ADMIN,
+        "-d", basedefs.DB_NAME,
+        "-z",
+        "-R",
+        "-C",
+        "-J",
+        "-q",
+    ]
+
+    out, rc = utils.execCmd(cmdList=cmd,
+                  failOnError=False,
+                  msg="Can't clear zombie tasks",
+                 )
+
+    if rc > 1:
+        raise Exception(output_messages.ERR_CANT_CLEAR_ZOMBIE_TASKS)
+
+
 def deployDbAsyncTasks(dbName=basedefs.DB_NAME):
     # Deploy DB functionality first
     cmd = [
@@ -1029,6 +1077,10 @@
                 if not options.ignore_tasks:
                     # Check that there are no running tasks/compensations
                     try:
+                        if zombieTasksFound():
+                        # Now, clean zombie tasks. We assume that the tool 
works.
+                            runFunc([clearZombieTasks], 
output_messages.MSG_CLEAN_ASYNC)
+
                         checkRunningTasks()
                     # If something went wrong, restart DB services and the 
engine
                     except:
diff --git a/packaging/fedora/setup/output_messages.py 
b/packaging/fedora/setup/output_messages.py
index 7bbd8f6..b210e39 100644
--- a/packaging/fedora/setup/output_messages.py
+++ b/packaging/fedora/setup/output_messages.py
@@ -446,3 +446,10 @@
 MSG_STOP_UPGRADE_SPACE = "Not enough free space available for the upgrade 
operation.\
 Stopping upgrade.\nIf you would like to perform an upgrade and ignore the 
space check,\n\
 run the upgrade with --no-space-check option"
+
+# Async tasks Errors
+MSG_CLEAN_ASYNC = "Cleaning async tasks"
+ERR_CANT_GET_ZOMBIE_TASKS = "Error: failed to get async tasks status"
+ERR_CANT_CLEAR_ZOMBIE_TASKS = "Error: failed to clear stale async tasks"
+
+


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

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