Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: setup: clean up answer files writing
......................................................................

packaging: setup: clean up answer files writing

Always write one to /var/lib/ovirt-hosted-engine-setup/answers .

If user asked for one with --generate-answer, always write there.

Write to /etc only at end of successful setup.

Support relative paths for answer files.

Bug-Url: https://bugzilla.redhat.com/1151366
Bug-Url: https://bugzilla.redhat.com/1121057
Related-To: https://bugzilla.redhat.com/1025313
Change-Id: Icb28356a0ee38b325c53ec631b21b912e044d2a9
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M ovirt-hosted-engine-setup.spec.in
M src/bin/Makefile.am
M src/bin/ovirt-hosted-engine-setup
M src/ovirt_hosted_engine_setup/constants.py
M src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
M src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py
6 files changed, 48 insertions(+), 29 deletions(-)


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

diff --git a/ovirt-hosted-engine-setup.spec.in 
b/ovirt-hosted-engine-setup.spec.in
index 846ba57..82a801f 100644
--- a/ovirt-hosted-engine-setup.spec.in
+++ b/ovirt-hosted-engine-setup.spec.in
@@ -90,6 +90,8 @@
 %dir %{_sysconfdir}/ovirt-hosted-engine-setup.env.d
 %dir %{_sysconfdir}/ovirt-hosted-engine
 %dir %{_localstatedir}/log/ovirt-hosted-engine-setup
+%dir %{_localstatedir}/lib/ovirt-hosted-engine-setup
+%dir %{_localstatedir}/lib/ovirt-hosted-engine-setup/answers
 %{_sbindir}/hosted-engine
 %{_sbindir}/%{name}
 %{python_sitelib}/ovirt_hosted_engine_setup/
diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am
index ca4817d..b98bc1d 100644
--- a/src/bin/Makefile.am
+++ b/src/bin/Makefile.am
@@ -50,6 +50,7 @@
        $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-hosted-engine-setup.env.d
        $(MKDIR_P) $(DESTDIR)/$(sysconfdir)/ovirt-hosted-engine
        $(MKDIR_P) $(DESTDIR)/$(localstatedir)/log/ovirt-hosted-engine-setup
+       $(MKDIR_P) 
$(DESTDIR)/$(localstatedir)/lib/ovirt-hosted-engine-setup/answers
 
 install-exec-local: ovirt-hosted-engine-setup
        $(MKDIR_P) $(DESTDIR)/$(sbindir)
diff --git a/src/bin/ovirt-hosted-engine-setup 
b/src/bin/ovirt-hosted-engine-setup
index 7a0a1f0..8f98132 100755
--- a/src/bin/ovirt-hosted-engine-setup
+++ b/src/bin/ovirt-hosted-engine-setup
@@ -51,7 +51,7 @@
                        environment="${environment} 
APPEND:CORE/configFileAppend=str:${v}"
                ;;
                --generate-answer=*)
-                       environment="${environment} 
OVEHOSTED_CORE/answerFile=str:${v}"
+                       environment="${environment} 
OVEHOSTED_CORE/userAnswerFile=str:${v}"
                ;;
                --help)
                        usage
diff --git a/src/ovirt_hosted_engine_setup/constants.py 
b/src/ovirt_hosted_engine_setup/constants.py
index 5b28df7..5ddd7cf 100644
--- a/src/ovirt_hosted_engine_setup/constants.py
+++ b/src/ovirt_hosted_engine_setup/constants.py
@@ -147,6 +147,12 @@
         OVIRT_HOSTED_ENGINE,
         'answers.conf'
     )
