[node-patches] Change in ovirt-node[master]: Bootloader: find grub configs on EFI

rbarry at redhat.com rbarry at redhat.com
Tue Feb 2 18:03:55 UTC 2016


Ryan Barry has uploaded a new change for review.

Change subject: Bootloader: find grub configs on EFI
......................................................................

Bootloader: find grub configs on EFI

Mount the EFI filesystem if it's EFI so we can look there.

Recurse through the boot config directory and intelligently pick
the config depending on whether it's grub2 or not.

Change-Id: Id837e7932c1c36f08c1dd9a9c28309f435630545
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1046887
Signed-off-by: Ryan Barry <rbarry at redhat.com>
---
M src/ovirt/node/utils/system.py
1 file changed, 22 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/01/53001/1

diff --git a/src/ovirt/node/utils/system.py b/src/ovirt/node/utils/system.py
index a064416..3a4e9eb 100755
--- a/src/ovirt/node/utils/system.py
+++ b/src/ovirt/node/utils/system.py
@@ -1105,26 +1105,31 @@
 
     @staticmethod
     def find_grub_cfg():
-        cfg_path = None
+        cfg = None
 
-        if os.path.ismount("/dev/.initramfs/live"):
-            if Bootloader.is_grub2():
-                cfg_path = "/dev/.initramfs/live/grub2/grub.cfg"
-            else:
-                cfg_path = "/dev/.initramfs/live/grub/grub.conf"
-        elif os.path.ismount("/run/initramfs/.live"):
-            cfg_path = "/liveos/grub/grub.conf"
-        elif Filesystem.by_label("Boot"):
-            cfg_path = "/boot/grub/grub.conf"
+        if Filesystem.by_label("Boot"):
+            cfg_path = "/boot/grub"
+        elif is_efi():
+            mount_efi(target="/liveos")
+            cfg_path = "/liveos/EFI"
+        elif os.path.ismount("/dev/.initramfs/live"):
+            cfg_path = "/dev/.initramfs/live"
+        elif os.path.ismount("/run/.initramfs/live"):
+            cfg_path = "/liveos"
 
-        else:
+        cfg_extension = ".cfg" if Bootloader.is_grub2() else ".conf"
+
+        for dirname, _, fileList in os.walk(cfg_path):
+            try:
+                candidate = [f for f in fileList if
+                             f.endswith(cfg_extension)].pop()
+                cfg = File("%s/%s" % (dirname, candidate))
+                LOGGER.debug("The path for grub is: %s" % cfg)
+            except IndexError:
+                LOGGER.debug("No grub config found in %s" % dirname)
+
+        if cfg is None:
             raise RuntimeError("Failed to find the path for grub.[cfg|conf]")
-
-        cfg = File(cfg_path)
-
-        if not cfg.exists():
-            raise RuntimeError("Grub config file does not exist: %s" %
-                               cfg.filename)
 
         return cfg
 


-- 
To view, visit https://gerrit.ovirt.org/53001
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Id837e7932c1c36f08c1dd9a9c28309f435630545
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: master
Gerrit-Owner: Ryan Barry <rbarry at redhat.com>



More information about the node-patches mailing list