Sandro Bonazzola has uploaded a new change for review.

Change subject: node: added persistent storage configuration
......................................................................

node: added persistent storage configuration

Added persistent storage configuration on modified files
and directories when executed on oVirt Node / RHEV-H

Change-Id: I67afe1d994437eac841cc4217ed39f68d5b12374
Bug-Url: https://bugzilla.redhat.com/1151339
Signed-off-by: Sandro Bonazzola <sbona...@redhat.com>
---
M src/ovirt_hosted_engine_setup/constants.py
M src/ovirt_hosted_engine_setup/util.py
M src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
M src/plugins/ovirt-hosted-engine-setup/core/misc.py
M src/plugins/ovirt-hosted-engine-setup/pki/vdsmpki.py
5 files changed, 122 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-hosted-engine-setup 
refs/changes/40/34440/1

diff --git a/src/ovirt_hosted_engine_setup/constants.py 
b/src/ovirt_hosted_engine_setup/constants.py
index 5ddd7cf..1b5ef8d 100644
--- a/src/ovirt_hosted_engine_setup/constants.py
+++ b/src/ovirt_hosted_engine_setup/constants.py
@@ -296,6 +296,7 @@
     SCREEN_PROCEED = 'OVEHOSTED_CORE/screenProceed'
     CONFIRM_SETTINGS = 'OVEHOSTED_CORE/confirmSettings'
     RE_DEPLOY = 'OVEHOSTED_CORE/additionalHostReDeployment'
+    NODE_SETUP = 'OVEHOSTED_CORE/nodeSetup'
 
 
 @util.export
@@ -754,6 +755,8 @@
     HOST_ADDED = 'ohosted.engine.host.added'
     HA_START = 'ohosted.engine.ha.start'
     VDSM_LIBVIRT_CONFIGURED = 'ohosted.vdsm.libvirt.configured'
+    NODE_FILES_PERSIST_S = 'ohosted.node.files.persist.start'
+    NODE_FILES_PERSIST_E = 'ohosted.node.files.persist.end'
 
     DIALOG_TITLES_S_VM = 'ohosted.dialog.titles.vm.start'
     DIALOG_TITLES_E_VM = 'ohosted.dialog.titles.vm.end'
diff --git a/src/ovirt_hosted_engine_setup/util.py 
b/src/ovirt_hosted_engine_setup/util.py
index d482ad8..29a60f1 100644
--- a/src/ovirt_hosted_engine_setup/util.py
+++ b/src/ovirt_hosted_engine_setup/util.py
@@ -68,6 +68,18 @@
     return (UNICAST_MAC_ADDR.match(mac) is not None)
 
 
