Browse Source

Merge "dracut-regenerate: catch failures and exit code"

tags/2.26.0
Zuul 1 month ago
parent
commit
8690579efc

+ 28
- 5
diskimage_builder/elements/dracut-regenerate/finalise.d/50-dracut-regenerate View File

@@ -14,22 +14,34 @@
14 14
 #    License for the specific language governing permissions and limitations
15 15
 #    under the License.
16 16
 
17
+import logging
17 18
 import os
18 19
 import re
19 20
 import subprocess
20 21
 import yaml
21 22
 
22 23
 
24
+logging.basicConfig(
25
+    level=logging.DEBUG if int(os.getenv('DIB_DEBUG_TRACE', 0)) > 0
26
+    else logging.INFO)
27
+
28
+
23 29
 def main():
30
+    logging.info("Starting dracut regeneration")
31
+    logging.debug("Debug logging enabled")
32
+
24 33
     dracut_env = os.getenv('DIB_DRACUT_ENABLED_MODULES')
25 34
     dracut_objects = yaml.safe_load(dracut_env)
26 35
 
36
+    logging.debug(dracut_objects)
37
+
27 38
     modules_to_boot = []
28 39
     for dracut_object in dracut_objects:
29 40
         # first, install dependent packages
30 41
         packages = dracut_object.get('packages', [])
31 42
         for package in packages:
32 43
             cmdline = ["install-packages", package]
44
+            logging.debug("Calling: %s" % cmdline)
33 45
             subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
34 46
             out = subp.communicate()[0]
35 47
             if subp.returncode:
@@ -43,9 +55,9 @@ def main():
43 55
     # regenerate dracut with the list of installed modules
44 56
     if len(modules_to_boot) > 0:
45 57
         cmdline = ["select-boot-kernel-initrd"]
58
+        logging.debug("Calling: %s" % cmdline)
46 59
         subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
47 60
         out, err = subp.communicate()
48
-
49 61
         if subp.returncode:
50 62
             e = subprocess.CalledProcessError(subp.returncode, cmdline)
51 63
             e.output = out
@@ -57,11 +69,22 @@ def main():
57 69
         ramdisk_path = "/boot/%s" % kernel_set[1].strip()
58 70
         modules_to_boot = ' ' .join(modules_to_boot)
59 71
 
60
-        subp = subprocess.Popen(['dracut', '--force', '--add', modules_to_boot,
61
-                                 '-f', ramdisk_path, kernel_version],
62
-                                stdout=subprocess.PIPE)
63
-        subp.wait()
72
+        cmdline = ['dracut', '--force', '--add', modules_to_boot,
73
+                   '-f', ramdisk_path, kernel_version]
74
+        logging.debug("Calling: %s" % cmdline)
75
+        subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
76
+        out, err = subp.communicate()
77
+        if subp.returncode:
78
+            e = subprocess.CalledProcessError(subp.returncode, cmdline)
79
+            e.output = out
80
+            raise e
81
+
82
+    logging.info("dracut regenerate done")
64 83
 
65 84
 
66 85
 if __name__ == '__main__':
67 86
     main()
87
+
88
+# Local Variables:
89
+# mode: python
90
+# End:

Loading…
Cancel
Save