Merge ~ogayot/curtin:fix-curthooks-no-kernel into curtin:master

Proposed by Olivier Gayot
Status: Merged
Approved by: Olivier Gayot
Approved revision: 93d47e95859fc92d5108913fc15b98a0ad56234e
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~ogayot/curtin:fix-curthooks-no-kernel
Merge into: curtin:master
Diff against target: 43 lines (+16/-6)
2 files modified
curtin/commands/curthooks.py (+7/-6)
tests/unittests/test_curthooks.py (+9/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Dan Bungert Approve
Review via email: mp+446197@code.launchpad.net

Commit message

curthooks: fix exception when passing 'kernel: null'

When we don't want curthooks to install a kernel, we can pass:

  kernel: null

However, currently, it makes the code raise an exception because we run
.get() on the kernel object even if it is None.

 config.merge_config(mapping, kernel_cfg.get('mapping', {}))
 AttributeError: 'NoneType' object has no attribute 'get'
 'NoneType' object has no attribute 'get'

Fixed by returning gracefully without installing any kernel upon
encountering this configuration.

LP: #2026225

Signed-off-by: Olivier Gayot <email address hidden>

Description of the change

When we specify 'kernel: null' in the curthooks configuration, curtin raises an exception:

builtin_curthooks
     install_kernel(cfg, target)
   File "/snap/ubuntu-desktop-installer/x1/lib/python3.10/site-packages/curtin/commands/curthooks.py", line 375, in install_kernel
     config.merge_config(mapping, kernel_cfg.get('mapping', {}))
 AttributeError: 'NoneType' object has no attribute 'get'
 'NoneType' object has no attribute 'get'
 curtin: Installation failed with exception: Unexpected error while running command.

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Dan Bungert (dbungert) wrote :

Please mention the LP in the commit message then LGTM. Thanks!

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
index c52d5ab..b0844d5 100644
--- a/curtin/commands/curthooks.py
+++ b/curtin/commands/curthooks.py
@@ -365,12 +365,13 @@ def install_kernel(cfg, target):
365 kernel_cfg = cfg.get('kernel', {'package': None,365 kernel_cfg = cfg.get('kernel', {'package': None,
366 'fallback-package': "linux-generic",366 'fallback-package': "linux-generic",
367 'mapping': {}})367 'mapping': {}})
368 if kernel_cfg is not None:368
369 kernel_package = kernel_cfg.get('package')369 if kernel_cfg is None:
370 kernel_fallback = kernel_cfg.get('fallback-package')370 LOG.debug("Not installing any kernel since kernel: null was specified")
371 else:371 return
372 kernel_package = None372
373 kernel_fallback = None373 kernel_package = kernel_cfg.get('package')
374 kernel_fallback = kernel_cfg.get('fallback-package')
374375
375 mapping = copy.deepcopy(KERNEL_MAPPING)376 mapping = copy.deepcopy(KERNEL_MAPPING)
376 config.merge_config(mapping, kernel_cfg.get('mapping', {}))377 config.merge_config(mapping, kernel_cfg.get('mapping', {}))
diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
index d6b5445..a67bc81 100644
--- a/tests/unittests/test_curthooks.py
+++ b/tests/unittests/test_curthooks.py
@@ -94,6 +94,15 @@ class TestCurthooksInstallKernel(CiTestCase):
94 self.mock_instpkg.assert_called_with(94 self.mock_instpkg.assert_called_with(
95 [kernel_package], target=self.target, env=env)95 [kernel_package], target=self.target, env=env)
9696
97 def test__installs_kernel_null(self):
98 kernel_cfg = {'kernel': None}
99 self.mock_get_flash_kernel_pkgs.return_value = None
100
101 with patch.dict(os.environ, clear=True):
102 curthooks.install_kernel(kernel_cfg, self.target)
103
104 self.mock_instpkg.assert_not_called()
105
97106
98class TestEnableDisableUpdateInitramfs(CiTestCase):107class TestEnableDisableUpdateInitramfs(CiTestCase):
99108

Subscribers

People subscribed via source and target branches