[node-patches] Change in ovirt-node[ovirt-3.6]: install.py: Handle multiple kernels for rebuild initramfs

dougsland at redhat.com dougsland at redhat.com
Mon Jun 6 19:43:28 UTC 2016


Douglas Schilling Landgraf has uploaded a new change for review.

Change subject: install.py: Handle multiple kernels for rebuild initramfs
......................................................................

install.py: Handle multiple kernels for rebuild initramfs

Currently, if users try to add external kernel modules
using edit-node it will fail as the install.py cannot
handle such situation as it only expect one kernel in the image.

To avoid such issue, this patch adds a logic for such scenario
and detects the higher kernel version available.

Change-Id: I7787a9e3e6bc0b6c5ca7a257f8668a599357cd79
Bug-Url: https://bugzilla.redhat.com/show_bug.cgi?id=1330632
Signed-off-by: Douglas Schilling Landgraf <dougsland at redhat.com>
(cherry picked from commit 63caa7e3463654b63eda6302276fff3c459d9bde)
---
M src/ovirtnode/install.py
1 file changed, 40 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-node refs/changes/11/58711/1

diff --git a/src/ovirtnode/install.py b/src/ovirtnode/install.py
index f92912b..1612173 100755
--- a/src/ovirtnode/install.py
+++ b/src/ovirtnode/install.py
@@ -30,7 +30,10 @@
 import logging
 import tempfile
 OVIRT_VARS = _functions.parse_defaults()
+
+from itertools import combinations
 from ovirtnode.storage import Storage
+from rpmUtils.miscutils import compareVerOnly
 
 logger = logging.getLogger(__name__)
 
@@ -57,6 +60,38 @@
                 return "EFI/redhat"
         else:
             return "EFI/redhat"
+
+    def check_higher_kernel(self, path=None):
+        """
+        Check through kernel modules dir, the higher version
+        available
+
+        path -- The path to kernel modules dir
+        """
+        higher_kernel = None
+
+        if path is None:
+            modules_dir = "/lib/modules"
+        else:
+            modules_dir = "{0}/lib/modules".format(path)
+
+        modules_dir = os.listdir(modules_dir)
+        for km1, km2 in combinations(modules_dir, 2):
+            ret = compareVerOnly(km1, km2)
+
+            # Extra validation via rpmUtils.miscutils to
+            # check if new value in km1 or in km2 is higher than
+            # the current hold in higher_kernel
+            if ret == 1:
+                if higher_kernel is None or \
+                        compareVerOnly(km1, higher_kernel) == 1:
+                    higher_kernel = km1
+            elif ret == -1:
+                if higher_kernel is None or \
+                        compareVerOnly(km2, higher_kernel) == 1:
+                    higher_kernel = km2
+
+        return higher_kernel
 
     def kernel_image_copy(self):
         if (not _functions.system("cp -p %s/vmlinuz0 %s" % \
@@ -747,8 +782,11 @@
 
             if len(upd_kver.splitlines()) != 1:
                 # It would be very unusual to see more than one kver directory
-                # in /lib/modules, because our images just contain one kernel
-                raise RuntimeError("Found more than one kernel version")
+                # in /lib/modules but might happen when using edit-node.
+                # Check via check_higher_kernel() the higher version available
+                upd_kver = self.check_higher_kernel(updfs)
+                if upd_kver is None:
+                    raise RuntimeError("Unable to find the kernel version")
 
             # Update initramfs to pickup multipath wwids
             # Let /boot point to the filesystem on the update candidate partition


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7787a9e3e6bc0b6c5ca7a257f8668a599357cd79
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-node
Gerrit-Branch: ovirt-3.6
Gerrit-Owner: Douglas Schilling Landgraf <dougsland at redhat.com>



More information about the node-patches mailing list