Quellcode durchsuchen

Merge pull request #34 from aznashwan/mkinitrd

Improve OSMount and OSMorphing processes.
Nashwan Azhari vor 7 Jahren
Ursprung
Commit
0833f9c406

+ 1 - 1
coriolis/osmorphing/base.py

@@ -189,7 +189,7 @@ class BaseLinuxOSMorphingTools(BaseOSMorphingTools):
     def _replace_fstab_entries_device_prefix(
             self, current_prefix="/dev/sd", new_prefix="/dev/sd"):
         fstab_chroot_path = "etc/fstab"
-        fstab_contents = self._read_file(fstab_chroot_path)
+        fstab_contents = self._read_file(fstab_chroot_path).decode()
         LOG.debug("Contents of /%s: %s", fstab_chroot_path, fstab_contents)
         fstab_contents_lines = fstab_contents.split('\n')
 

+ 13 - 1
coriolis/osmorphing/osmount/base.py

@@ -304,12 +304,14 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
                     utils.check_fs(self._ssh, fs_type, dev_path)
                 dev_paths_to_mount.append(dev_path)
 
+        os_boot_device = None
         os_root_device = None
         os_root_dir = None
         for dev_path in dev_paths_to_mount:
             tmp_dir = self._exec_cmd('mktemp -d').decode().split('\n')[0]
             self._exec_cmd('sudo mount %s %s' % (dev_path, tmp_dir))
             dirs = self._exec_cmd('ls %s' % tmp_dir).decode().split('\n')
+            LOG.debug("Contents of device %s:\n%s", dev_path, dirs)
 
             # TODO(alexpilotti): better ways to check for a linux root?
             if (not os_root_dir and 'etc' in dirs and 'bin' in dirs and
@@ -317,13 +319,23 @@ class BaseLinuxOSMountTools(BaseSSHOSMountTools):
                 os_root_dir = tmp_dir
                 os_root_device = dev_path
                 LOG.info("OS root device: %s", dev_path)
-                break
+                continue
+            elif (not os_boot_device and ('grub' in dirs or 'grub2' in dirs)):
+                os_boot_device = dev_path
+                LOG.info("OS boot device: %s", dev_path)
+                self._exec_cmd('sudo umount %s' % tmp_dir)
             else:
                 self._exec_cmd('sudo umount %s' % tmp_dir)
 
         if not os_root_dir:
             raise exception.OperatingSystemNotFound("root partition not found")
 
+        if os_boot_device:
+            LOG.debug("Mounting boot device '%s'", os_boot_device)
+            self._exec_cmd(
+                'sudo mount %s "%s/boot"' % (
+                    os_boot_device, os_root_dir))
+
         self._check_mount_fstab_partitions(os_root_dir)
 
         for dir in set(dirs).intersection(['proc', 'sys', 'dev', 'run']):

+ 23 - 0
coriolis/osmorphing/suse.py

@@ -53,6 +53,29 @@ class BaseSUSEMorphingTools(base.BaseLinuxOSMorphingTools):
                     "dracut -f /boot/initrd-%(version)s %(version)s" %
                     {"version": kernel_version})
 
+    def _run_mkinitrd(self):
+        self._event_manager.progress_update("Rebuilding initrds")
+        try:
+            # NOTE: on SLES<12, the `mkinitrd` executable
+            # must be run with no arguments:
+            self._exec_cmd_chroot("mkinitrd")
+            self._event_manager.progress_update(
+                "Successfully rebuilt initrds")
+        except Exception:
+            # NOTE: old version of `mkinitrd` can error out due to
+            # incompatibilities with sysfs/procfs:
+            self._event_manager.progress_update(
+                "Error occurred while rebuilding initrds, skipping")
+            LOG.warn(
+                "Exception occured while rebuilding SLES initrds:\n%s" % (
+                    utils.get_exception_details()))
+
+    def _rebuild_initrds(self):
+        if float(self._version_id) < 12:
+            self._run_mkinitrd()
+        else:
+            self._run_dracut()
+
     def _has_systemd(self):
         try:
             self._exec_cmd_chroot("rpm -q systemd")

+ 3 - 1
coriolis/secrets.py

@@ -6,9 +6,11 @@ import json
 from barbicanclient import client as barbican_client
 
 from coriolis import keystone
+from coriolis import utils
 
 
 def get_secret(ctxt, secret_ref):
     session = keystone.create_keystone_session(ctxt)
     barbican = barbican_client.Client(session=session)
-    return json.loads(barbican.secrets.get(secret_ref).payload)
+    sec = utils.retry_on_error()(barbican.secrets.get)(secret_ref)
+    return json.loads(sec.payload)