Yedidyah Bar David has uploaded a new change for review. Change subject: packaging: setup: try drop/create database ......................................................................
packaging: setup: try drop/create database If 'drop owned cascade' fails with user 'postgres', try drop/create database instead. 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 1 file changed, 52 insertions(+), 10 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/54/23054/1 diff --git a/packaging/common_utils.py b/packaging/common_utils.py index dc87fc9..a53fefc 100755 --- a/packaging/common_utils.py +++ b/packaging/common_utils.py @@ -896,16 +896,48 @@ clears the given DB """ 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, - failOnError=True, - envDict={'ENGINE_PGPASS': TEMP_PGPASS}, - ) + try: + logging.debug("Trying with drop owned by user cascade") + execSqlCmd( + sql_query=( + 'drop owned by {user} cascade;' + ).format( + user=db_dict['username'], + ), + db_dict=db_dict, + failOnError=True, + envDict={'ENGINE_PGPASS': TEMP_PGPASS}, + ) + except Exception as e: + logging.debug("Failed: {error}".format(error=e)) + if db_dict['username'] == 'postgres': + logging.debug("Trying with drop/create database") + db_dict_copy = db_dict.copy() + db_dict_copy['dbname'] = 'postgres' + execSqlCmd( + sql_query=( + 'drop database {dbname};' + ).format( + dbname=db_dict['dbname'], # not db_dict_copy! + ), + db_dict=db_dict_copy, + failOnError=True, + envDict={'ENGINE_PGPASS': TEMP_PGPASS}, + ) + execSqlCmd( + sql_query=( + ( + 'create database {database} ' + 'encoding \'UTF8\' LC_COLLATE \'en_US.UTF-8\' ' + 'LC_CTYPE \'en_US.UTF-8\' template template0;' + ).format( + database=db_dict['dbname'], + ) + ), + db_dict=db_dict_copy, + failOnError=True, + envDict={'ENGINE_PGPASS': TEMP_PGPASS}, + ) def getConfiguredIps(): try: @@ -974,6 +1006,16 @@ dwh_db_password=db_dict['dwh_db_password'], ), ) + if db_dict['engine_user'] == 'postgres': + f.write( + '{host}:{port}:{database}:{user}:{password}\n'.format( + host=db_dict['host'], + port=db_dict['port'], + database='postgres', + user='postgres', + password=db_dict['engine_pass'], + ) + ) return pgpass -- To view, visit http://gerrit.ovirt.org/23054 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I2f34be79cbf4eec9f18f33dd735ba0c1fff00d92 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-reports Gerrit-Branch: master Gerrit-Owner: Yedidyah Bar David <d...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches