Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: set engine db credentials from config
......................................................................

packaging: setup: set engine db credentials from config

engine-setup writes the engine database credentials to the dwh db
config file, but did not read them from there on the next run, instead
asking for them again.

Change-Id: I1e07b41d2834f74d4babe6429c2ba3979a4b12ed
Bug-Url: https://bugzilla.redhat.com/1156039
Bug-Url: https://bugzilla.redhat.com/1128787
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M 
packaging/setup/plugins/ovirt-engine-common/ovirt-engine-dwh/db/engine_connection.py
1 file changed, 72 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-dwh refs/changes/27/34427/1

diff --git 
a/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-dwh/db/engine_connection.py
 
b/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-dwh/db/engine_connection.py
index 5234e11..dd29f4a 100644
--- 
a/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-dwh/db/engine_connection.py
+++ 
b/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-dwh/db/engine_connection.py
@@ -29,6 +29,9 @@
 from otopi import plugin
 
 
+from ovirt_engine import configfile
+
+
 from ovirt_engine_setup.dwh import constants as odwhcons
 from ovirt_engine_setup.engine_common import database
 from ovirt_engine_setup.engine_common \
@@ -82,6 +85,75 @@
         )
 
     @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+        after=(
+            oengcommcons.Stages.DB_CONNECTION_SETUP,
+        ),
+        # If engine is enabled too, we let its plugin read the setup
+        condition=lambda self: not self.environment[
+            odwhcons.EngineCoreEnv.ENABLE
+        ],
+    )
+    def _setup_engine_db_credentials(self):
+        config = configfile.ConfigFile([
+            odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG_DEFAULTS,
+            odwhcons.FileLocations.OVIRT_ENGINE_DWHD_SERVICE_CONFIG,
+        ])
+        if config.get('ENGINE_DB_PASSWORD'):
+            try:
+                dbenv = {}
+                for e, k in (
+                    (odwhcons.EngineDBEnv.HOST, 'ENGINE_DB_HOST'),
+                    (odwhcons.EngineDBEnv.PORT, 'ENGINE_DB_PORT'),
+                    (odwhcons.EngineDBEnv.USER, 'ENGINE_DB_USER'),
+                    (odwhcons.EngineDBEnv.PASSWORD, 'ENGINE_DB_PASSWORD'),
+                    (odwhcons.EngineDBEnv.DATABASE, 'ENGINE_DB_DATABASE'),
+                ):
+                    dbenv[e] = (
+                        self.environment.get(e)
+                        if self.environment.get(e) is not None
+                        else config.get(k)
+                    )
+                for e, k in (
+                    (odwhcons.EngineDBEnv.SECURED, 'ENGINE_DB_SECURED'),
+                    (
+                        odwhcons.EngineDBEnv.SECURED_HOST_VALIDATION,
+                        'ENGINE_DB_SECURED_VALIDATION'
+                    )
+                ):
+                    dbenv[e] = config.getboolean(k)
+
+                dbovirtutils = database.OvirtUtils(
+                    plugin=self,
+                    dbenvkeys=odwhcons.Const.ENGINE_DB_ENV_KEYS,
+                )
+                dbovirtutils.tryDatabaseConnect(dbenv)
+                self.environment.update(dbenv)
+                self.environment[
+                    odwhcons.EngineDBEnv.NEW_DATABASE
+                ] = dbovirtutils.isNewDatabase()
+            except RuntimeError as e:
+                self.logger.debug(
+                    'Existing credential use failed',
+                    exc_info=True,
+                )
+                msg = _(
+                    'Cannot connect to Engine database using existing '
+                    'credentials: {user}@{host}:{port}'
+                ).format(
+                    host=dbenv[odwhcons.EngineDBEnv.HOST],
+                    port=dbenv[odwhcons.EngineDBEnv.PORT],
+                    database=dbenv[odwhcons.EngineDBEnv.DATABASE],
+                    user=dbenv[odwhcons.EngineDBEnv.USER],
+                )
+                if self.environment[
+                    osetupcons.CoreEnv.ACTION
+                ] == osetupcons.Const.ACTION_REMOVE:
+                    self.logger.warning(msg)
+                else:
+                    raise RuntimeError(msg)
+
+    @plugin.event(
         stage=plugin.Stages.STAGE_CUSTOMIZATION,
         condition=lambda self: self.environment[odwhcons.CoreEnv.ENABLE],
         before=(


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

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

Reply via email to