Parcourir la source

debian: install uefi fallback bootloader in "post_packages_install"

A previous commit added the helper but expected the providers to
call it.

There's no reason why we can't do it as part of "post_packages_install"
by default.
Lucian Petrut il y a 1 semaine
Parent
commit
081ada8302
2 fichiers modifiés avec 44 ajouts et 0 suppressions
  1. 4 0
      coriolis/osmorphing/debian.py
  2. 40 0
      coriolis/tests/osmorphing/test_debian.py

+ 4 - 0
coriolis/osmorphing/debian.py

@@ -8,6 +8,7 @@ import re
 from oslo_log import log as logging
 from oslo_log import log as logging
 import yaml
 import yaml
 
 
+from coriolis import constants
 from coriolis import exception
 from coriolis import exception
 from coriolis.osmorphing import base
 from coriolis.osmorphing import base
 from coriolis.osmorphing.osdetect import debian as debian_osdetect
 from coriolis.osmorphing.osdetect import debian as debian_osdetect
@@ -216,6 +217,9 @@ class BaseDebianMorphingTools(base.BaseLinuxOSMorphingTools):
     def post_packages_install(self, package_names):
     def post_packages_install(self, package_names):
         self._configure_cloud_init()
         self._configure_cloud_init()
         self._run_update_initramfs()
         self._run_update_initramfs()
+        if (self._osmorphing_parameters.get("firmware_type") ==
+                constants.FIRMWARE_TYPE_EFI):
+            self._install_uefi_fallback_bootloader()
         super(BaseDebianMorphingTools, self).post_packages_install(
         super(BaseDebianMorphingTools, self).post_packages_install(
             package_names)
             package_names)
 
 

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

@@ -2,12 +2,16 @@
 # All Rights Reserved.
 # All Rights Reserved.
 from unittest import mock
 from unittest import mock
 
 
+import ddt
+
+from coriolis import constants
 from coriolis import exception
 from coriolis import exception
 from coriolis.osmorphing import base
 from coriolis.osmorphing import base
 from coriolis.osmorphing import debian
 from coriolis.osmorphing import debian
 from coriolis.tests import test_base
 from coriolis.tests import test_base
 
 
 
 
+@ddt.ddt
 class BaseDebianMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
 class BaseDebianMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
     """Test suite for the BaseDebianMorphingTools class."""
     """Test suite for the BaseDebianMorphingTools class."""
 
 
@@ -286,20 +290,56 @@ class BaseDebianMorphingToolsTestCase(test_base.CoriolisBaseTestCase):
     @mock.patch.object(
     @mock.patch.object(
         debian.BaseDebianMorphingTools,
         debian.BaseDebianMorphingTools,
         '_run_update_initramfs')
         '_run_update_initramfs')
+    @mock.patch.object(
+        debian.BaseDebianMorphingTools,
+        '_install_uefi_fallback_bootloader')
     @mock.patch.object(debian.BaseDebianMorphingTools, '_configure_cloud_init')
     @mock.patch.object(debian.BaseDebianMorphingTools, '_configure_cloud_init')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, 'post_packages_install')
     @mock.patch.object(base.BaseLinuxOSMorphingTools, 'post_packages_install')
     def test_post_packages_install(
     def test_post_packages_install(
         self,
         self,
         mock_post_packages_install,
         mock_post_packages_install,
         mock__configure_cloud_init,
         mock__configure_cloud_init,
+        mock_install_uefi_fallback_bootloader,
+        mock_run_update_initramfs,
+
+    ):
+        self.morpher._osmorphing_parameters = {}
+        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)
+
+        # We haven't set the firmware type, this shouldn't run.
+        mock_install_uefi_fallback_bootloader.assert_not_called()
+
+    @mock.patch.object(
+        debian.BaseDebianMorphingTools,
+        '_run_update_initramfs')
+    @mock.patch.object(
+        debian.BaseDebianMorphingTools,
+        '_install_uefi_fallback_bootloader')
+    @mock.patch.object(debian.BaseDebianMorphingTools, '_configure_cloud_init')
+    @mock.patch.object(base.BaseLinuxOSMorphingTools, 'post_packages_install')
+    def test_post_packages_install_uefi(
+        self,
+        mock_post_packages_install,
+        mock__configure_cloud_init,
+        mock_install_uefi_fallback_bootloader,
         mock_run_update_initramfs,
         mock_run_update_initramfs,
+
     ):
     ):
+        self.morpher._osmorphing_parameters = {
+            "firmware_type": constants.FIRMWARE_TYPE_EFI,
+        }
         self.morpher.post_packages_install(self.package_names)
         self.morpher.post_packages_install(self.package_names)
 
 
         mock__configure_cloud_init.assert_called_once()
         mock__configure_cloud_init.assert_called_once()
         mock_run_update_initramfs.assert_called_once_with()
         mock_run_update_initramfs.assert_called_once_with()
         mock_post_packages_install.assert_called_once_with(self.package_names)
         mock_post_packages_install.assert_called_once_with(self.package_names)
 
 
+        mock_install_uefi_fallback_bootloader.assert_called_once_with()
+
     @mock.patch.object(debian.BaseDebianMorphingTools, '_exec_cmd_chroot')
     @mock.patch.object(debian.BaseDebianMorphingTools, '_exec_cmd_chroot')
     def test_install_packages(self, mock_exec_cmd_chroot):
     def test_install_packages(self, mock_exec_cmd_chroot):
         self.morpher.install_packages(self.package_names)
         self.morpher.install_packages(self.package_names)