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

Remove redundant boot partition mounts from `_get_grub2_cfg_location`

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu 2 дней назад
Родитель
Сommit
b90b471c1f

+ 0 - 2
coriolis/osmorphing/redhat.py

@@ -76,8 +76,6 @@ class BaseRedHatMorphingTools(base.BaseLinuxOSMorphingTools):
         refuses to overwrite the wrapper and requires output to
         /boot/grub2/grub.cfg. Prefer the BIOS path when it exists.
         """
-        self._exec_cmd_chroot("mount /boot || true")
-        self._exec_cmd_chroot("mount /boot/efi || true")
         uefi_cfg = os.path.join(self.UEFI_GRUB_LOCATION, "grub.cfg")
         bios_cfg = os.path.join(self.BIOS_GRUB_LOCATION, "grub.cfg")
         # Prefer /boot/grub2/grub.cfg - on RHEL 9.4+ UEFI, the EFI file is a

+ 0 - 2
coriolis/osmorphing/suse.py

@@ -82,8 +82,6 @@ class BaseSUSEMorphingTools(base.BaseLinuxOSMorphingTools):
         return "grub2-mkconfig -o %s" % location
 
     def _get_grub2_cfg_location(self):
-        self._exec_cmd_chroot("mount /boot || true")
-        self._exec_cmd_chroot("mount /boot/efi || true")
         uefi_cfg = os.path.join(self.UEFI_GRUB_LOCATION, "grub.cfg")
         bios_cfg = os.path.join(self.BIOS_GRUB_LOCATION, "grub.cfg")
         if self._test_path_chroot(uefi_cfg):

+ 3 - 21
coriolis/tests/osmorphing/test_redhat.py

@@ -68,44 +68,30 @@ class BaseRedHatMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
             'grub2-mkconfig -o %s' % mock_get_grub2_cfg_location.return_value
         )
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot,
-                                          mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot):
         mock_test_path_chroot.return_value = True
 
         result = self.morphing_tools._get_grub2_cfg_location()
 
         self.assertEqual(result, '/boot/grub2/grub.cfg')
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
         mock_test_path_chroot.assert_called_once_with(
             '/boot/grub2/grub.cfg')
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot,
-                                          mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot):
         mock_test_path_chroot.side_effect = [False, True]
 
         result = self.morphing_tools._get_grub2_cfg_location()
 
         self.assertEqual(result, '/boot/efi/EFI/redhat/grub.cfg')
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
         mock_test_path_chroot.assert_has_calls([
             mock.call('/boot/grub2/grub.cfg'),
             mock.call('/boot/efi/EFI/redhat/grub.cfg')
         ])
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_unknown(self, mock_test_path_chroot,
-                                             mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_unknown(self, mock_test_path_chroot):
         mock_test_path_chroot.return_value = False
 
         self.assertRaisesRegex(
@@ -114,10 +100,6 @@ class BaseRedHatMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
             self.morphing_tools._get_grub2_cfg_location
         )
 
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
         mock_test_path_chroot.assert_has_calls([
             mock.call('/boot/grub2/grub.cfg'),
             mock.call('/boot/efi/EFI/redhat/grub.cfg')

+ 4 - 24
coriolis/tests/osmorphing/test_suse.py

@@ -117,43 +117,27 @@ class BaseSUSEMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
             "grub2-mkconfig -o %s" % mock_get_grub2_cfg_location.return_value
         )
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot,
-                                          mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_uefi(self, mock_test_path_chroot):
         mock_test_path_chroot.return_value = True
 
         result = self.morphing_tools._get_grub2_cfg_location()
 
         self.assertEqual(result, '/boot/efi/EFI/suse/grub.cfg')
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
         mock_test_path_chroot.assert_called_once_with(
             '/boot/efi/EFI/suse/grub.cfg')
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot,
-                                          mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_bios(self, mock_test_path_chroot):
         mock_test_path_chroot.side_effect = [False, True]
 
         result = self.morphing_tools._get_grub2_cfg_location()
 
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
-        mock_test_path_chroot.assert_called_with(
-            '/boot/grub2/grub.cfg')
-
+        mock_test_path_chroot.assert_called_with('/boot/grub2/grub.cfg')
         self.assertEqual(result, '/boot/grub2/grub.cfg')
 
-    @mock.patch.object(base.BaseLinuxOSMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, '_test_path_chroot')
-    def test__get_grub2_cfg_location_not_found(self, mock_test_path_chroot,
-                                               mock_exec_cmd_chroot):
+    def test__get_grub2_cfg_location_not_found(self, mock_test_path_chroot):
         mock_test_path_chroot.return_value = False
 
         self.assertRaisesRegex(
@@ -161,10 +145,6 @@ class BaseSUSEMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
             "could not determine grub location. boot partition not mounted?",
             self.morphing_tools._get_grub2_cfg_location
         )
-        mock_exec_cmd_chroot.assert_has_calls([
-            mock.call("mount /boot || true"),
-            mock.call("mount /boot/efi || true")
-        ])
         mock_test_path_chroot.assert_has_calls([
             mock.call('/boot/efi/EFI/suse/grub.cfg'),
             mock.call('/boot/grub2/grub.cfg')