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

Change subject: packaging: setup: remove the usage of rpm to check version
......................................................................

packaging: setup: remove the usage of rpm to check version

detect jasper version based on jar name instead of rpm version. this is
much simpler and cross platform.

Change-Id: I8799bde82f7c2da2b0a3074ea47e6ffc3eb898cd
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M packaging/legacy-setup/common_utils.py
M packaging/legacy-setup/ovirt-engine-reports-setup.py
2 files changed, 24 insertions(+), 70 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/19/23419/1

diff --git a/packaging/legacy-setup/common_utils.py 
b/packaging/legacy-setup/common_utils.py
index dd87796..f8ac244 100755
--- a/packaging/legacy-setup/common_utils.py
+++ b/packaging/legacy-setup/common_utils.py
@@ -640,14 +640,6 @@
 
     return (version, minorVersion, release)
 
-def getAppVersion(package):
-    '''
-    get the installed package version
-    '''
-    cmd = "rpm -q --queryformat %{VERSION}-%{RELEASE} " + package
-    output, rc = execExternalCmd(cmd, True, "Failed to get package version & 
release")
-    return output.rstrip()
-
 @transactionDisplay("Importing reports")
 def importReports(src, update=True):
     """
diff --git a/packaging/legacy-setup/ovirt-engine-reports-setup.py 
b/packaging/legacy-setup/ovirt-engine-reports-setup.py
index d0dcee3..009f1ea 100755
--- a/packaging/legacy-setup/ovirt-engine-reports-setup.py
+++ b/packaging/legacy-setup/ovirt-engine-reports-setup.py
@@ -12,6 +12,8 @@
 import sys
 import traceback
 import getpass
+import zipfile
+import contextlib
 import shutil
 import cracklib
 import types
@@ -68,7 +70,6 @@
 
 REPORTS_JARS_DIR = "/usr/share/java/ovirt-engine-reports"
 
-FILE_DEPLOY_VERSION = "/etc/ovirt-engine/jrs-deployment.version"
 OVIRT_SETUP_POST_INSTALL_CONFIG = 
"/etc/ovirt-engine-setup.conf.d/20-setup-ovirt-post.conf"
 OVIRT_REPORTS_ETC="/etc/ovirt-engine-reports"
 OVIRT_REPORTS_TRUST_STORE="%s/trust.jks" % OVIRT_REPORTS_ETC
@@ -148,33 +149,6 @@
 
     (options, args) = parser.parse_args()
     return (options, args)
-
-@transactionDisplay('Updating DB Schema')
-def updateDbSchema(db_dict, TEMP_PGPASS):
-    sql_files = os.listdir(REPORTS_DB_UPGRADE_SCRIPTS_DIR)
-    sql_files.sort()
-    reports_version_type = 'ce'
-    for sql_file in sql_files:
-        if (
-            not sql_file.startswith('upgrade-postgresql-') or
-            reports_version_type not in sql_file or
-            sql_file < 'upgrade-postgresql-4.7'
-        ):
-            continue
-
-        cmd = [
-            EXEC_PSQL,
-            '-U', db_dict['username'],
-            '-d', db_dict['dbname'],
-            '-h', db_dict['host'],
-            '-p', db_dict['port'],
-            '-f', os.path.join(REPORTS_DB_UPGRADE_SCRIPTS_DIR,sql_file)
-        ]
-        utils.execCmd(
-            cmdList=cmd,
-            failOnError=True,
-            envDict={'ENGINE_PGPASS': TEMP_PGPASS},
-        )
 
 @transactionDisplay("Deploying Server")
 def deployJs(db_dict, TEMP_PGPASS):
@@ -555,36 +529,32 @@
         shutil.copyfile(target, link)
 
 def isWarUpdated():
-    """
-    check the war version and compare it with current rpm version
-    """
-    warUpdated = False
-    if os.path.exists(FILE_DEPLOY_VERSION):
-        logging.debug("%s exists, checking version" % FILE_DEPLOY_VERSION)
 
-        fd = file(FILE_DEPLOY_VERSION, 'r')
-        deployedVersion = fd.readline()
-        deployedVersion = deployedVersion.strip()
-        found = re.search("(\d+\.\d+)\.(\d+\-.+)", deployedVersion)
-        if not found:
-            logging.error("%s is not a valid version string" % deployedVersion)
-            raise Exception("Cannot parse version string, please report this 
error")
+    jasperwar = os.path.join(REPORTS_SERVER_DIR, 'jasperserver.war')
 
-        rpmVersion = utils.getAppVersion(JRS_PACKAGE_NAME)
+    if not os.path.exists(jasperwar):
+        raise RuntimeError('Cannot locate jasper source war')
 
-        if deployedVersion != rpmVersion:
-            logging.debug("%s differs from %s, war deployment required" % 
(deployedVersion, rpmVersion))
-        else:
-            logging.debug("war directory is up to date with installed version")
-            warUpdated = True
-    else:
-        logging.debug("%s does not exist, assuming clean install" % 
FILE_DEPLOY_VERSION)
-        fd = open(FILE_DEPLOY_VERSION, "w")
-        fd.write(utils.getAppVersion(JRS_PACKAGE_NAME))
-        fd.close()
-        logging.debug("Created JRS version file")
+    sourcejar = None
+    with contextlib.closing(zipfile.ZipFile(jasperwar, 'r')) as f:
+        for n in f.namelist():
+            n = os.path.basename(n)
+            if re.match(r'jasperreports-\d.*\.jar', n):
+                sourcejar = n
+                break
+    logging.debug("source jasper jar %s", sourcejar)
+    if not sourcejar:
+        raise RuntimeError('Cannot determine installed jasper version')
 
-    return warUpdated
+    currentjar = ''
+    if os.path.exists(os.path.join(DIR_WAR, 'WEB-INF/lib')):
+        currentjar = glob.glob(os.path.join(DIR_WAR, 
'WEB-INF/lib/jasperreports-[0-9]*.jar'))
+        logging.debug("current jasper jar %s", currentjar)
+        if len(currentjar) != 1:
+            raise RuntimeError('Cannot determine current jasper version')
+        currentjar = os.path.basename(currentjar[0])
+
+    return sourcejar == currentjar
 
 @transactionDisplay("Exporting scheduled reports")
 def exportScheduale():
@@ -1113,14 +1083,6 @@
                     )
 
                 _exitBadState()
-
-            if not warUpdated and isWarInstalled():
-                backupWAR()
-                with open(FILE_DEPLOY_VERSION, 'r') as verfile:
-                    for line in verfile.readlines():
-                        if line.startswith('4.7'):
-                            updateDbSchema(db_dict, TEMP_PGPASS)
-                            break
 
             # Catch failures on configuration
             try:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8799bde82f7c2da2b0a3074ea47e6ffc3eb898cd
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-reports
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