Blame SOURCES/tui_fetch_and_process_1240625.patch

fd2bce
From c899ac40c5793dc76e5c726d610ee17f9bc71d43 Mon Sep 17 00:00:00 2001
fd2bce
From: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
Date: Tue, 7 Jul 2015 15:15:33 +0200
fd2bce
Subject: [PATCH 1/7] Fetch and process the content even if GUI doesn't take
fd2bce
 care of it (#1240625)
fd2bce
fd2bce
We cannot rely on the GUI code fetching and loading the content because in text
fd2bce
kickstart installations it never gets a chance to do so.
fd2bce
fd2bce
Signed-off-by: Vratislav Podzimek <vpodzime@redhat.com>
fd2bce
---
fd2bce
 org_fedora_oscap/ks/oscap.py | 35 ++++++++++++++++++++++++++++++++++-
fd2bce
 1 file changed, 34 insertions(+), 1 deletion(-)
fd2bce
fd2bce
diff --git a/org_fedora_oscap/ks/oscap.py b/org_fedora_oscap/ks/oscap.py
fd2bce
index 475aa2c..fd57b14 100644
fd2bce
--- a/org_fedora_oscap/ks/oscap.py
fd2bce
+++ b/org_fedora_oscap/ks/oscap.py
fd2bce
@@ -22,15 +22,19 @@
fd2bce
 
fd2bce
 import shutil
fd2bce
 import re
fd2bce
+import os
fd2bce
 
fd2bce
 from pyanaconda.addons import AddonData
fd2bce
 from pyanaconda.iutil import getSysroot
fd2bce
 from pyanaconda import iutil
fd2bce
 from pykickstart.errors import KickstartParseError, KickstartValueError
fd2bce
-from org_fedora_oscap import utils, common, rule_handling
fd2bce
+from org_fedora_oscap import utils, common, rule_handling, data_fetch
fd2bce
 from org_fedora_oscap.common import SUPPORTED_ARCHIVES
fd2bce
 from org_fedora_oscap.content_handling import ContentCheckError
fd2bce
 
fd2bce
+import logging
fd2bce
+log = logging.getLogger("anaconda")
fd2bce
+
fd2bce
 # export OSCAPdata class to prevent Anaconda's collect method from taking
fd2bce
 # AddonData class instead of the OSCAPdata class
fd2bce
 # @see: pyanaconda.kickstart.AnacondaKSHandler.__init__
fd2bce
@@ -356,6 +360,27 @@ class OSCAPdata(AddonData):
fd2bce
         return utils.join_paths(common.TARGET_CONTENT_DIR,
fd2bce
                                 self.tailoring_path)
fd2bce
 
fd2bce
+    def _fetch_content_and_initialize(self):
fd2bce
+        """Fetch content and initialize from it"""
fd2bce
+
fd2bce
+        data_fetch.fetch_data(self.content_url, self.raw_preinst_content_path, self.certificates)
fd2bce
+        # RPM is an archive at this phase
fd2bce
+        if self.content_type in ("archive", "rpm"):
fd2bce
+            # extract the content
fd2bce
+            common.extract_data(self.raw_preinst_content_path,
fd2bce
+                                common.INSTALLATION_CONTENT_DIR,
fd2bce
+                                [self.xccdf_path])
fd2bce
+
fd2bce
+        rules = common.get_fix_rules_pre(self.profile_id,
fd2bce
+                                         self.preinst_content_path,
fd2bce
+                                         self.datastream_id, self.xccdf_id,
fd2bce
+                                         self.preinst_tailoring_path)
fd2bce
+
fd2bce
+        # parse and store rules with a clean RuleData instance
fd2bce
+        self.rule_data = rule_handling.RuleData()
fd2bce
+        for rule in rules.splitlines():
fd2bce
+            self.rule_data.new_rule(rule)
fd2bce
+
fd2bce
     def setup(self, storage, ksdata, instclass):
fd2bce
         """
fd2bce
         The setup method that should make changes to the runtime environment
fd2bce
@@ -377,6 +402,14 @@ class OSCAPdata(AddonData):
fd2bce
             # selected
fd2bce
             return
fd2bce
 
fd2bce
+        if not os.path.exists(self.raw_preinst_content_path):
fd2bce
+            # content not available/fetched yet
fd2bce
+            try:
fd2bce
+                self._fetch_content_and_initialize()
fd2bce
+            except common.OSCAPaddonError:
fd2bce
+                log.error("Failed to fetch and initialize SCAP content!")
fd2bce
+                return
fd2bce
+
fd2bce
         # check fingerprint if given
fd2bce
         if self.fingerprint:
fd2bce
             hash_obj = utils.get_hashing_algorithm(self.fingerprint)
fd2bce
-- 
fd2bce
2.4.3
fd2bce