Shirly Radco has uploaded a new change for review.

Change subject: packaging: setup: keep and use dwh db credentials
......................................................................

packaging: setup: keep and use dwh db credentials

Change-Id: I37a5d82581403e8dbd39fc07f90bd3d7c2510222
Bug-Url: https://bugzilla.redhat.com/1156040
Bug-Url: https://bugzilla.redhat.com/1118322
Signed-off-by: Yedidyah Bar David <[email protected]>
(cherry picked from commit 8b1a7d6b2ac3fc8d9b517b7cddb5fab8a65c4bef)
---
M Makefile
M packaging/setup/ovirt_engine_setup/reports/constants.py
M 
packaging/setup/plugins/ovirt-engine-common/ovirt-engine-reports/db/connection.py
M 
packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/__init__.py
A 
packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/database.py
5 files changed, 180 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/43/34543/1

diff --git a/Makefile b/Makefile
index e4d4548..6b1e4ef 100644
--- a/Makefile
+++ b/Makefile
@@ -81,7 +81,7 @@
 
 .in:
        sed \
-       -e 
"s|@SERVICE_DEFAULTS@|$(DATA_DIR)/services/ovirt-engine-reportsd/ovirt-engine-reportsd.conf|g"
 \
+       -e 
"s|@SERVICE_DEFAULTS@|$(PKG_DATA_DIR)/services/ovirt-engine-reportsd/ovirt-engine-reportsd.conf|g"
 \
        -e "s|@SERVICE_VARS@|$(PKG_SYSCONF_DIR)/ovirt-engine-reports.conf|g" \
        -e "s|@PKG_USER@|$(PKG_USER)|g" \
        -e "s|@PKG_GROUP@|$(PKG_GROUP)|g" \
diff --git a/packaging/setup/ovirt_engine_setup/reports/constants.py 
b/packaging/setup/ovirt_engine_setup/reports/constants.py
index a833bde..ec9169a 100644
--- a/packaging/setup/ovirt_engine_setup/reports/constants.py
+++ b/packaging/setup/ovirt_engine_setup/reports/constants.py
@@ -155,6 +155,10 @@
         SERVICE_VARS_D,
         '10-setup-jboss.conf',
     )
+    REPORTS_SERVICE_CONFIG_DATABASE = os.path.join(
+        SERVICE_VARS_D,
+        '10-setup-database.conf',
+    )
     PKG_STATE_DIR = config.PKG_STATE_DIR
     PKG_DATA_DIR = config.PKG_DATA_DIR
     PKG_JAVA_DIR = config.PKG_JAVA_DIR
@@ -611,4 +615,13 @@
         return 'OVESETUP_ENGINE_CONFIG/fqdn'
 
 
[email protected]
[email protected]
+@osetupattrsclass
+class DWHCoreEnv(object):
+    """Sync with ovirt-dwh"""
+
+    ENABLE = 'OVESETUP_DWH_CORE/enable'
+
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-reports/db/connection.py
 
b/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-reports/db/connection.py
index 01130bc..5eb0dcb 100644
--- 
a/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-reports/db/connection.py
+++ 
b/packaging/setup/plugins/ovirt-engine-common/ovirt-engine-reports/db/connection.py
@@ -31,6 +31,9 @@
 from otopi import plugin
 
 
+from ovirt_engine import configfile
+
+
 from ovirt_engine_setup import constants as osetupcons
 from ovirt_engine_setup.reports import constants as oreportscons
 from ovirt_engine_setup.engine_common import database
