Sandro Bonazzola has uploaded a new change for review. Change subject: packaging: setup: check database object ownership on upgrade ......................................................................
packaging: setup: check database object ownership on upgrade check database object ownership to engine before upgrade. If the owner is not engine, abort setup asking the user to run changedbowner.sh script for fixing it. Change-Id: I45b655e88c25dd51e567405cc6747b42dfd8a98b Bug-Url: https://bugzilla.redhat.com/1022691 Signed-off-by: Sandro Bonazzola <[email protected]> --- M packaging/setup/ovirt_engine_setup/constants.py M packaging/setup/plugins/ovirt-engine-setup/db/schema.py 2 files changed, 79 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/68/20968/1 diff --git a/packaging/setup/ovirt_engine_setup/constants.py b/packaging/setup/ovirt_engine_setup/constants.py index 376f277..ab6fd1e 100644 --- a/packaging/setup/ovirt_engine_setup/constants.py +++ b/packaging/setup/ovirt_engine_setup/constants.py @@ -164,6 +164,10 @@ OVIRT_ENGINE_DB_UTILS_DIR, 'taskcleaner.sh' ) + OVIRT_ENGINE_DB_CHANGE_OWNER = os.path.join( + OVIRT_ENGINE_DB_UTILS_DIR, + 'changedbowner.sh' + ) OVIRT_ENGINE_DB_DIR = os.path.join( OVIRT_ENGINE_DATADIR, diff --git a/packaging/setup/plugins/ovirt-engine-setup/db/schema.py b/packaging/setup/plugins/ovirt-engine-setup/db/schema.py index 70728ab..3e5cf74 100644 --- a/packaging/setup/plugins/ovirt-engine-setup/db/schema.py +++ b/packaging/setup/plugins/ovirt-engine-setup/db/schema.py @@ -89,6 +89,69 @@ def __init__(self, context): super(Plugin, self).__init__(context=context) + def _checkDatabaseOwnership(self): + statement = database.Statement(environment=self.environment) + result = statement.execute( + statement=""" + select + nsp.nspname as object_schema, + cls.relname as object_name, + rol.rolname as owner, + case cls.relkind + when 'r' then 'TABLE' + when 'i' then 'INDEX' + when 'S' then 'SEQUENCE' + when 'v' then 'VIEW' + when 'c' then 'TYPE' + else + cls.relkind::text + end as object_type + from + pg_class cls join + pg_roles rol on rol.oid = cls.relowner join + pg_namespace nsp on nsp.oid = cls.relnamespace + where + nsp.nspname not in ('information_schema', 'pg_catalog') and + nsp.nspname not like 'pg_toast%%' and + rol.rolname != %(user)s + order by + nsp.nspname, + cls.relname + """, + args=dict( + user=self.environment[osetupcons.DBEnv.USER], + ), + ownConnection=True, + transaction=False, + ) + if len(result) > 0: + raise RuntimeError( + _( + 'Cannot upgrade the database schema due to wrong ' + 'ownership of some database entities.\n' + 'Please execute: {command}\n' + 'Using the password of the "postgres" user.' + ).format( + command=( + '{cmd} ' + '-s {server} ' + '-p {port} ' + '-d {db} ' + '-f postgres ' + '-t {user}' + ).format( + cmd=( + osetupcons.FileLocations. + OVIRT_ENGINE_DB_CHANGE_OWNER + ), + server=self.environment[osetupcons.DBEnv.HOST], + port=self.environment[osetupcons.DBEnv.PORT], + db=self.environment[osetupcons.DBEnv.DATABASE], + user=self.environment[osetupcons.DBEnv.USER], + ), + ) + ) + def _checkSupportedVersionsPresent(self): # TODO: figure out a better way to do this for the future statement = database.Statement(environment=self.environment) @@ -129,6 +192,18 @@ ) @plugin.event( + stage=plugin.Stages.STAGE_VALIDATION, + after=( + osetupcons.Stages.DB_CREDENTIALS_AVAILABLE_EARLY, + ), + condition=lambda self: not self.environment[ + osetupcons.DBEnv.NEW_DATABASE + ], + ) + def _validation(self): + self._checkDatabaseOwnership() + + @plugin.event( stage=plugin.Stages.STAGE_MISC, name=osetupcons.Stages.DB_SCHEMA, after=( -- To view, visit http://gerrit.ovirt.org/20968 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I45b655e88c25dd51e567405cc6747b42dfd8a98b Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.3 Gerrit-Owner: Sandro Bonazzola <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