+    OVIRT_HOSTED_ENGINE_ANSWERS_ARCHIVE_DIR = os.path.join(
+        config.LOCALSTATEDIR,
+        'lib',
+        OVIRT_HOSTED_ENGINE_SETUP,
+        'answers'
+    )
     HOSTED_ENGINE_IPTABLES_TEMPLATE = os.path.join(
         config.DATADIR,
         OVIRT_HOSTED_ENGINE_SETUP,
@@ -280,7 +286,8 @@
 @util.export
 @util.codegen
 class CoreEnv(object):
-    ANSWER_FILE = 'OVEHOSTED_CORE/answerFile'
+    USER_ANSWER_FILE = 'OVEHOSTED_CORE/userAnswerFile'
+    ETC_ANSWER_FILE = 'OVEHOSTED_CORE/etcAnswerFile'
     REQUIREMENTS_CHECK_ENABLED = 'OVEHOSTED_CORE/checkRequirements'
     ADDITIONAL_HOST_ENABLED = 'OVEHOSTED_CORE/additionalHostEnabled'
     IS_ADDITIONAL_HOST = 'OVEHOSTED_CORE/isAdditionalHost'
diff --git a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py 
b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
index 44e434d..185f626 100644
--- a/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
+++ b/src/plugins/ovirt-hosted-engine-setup/core/answerfile.py
@@ -22,11 +22,14 @@
 
 
 import gettext
+import os
+import datetime
 
 
 from otopi import util
 from otopi import common
 from otopi import plugin
+from otopi import constants as otopicons
 
 
 from ovirt_hosted_engine_setup import constants as ohostedcons
@@ -42,18 +45,13 @@
     def __init__(self, context):
         super(Plugin, self).__init__(context=context)
 
-    def _save_answers(self):
+    def _save_answers(self, name):
         self.logger.info(
             _("Generating answer file '{name}'").format(
-                name=self.environment[ohostedcons.CoreEnv.ANSWER_FILE],
+                name=name,
             )
         )
-        with open(
-            self.resolveFile(
-                self.environment[ohostedcons.CoreEnv.ANSWER_FILE]
-            ),
-            'w'
-        ) as f:
+        with open(self.resolveFile(name), 'w') as f:
             f.write('[environment:default]\n')
             for c in ohostedcons.__dict__['__hosted_attrs__']:
                 for k in c.__dict__.values():
@@ -76,34 +74,45 @@
     )
     def _init(self):
         self.environment.setdefault(
-            ohostedcons.CoreEnv.ANSWER_FILE,
+            ohostedcons.CoreEnv.ETC_ANSWER_FILE,
             ohostedcons.FileLocations.OVIRT_HOSTED_ENGINE_ANSWERS
         )
-
-    @plugin.event(
-        stage=plugin.Stages.STAGE_VALIDATION,
-        priority=plugin.Stages.PRIORITY_LAST,
-        condition=lambda self: self.environment[
-            ohostedcons.CoreEnv.ANSWER_FILE
-        ] is not None
-    )
-    def _save_answers_at_validation(self):
-        self._save_answers()
+        self.environment.setdefault(
+            ohostedcons.CoreEnv.USER_ANSWER_FILE,
+            None
+        )
+        self._answers = []
 
     @plugin.event(
         stage=plugin.Stages.STAGE_CLEANUP,
         priority=plugin.Stages.PRIORITY_LAST,
-        condition=lambda self: self.environment[
-            ohostedcons.CoreEnv.ANSWER_FILE
-        ] is not None
     )
     def _save_answers_at_cleanup(self):
-        self._save_answers()
-        self.logger.info(
-            _("Answer file '{name}' has been updated").format(
-                name=self.environment[ohostedcons.CoreEnv.ANSWER_FILE],
+        self._answers.extend(
+            (
+                os.path.join(
+                    (
+                        ohostedcons.FileLocations.
+                        OVIRT_HOSTED_ENGINE_ANSWERS_ARCHIVE_DIR
+                    ),
+                    'answers-%s.conf' % (
+                        datetime.datetime.now().strftime('%Y%m%d%H%M%S'),
+                    )
+                ),
+                self.environment[
+                    ohostedcons.CoreEnv.USER_ANSWER_FILE
+                ],
             )
         )
+        if not self.environment[otopicons.BaseEnv.ERROR]:
+            self._answers.append(
+                self.environment[
+                    ohostedcons.CoreEnv.ETC_ANSWER_FILE
+                ]
+            )
+        for name in self._answers:
+            if name:
+                self._save_answers(name)
 
 
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py 
b/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py
index 1500902..45a7494 100644
--- a/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py
+++ b/src/plugins/ovirt-hosted-engine-setup/core/remote_answerfile.py
@@ -139,7 +139,7 @@
                     os.close(fd)
                     sftp = paramiko.SFTPClient.from_transport(transport)
                     sftp.get(
-                        '/etc/ovirt-hosted-engine/answers.conf',
+                        ohostedcons.CoreEnv.ETC_ANSWER_FILE,
                         self._tmp_ans
                     )
                 finally:


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb28356a0ee38b325c53ec631b21b912e044d2a9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-hosted-engine-setup
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