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
1diff --git a/curtin/commands/curthooks.py b/curtin/commands/curthooks.py
2index c52d5ab..b0844d5 100644
3--- a/curtin/commands/curthooks.py
4+++ b/curtin/commands/curthooks.py
5@@ -365,12 +365,13 @@ def install_kernel(cfg, target):
6 kernel_cfg = cfg.get('kernel', {'package': None,
7 'fallback-package': "linux-generic",
8 'mapping': {}})
9- if kernel_cfg is not None:
10- kernel_package = kernel_cfg.get('package')
11- kernel_fallback = kernel_cfg.get('fallback-package')
12- else:
13- kernel_package = None
14- kernel_fallback = None
15+
16+ if kernel_cfg is None:
17+ LOG.debug("Not installing any kernel since kernel: null was specified")
18+ return
19+
20+ kernel_package = kernel_cfg.get('package')
21+ kernel_fallback = kernel_cfg.get('fallback-package')
22
23 mapping = copy.deepcopy(KERNEL_MAPPING)
24 config.merge_config(mapping, kernel_cfg.get('mapping', {}))
25diff --git a/tests/unittests/test_curthooks.py b/tests/unittests/test_curthooks.py
26index d6b5445..a67bc81 100644
27--- a/tests/unittests/test_curthooks.py
28+++ b/tests/unittests/test_curthooks.py
29@@ -94,6 +94,15 @@ class TestCurthooksInstallKernel(CiTestCase):
30 self.mock_instpkg.assert_called_with(
31 [kernel_package], target=self.target, env=env)
32
33+ def test__installs_kernel_null(self):
34+ kernel_cfg = {'kernel': None}
35+ self.mock_get_flash_kernel_pkgs.return_value = None
36+
37+ with patch.dict(os.environ, clear=True):
38+ curthooks.install_kernel(kernel_cfg, self.target)
39+
40+ self.mock_instpkg.assert_not_called()
41+
42
43 class TestEnableDisableUpdateInitramfs(CiTestCase):
44

Subscribers

People subscribed via source and target branches