+def persist(path):
+    try:
+        from ovirt.node.utils.fs import Config
+        cfg = Config()
+        cfg.persist(path)
+    except ImportError:
+        raise RuntimeError(
+            'Use ohostedcons.CoreEnv.NODE_SETUP for ensuring module '
+            'availability'
+        )
+
+
 class VirtUserContext(object):
     """
     Switch to vdsm:kvm user with provided umask
diff --git a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py 
b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
index 185f626..0ea5b6d 100644
--- a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
+++ b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
@@ -33,6 +33,7 @@
 
 
 from ovirt_hosted_engine_setup import constants as ohostedcons
+from ovirt_hosted_engine_setup import util as ohostedutil
 
 
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
@@ -51,7 +52,8 @@
                 name=name,
             )
         )
-        with open(self.resolveFile(name), 'w') as f:
+        path = self.resolveFile(name)
+        with open(path, 'w') as f:
             f.write('[environment:default]\n')
             for c in ohostedcons.__dict__['__hosted_attrs__']:
                 for k in c.__dict__.values():
@@ -68,6 +70,17 @@
                                         else v,
                                     )
                                 )
+        if self.environment[ohostedcons.CoreEnv.NODE_SETUP]:
+            try:
+                ohostedutil.persist(path)
+            except Exception as e:
+                self.logger.debug(
+                    'Error persisting {path}'.format(
+                        path=path,
+                    ),
+                    exc_info=True,
+                )
+                self.logger.error(e)
 
     @plugin.event(
         stage=plugin.Stages.STAGE_INIT,
diff --git a/src/plugins/ovirt-hosted-engine-setup/core/misc.py 
b/src/plugins/ovirt-hosted-engine-setup/core/misc.py
index ddf0008..57d5821 100644
--- a/src/plugins/ovirt-hosted-engine-setup/core/misc.py
+++ b/src/plugins/ovirt-hosted-engine-setup/core/misc.py
@@ -1,6 +1,6 @@
 #
 # ovirt-hosted-engine-setup -- ovirt hosted engine setup
-# Copyright (C) 2013 Red Hat, Inc.
+# Copyright (C) 2013-2014 Red Hat, Inc.
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -31,6 +31,7 @@
 
 
 from ovirt_hosted_engine_setup import constants as ohostedcons
+from ovirt_hosted_engine_setup import util as ohostedutil
 
 
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
@@ -96,10 +97,69 @@
             ohostedcons.CoreEnv.REQUIREMENTS_CHECK_ENABLED,
             True
         )
+        self.environment[ohostedcons.CoreEnv.NODE_SETUP] = False
+        try:
+            # avoid: pyflakes 'Config' imported but unused error
+            import ovirt.node.utils.fs
+            if hasattr(ovirt.node.utils.fs, 'Config'):
+                self.environment[ohostedcons.CoreEnv.NODE_SETUP] = True
+        except ImportError:
+            self.logger.debug('Disabling persisting file configuration')
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLOSEUP,
+        name=ohostedcons.Stages.NODE_FILES_PERSIST_S,
+        after=(
+            ohostedcons.Stages.HA_START,
+        ),
+        before=(
+            ohostedcons.Stages.NODE_FILES_PERSIST_E,
+        ),
+        condition=lambda self: self.environment[
+            ohostedcons.CoreEnv.NODE_SETUP
+        ],
+    )
+    def _persist_files_start(self):
+        # Using two stages here because some files can be written out of
+        # transactions
+        self.logger.debug('Saving persisting file configuration')
+        for path in self.environment[
+            otopicons.CoreEnv.MODIFIED_FILES
+        ] + [
+            self.environment[otopicons.CoreEnv.LOG_DIR],
+        ]:
+            try:
+                ohostedutil.persist(path)
+            except Exception as e:
+                self.logger.debug(
+                    'Error persisting {path}'.format(
+                        path=path,
+                    ),
+                    exc_info=True,
+                )
+                self.logger.error(e)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CLOSEUP,
+        name=ohostedcons.Stages.NODE_FILES_PERSIST_E,
+        after=(
+            ohostedcons.Stages.NODE_FILES_PERSIST_S,
+        ),
+        condition=lambda self: self.environment[
+            ohostedcons.CoreEnv.NODE_SETUP
+        ],
+    )
+    def _persist_files_end(self):
+        # Using two stages here because some files can be written out of
+        # transactions
+        self.logger.debug('Finished persisting file configuration')
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CLOSEUP,
         priority=plugin.Stages.PRIORITY_LAST,
+        after=(
+            ohostedcons.Stages.NODE_FILES_PERSIST_E,
+        ),
     )
     def _closeup(self):
         self.dialog.note(
diff --git a/src/plugins/ovirt-hosted-engine-setup/pki/vdsmpki.py 
b/src/plugins/ovirt-hosted-engine-setup/pki/vdsmpki.py
index 84d3ae2..b107bff 100644
--- a/src/plugins/ovirt-hosted-engine-setup/pki/vdsmpki.py
+++ b/src/plugins/ovirt-hosted-engine-setup/pki/vdsmpki.py
@@ -35,6 +35,7 @@
 
 
 from ovirt_hosted_engine_setup import constants as ohostedcons
+from ovirt_hosted_engine_setup import util as ohostedutil
 
 
 _ = lambda m: gettext.dgettext(message=m, domain='ovirt-hosted-engine-setup')
@@ -287,6 +288,37 @@
             self._getSPICEcerts()
 
     @plugin.event(
+        stage=plugin.Stages.STAGE_CLOSEUP,
+        after=(
+            ohostedcons.Stages.NODE_FILES_PERSIST_S,
+        ),
+        before=(
+            ohostedcons.Stages.NODE_FILES_PERSIST_E,
+        ),
+        condition=lambda self: self.environment[
+            ohostedcons.CoreEnv.NODE_SETUP
+        ],
+    )
+    def _persist_files_start(self):
+        self.logger.debug('Saving persisting PKI configuration')
+        for path in (
+            ohostedcons.FileLocations.VDSMCERT,
+            ohostedcons.FileLocations.LIBVIRT_SPICE_SERVER_CERT,
+        ):
+            try:
+                if os.path.exists(path):
+                    # here we need the whole directory to be persisted
+                    ohostedutil.persist(os.path.dirname(path))
+            except Exception as e:
+                self.logger.debug(
+                    'Error persisting {path}'.format(
+                        path=path,
+                    ),
+                    exc_info=True,
+                )
+                self.logger.error(e)
+
+    @plugin.event(
         stage=plugin.Stages.STAGE_CLEANUP,
     )
     def _cleanup(self):


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67afe1d994437eac841cc4217ed39f68d5b12374
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
Gerrit-Branch: ovirt-hosted-engine-setup-1.2
Gerrit-Owner: Sandro Bonazzola <sbona...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to