Просмотр исходного кода

Move _run_update_initramfs to Debian tools

As per the PR feedback, we'll move "_run_update_initramfs" to
the Debian os-morphing tools and call it by default during
"post_packages_install".
Lucian Petrut 1 неделя назад
Родитель
Сommit
f292b73056

+ 20 - 0
coriolis/osmorphing/debian.py

@@ -162,6 +162,25 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
             cfg_name = "%s/coriolis_netplan.yaml" % self.netplan_base
             self._write_file_sudo(cfg_name, new_cfg)
 
+    def _run_update_initramfs(self):
+        # env LC_ALL=C suppresses Perl/shell locale warnings that would
+        # otherwise appear in stdout and get mixed into the version list.
+        # Using 'env' rather than a shell assignment prefix because
+        # _exec_cmd_chroot runs the command directly via chroot (no shell),
+        # so "LC_ALL=C cmd" would be treated as the binary name.
+        raw = self._exec_cmd_chroot("env LC_ALL=C linux-version list")
+
+        kernel_versions = [v for v in raw.splitlines() if v and v[0].isdigit()]
+        if not kernel_versions:
+            LOG.warning(
+                "No kernel versions found via 'linux-version list'; "
+                "skipping update-initramfs. Raw output was: %r",
+                raw,
+            )
+            return
+        for version in kernel_versions:
+            self._exec_cmd_chroot(f"update-initramfs -k {version} -u")
+
     def get_installed_packages(self):
         cmd = "dpkg-query -f '${binary:Package}\\n' -W"
         try:
@@ -196,6 +215,7 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
 
     def post_packages_install(self, package_names):
         self._configure_cloud_init()
+        self._run_update_initramfs()
         super(BaseDebianMorphingTools, self).post_packages_install(
             package_names)
 

+ 0 - 19
coriolis/osmorphing/ubuntu.py

@@ -122,22 +122,3 @@ class BaseUbuntuMorphingTools(debian.BaseDebianMorphingTools):
                 "Writing following configuration to '%s': %s" % (
                     config_path_chroot, config_data))
             self._write_file_sudo(config_path_chroot, yaml.dump(config_data))
-
-    def _run_update_initramfs(self):
-        # env LC_ALL=C suppresses Perl/shell locale warnings that would
-        # otherwise appear in stdout and get mixed into the version list.
-        # Using 'env' rather than a shell assignment prefix because
-        # _exec_cmd_chroot runs the command directly via chroot (no shell),
-        # so "LC_ALL=C cmd" would be treated as the binary name.
-        raw = self._exec_cmd_chroot("env LC_ALL=C linux-version list")
-
-        kernel_versions = [v for v in raw.splitlines() if v and v[0].isdigit()]
-        if not kernel_versions:
-            LOG.warning(
-                "No kernel versions found via 'linux-version list'; "
-                "skipping update-initramfs. Raw output was: %r",
-                raw,
-            )
-            return
-        for version in kernel_versions:
-            self._exec_cmd_chroot(f"update-initramfs -k {version} -u")

+ 40 - 2
coriolis/tests/osmorphing/test_debian.py

@@ -283,14 +283,21 @@ class BaseDebianMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
 
         mock_pre_packages_install.assert_called_once_with(self.package_names)
 
+    @mock.patch.object(
+        debian.BaseDebianMorphingTools,
+        '_run_update_initramfs')
     @mock.patch.object(debian.BaseDebianMorphingTools, '_configure_cloud_init')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, 'post_packages_install')
     def test_post_packages_install(
-            self, mock_post_packages_install, mock__configure_cloud_init):
-
+        self,
+        mock_post_packages_install,
+        mock__configure_cloud_init,
+        mock_run_update_initramfs,
+    ):
         self.morpher.post_packages_install(self.package_names)
 
         mock__configure_cloud_init.assert_called_once()
+        mock_run_update_initramfs.assert_called_once_with()
         mock_post_packages_install.assert_called_once_with(self.package_names)
 
     @mock.patch.object(debian.BaseDebianMorphingTools, '_exec_cmd_chroot')
@@ -457,3 +464,34 @@ deb http://archive.debian.org/debian wheezy-updates main non-free-firmware
         ])
         mock_test_path_chroot.assert_called_once_with(
             "/boot/efi/EFI/BOOT/BOOTX64.efi")
+
+    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
+    def test_update_initramfs(self, mock_exec_cmd_chroot):
+        mock_exec_cmd_chroot.side_effect = [
+            # 'linux-version list' output
+            "6.8.0-111-generic\n6.8.0-124-generic\n",
+            # 'update-initramfs' output
+            "",
+            "",
+        ]
+
+        self.morpher._run_update_initramfs()
+
+        mock_exec_cmd_chroot.assert_has_calls([
+            mock.call("env LC_ALL=C linux-version list"),
+            mock.call("update-initramfs -k 6.8.0-111-generic -u"),
+            mock.call("update-initramfs -k 6.8.0-124-generic -u"),
+        ])
+
+    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
+    def test_update_initramfs_no_kernels(self, mock_exec_cmd_chroot):
+        mock_exec_cmd_chroot.side_effect = [
+            # 'linux-version list' output
+            ""
+        ]
+
+        self.morpher._run_update_initramfs()
+
+        mock_exec_cmd_chroot.assert_has_calls([
+            mock.call("env LC_ALL=C linux-version list"),
+        ])

+ 0 - 31
coriolis/tests/osmorphing/test_ubuntu.py

@@ -170,34 +170,3 @@ class BaseUbuntuMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
                 self.os_root_dir, self.os_root_dir))
         mock_write_file_sudo.assert_called_once_with(
             'etc/netplan/file1.yaml', ubuntu.yaml.dump(config_data))
-
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
-    def test_update_initramfs(self, mock_exec_cmd_chroot):
-        mock_exec_cmd_chroot.side_effect = [
-            # 'linux-version list' output
-            "6.8.0-111-generic\n6.8.0-124-generic\n",
-            # 'update-initramfs' output
-            "",
-            "",
-        ]
-
-        self.morphing_tools._run_update_initramfs()
-
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("env LC_ALL=C linux-version list"),
-            mock.call("update-initramfs -k 6.8.0-111-generic -u"),
-            mock.call("update-initramfs -k 6.8.0-124-generic -u"),
-        ])
-
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
-    def test_update_initramfs_no_kernels(self, mock_exec_cmd_chroot):
-        mock_exec_cmd_chroot.side_effect = [
-            # 'linux-version list' output
-            ""
-        ]
-
-        self.morphing_tools._run_update_initramfs()
-
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("env LC_ALL=C linux-version list"),
-        ])