@@ -231,5 +234,72 @@
                 else:
                     raise RuntimeError(msg)
 
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+        condition=lambda self: (
+            self.environment[oreportscons.CoreEnv.ENABLE] and
+            # If dwh is enabled, let it check its own stuff
+            not self.environment.get(oreportscons.DWHCoreEnv.ENABLE)
+        ),
+    )
+    def _dwh_setup(self):
+        config = configfile.ConfigFile([
+            oreportscons.FileLocations.SERVICE_DEFAULTS,
+            oreportscons.FileLocations.SERVICE_VARS,
+        ])
+        if config.get('DWH_DB_PASSWORD'):
+            try:
+                dbenv = {}
+                for e, k in (
+                    (oreportscons.DWHDBEnv.HOST, 'DWH_DB_HOST'),
+                    (oreportscons.DWHDBEnv.PORT, 'DWH_DB_PORT'),
+                    (oreportscons.DWHDBEnv.USER, 'DWH_DB_USER'),
+                    (oreportscons.DWHDBEnv.PASSWORD, 'DWH_DB_PASSWORD'),
+                    (oreportscons.DWHDBEnv.DATABASE, 'DWH_DB_DATABASE'),
+                ):
+                    dbenv[e] = (
+                        self.environment.get(e)
+                        if self.environment.get(e) is not None
+                        else config.get(k)
+                    )
+                for e, k in (
+                    (oreportscons.DWHDBEnv.SECURED, 'DWH_DB_SECURED'),
+                    (
+                        oreportscons.DWHDBEnv.SECURED_HOST_VALIDATION,
+                        'DWH_DB_SECURED_VALIDATION'
+                    )
+                ):
+                    dbenv[e] = config.getboolean(k)
+
+                dbovirtutils = database.OvirtUtils(
+                    plugin=self,
+                    dbenvkeys=oreportscons.Const.DWH_DB_ENV_KEYS,
+                )
+                dbovirtutils.tryDatabaseConnect(dbenv)
+                self.environment.update(dbenv)
+                self.environment[
+                    oreportscons.DWHDBEnv.NEW_DATABASE
+                ] = dbovirtutils.isNewDatabase()
+            except RuntimeError as e:
+                self.logger.debug(
+                    'Existing credential use failed',
+                    exc_info=True,
+                )
+                msg = _(
+                    'Cannot connect to DWH database using existing '
+                    'credentials: {user}@{host}:{port}'
+                ).format(
+                    host=dbenv[oreportscons.DWHDBEnv.HOST],
+                    port=dbenv[oreportscons.DWHDBEnv.PORT],
+                    database=dbenv[oreportscons.DWHDBEnv.DATABASE],
+                    user=dbenv[oreportscons.DWHDBEnv.USER],
+                )
+                if self.environment[
+                    osetupcons.CoreEnv.ACTION
+                ] == osetupcons.Const.ACTION_REMOVE:
+                    self.logger.warning(msg)
+                else:
+                    raise RuntimeError(msg)
+
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/__init__.py
 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/__init__.py
index b6b99da..4263413 100644
--- 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/__init__.py
+++ 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/__init__.py
@@ -26,6 +26,7 @@
 from . import jboss
 from . import protocols
 from . import sso
+from . import database
 
 
 @util.export
@@ -37,6 +38,7 @@
     jboss.Plugin(context=context)
     protocols.Plugin(context=context)
     sso.Plugin(context=context)
+    database.Plugin(context=context)
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/database.py
 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/database.py
new file mode 100644
index 0000000..72b06bb
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-setup/ovirt-engine-reports/config/database.py
@@ -0,0 +1,94 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2014 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Database plugin."""
+
+
+import gettext
+_ = lambda m: gettext.dgettext(message=m, domain='ovirt-engine-reports')
+
+
+from otopi import constants as otopicons
+from otopi import util
+from otopi import filetransaction
+from otopi import plugin
+
+
+from ovirt_engine import util as outil
+
+
+from ovirt_engine_setup import constants as osetupcons
+from ovirt_engine_setup.reports import constants as oreportscons
+
+
[email protected]
+class Plugin(plugin.PluginBase):
+    """Databsae plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda self: self.environment[oreportscons.CoreEnv.ENABLE],
+    )
+    def _misc(self):
+        uninstall_files = []
+        self.environment[
+            osetupcons.CoreEnv.REGISTER_UNINSTALL_GROUPS
+        ].addFiles(
+            group='ovirt_reports_files',
+            fileList=uninstall_files,
+        )
+        self.environment[otopicons.CoreEnv.MAIN_TRANSACTION].append(
+            filetransaction.FileTransaction(
+                name=(
+                    oreportscons.FileLocations.
+                    REPORTS_SERVICE_CONFIG_DATABASE
+                ),
+                mode=0o600,
+                owner=self.environment[osetupcons.SystemEnv.USER_ENGINE],
+                enforcePermissions=True,
+                content=(
+                    'DWH_DB_HOST="{host}"\n'
+                    'DWH_DB_PORT="{port}"\n'
+                    'DWH_DB_USER="{user}"\n'
+                    'DWH_DB_PASSWORD="{password}"\n'
+                    'DWH_DB_DATABASE="{db}"\n'
+                    'DWH_DB_SECURED="{secured}"\n'
+                    'DWH_DB_SECURED_VALIDATION="{securedValidation}"\n'
+                ).format(
+                    host=self.environment[oreportscons.DWHDBEnv.HOST],
+                    port=self.environment[oreportscons.DWHDBEnv.PORT],
+                    user=self.environment[oreportscons.DWHDBEnv.USER],
+                    password=outil.escape(
+                        self.environment[oreportscons.DWHDBEnv.PASSWORD],
+                        '"\\$',
+                    ),
+                    db=self.environment[oreportscons.DWHDBEnv.DATABASE],
+                    secured=self.environment[oreportscons.DWHDBEnv.SECURED],
+                    securedValidation=self.environment[
+                        oreportscons.DWHDBEnv.SECURED_HOST_VALIDATION
+                    ],
+                ),
+                modifiedList=uninstall_files,
+            )
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I37a5d82581403e8dbd39fc07f90bd3d7c2510222
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-reports
Gerrit-Branch: ovirt-engine-reports-3.5
Gerrit-Owner: Shirly Radco <[email protected]>
Gerrit-Reviewer: Yedidyah Bar David <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to