Hello Yedidyah Bar David, I'd like you to do a code review. Please visit
http://gerrit.ovirt.org/23236 to review the following change. Change subject: packaging: setup: drop all objects ...................................................................... packaging: setup: drop all objects Instead of 'drop owned cascade', use cleandb.sh from dbscripts. Change-Id: I2f34be79cbf4eec9f18f33dd735ba0c1fff00d92 Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1049468 Signed-off-by: Yedidyah Bar David <d...@redhat.com> --- M packaging/common_utils.py M packaging/ovirt-engine-reports-setup.py M packaging/ovirt-engine-reports.spec.in 3 files changed, 34 insertions(+), 32 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/36/23236/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index b4636ec..cb13fa3 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -46,6 +46,8 @@ FILE_ENGINE_CONFIG_BIN="/usr/bin/engine-config" JRS_PACKAGE_PATH="/usr/share/jasperreports-server" +ENGINE_DBSCRIPTS_PATH="/usr/share/ovirt-engine/dbscripts" + # Defaults DB_ADMIN = "engine_reports" DB_HOST = "localhost" @@ -883,41 +885,40 @@ def createLang(db_dict, TEMP_PGPASS): - if runPostgresSuQuery('"show server_version;"')[0].strip() > '9.2.0': - logging.debug( - 'PSQL version is higher than 9.2, ' - 'no need to createlang' + try: + cmd = [ + '/usr/bin/createlang', + '--host=%s' % db_dict['host'], + '--port=%s' % db_dict['port'], + '--dbname=%s' % db_dict['dbname'], + '--username=%s' % db_dict['username'], + 'plpgsql', + ] + + execCmd( + cmdList=cmd, + failOnError=True, + envDict={'ENGINE_PGPASS': TEMP_PGPASS}, ) - return + except Exception as e: + logging.debug("createLang: %s" % e) - cmd = [ - '/usr/bin/createlang', - '--host=%s' % db_dict['host'], - '--port=%s' % db_dict['port'], - '--dbname=%s' % db_dict['dbname'], - '--username=%s' % db_dict['username'], - 'plpgsql', - ] - - execCmd( - cmdList=cmd, - failOnError=True, - envDict={'ENGINE_PGPASS': TEMP_PGPASS}, - ) - - -def clearDB(db_dict, TEMP_PGPASS): +def clearDB(db_dict, TEMP_PGPASS, log_file): """ clears the given DB """ + createLang(db_dict, TEMP_PGPASS) logging.debug("Clearing db %s contents" % db_dict['dbname']) - execSqlCmd( - sql_query=( - 'drop owned by {user} cascade;' - ).format( - user=db_dict['username'], - ), - db_dict=db_dict, + cmd = [ + '%s/%s' % (ENGINE_DBSCRIPTS_PATH, 'cleandb.sh'), + '-s', db_dict['host'], + '-d', db_dict['dbname'], + '-u', db_dict['username'], + '-p', db_dict['port'], + '-l', log_file, + ] + execCmd( + cmdList=cmd, failOnError=True, envDict={'ENGINE_PGPASS': TEMP_PGPASS}, ) diff --git a/packaging/ovirt-engine-reports-setup.py b/packaging/ovirt-engine-reports-setup.py index d69fb48..043fd8f 100755 --- a/packaging/ovirt-engine-reports-setup.py +++ b/packaging/ovirt-engine-reports-setup.py @@ -198,7 +198,7 @@ # If we need to refresh the war, we also need to drop the DB if DB_EXIST: logging.debug("Removing DB") - utils.clearDB(db_dict, TEMP_PGPASS) + utils.clearDB(db_dict, TEMP_PGPASS, log_file) DB_EXIST = False DB_EXISTED = True @@ -212,7 +212,7 @@ if not DB_EXISTED and utils.localHost(db_dict['host']): logging.debug('Creating DB') utils.createDB(db_dict) - utils.createLang(db_dict, TEMP_PGPASS) + utils.createLang(db_dict, TEMP_PGPASS) logging.debug("Installing Jasper") for cmd in ( 'init-js-db-ce', @@ -680,7 +680,7 @@ if os.path.exists(FILE_TMP_SQL_DUMP): logging.debug("DB Restore started") # Drop - utils.clearDB(db_dict, TEMP_PGPASS) + utils.clearDB(db_dict, TEMP_PGPASS, log_file) # Restore cmd = [ "/usr/bin/psql", diff --git a/packaging/ovirt-engine-reports.spec.in b/packaging/ovirt-engine-reports.spec.in index 3f3da44..a3055b8 100644 --- a/packaging/ovirt-engine-reports.spec.in +++ b/packaging/ovirt-engine-reports.spec.in @@ -44,6 +44,7 @@ Requires: java-1.7.0-openjdk Requires: jpackage-utils Requires: ovirt-engine >= 3.3.0 +Requires: ovirt-engine-dbscripts >= 3.3.0 Requires: ovirt-engine-dwh >= 3.3.0 Requires: jasperreports-server = 5.5.0-1 Requires: m2crypto -- To view, visit http://gerrit.ovirt.org/23236 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2f34be79cbf4eec9f18f33dd735ba0c1fff00d92 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-reports Gerrit-Branch: ovirt-3.3 Gerrit-Owner: Yaniv Dary <yd...@redhat.com> Gerrit-Reviewer: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches