Merge "dracut-regenerate: catch failures and exit code"
This commit is contained in:
commit
8690579efc
@ -14,22 +14,34 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import yaml
|
||||
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.DEBUG if int(os.getenv('DIB_DEBUG_TRACE', 0)) > 0
|
||||
else logging.INFO)
|
||||
|
||||
|
||||
def main():
|
||||
logging.info("Starting dracut regeneration")
|
||||
logging.debug("Debug logging enabled")
|
||||
|
||||
dracut_env = os.getenv('DIB_DRACUT_ENABLED_MODULES')
|
||||
dracut_objects = yaml.safe_load(dracut_env)
|
||||
|
||||
logging.debug(dracut_objects)
|
||||
|
||||
modules_to_boot = []
|
||||
for dracut_object in dracut_objects:
|
||||
# first, install dependent packages
|
||||
packages = dracut_object.get('packages', [])
|
||||
for package in packages:
|
||||
cmdline = ["install-packages", package]
|
||||
logging.debug("Calling: %s" % cmdline)
|
||||
subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
|
||||
out = subp.communicate()[0]
|
||||
if subp.returncode:
|
||||
@ -43,9 +55,9 @@ def main():
|
||||
# regenerate dracut with the list of installed modules
|
||||
if len(modules_to_boot) > 0:
|
||||
cmdline = ["select-boot-kernel-initrd"]
|
||||
logging.debug("Calling: %s" % cmdline)
|
||||
subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
|
||||
out, err = subp.communicate()
|
||||
|
||||
if subp.returncode:
|
||||
e = subprocess.CalledProcessError(subp.returncode, cmdline)
|
||||
e.output = out
|
||||
@ -57,11 +69,22 @@ def main():
|
||||
ramdisk_path = "/boot/%s" % kernel_set[1].strip()
|
||||
modules_to_boot = ' ' .join(modules_to_boot)
|
||||
|
||||
subp = subprocess.Popen(['dracut', '--force', '--add', modules_to_boot,
|
||||
'-f', ramdisk_path, kernel_version],
|
||||
stdout=subprocess.PIPE)
|
||||
subp.wait()
|
||||
cmdline = ['dracut', '--force', '--add', modules_to_boot,
|
||||
'-f', ramdisk_path, kernel_version]
|
||||
logging.debug("Calling: %s" % cmdline)
|
||||
subp = subprocess.Popen(cmdline, stdout=subprocess.PIPE)
|
||||
out, err = subp.communicate()
|
||||
if subp.returncode:
|
||||
e = subprocess.CalledProcessError(subp.returncode, cmdline)
|
||||
e.output = out
|
||||
raise e
|
||||
|
||||
logging.info("dracut regenerate done")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
# Local Variables:
|
||||
# mode: python
|
||||
# End:
|
||||
|
Loading…
Reference in New Issue
Block a user