Merge charm-sysconfig:bug/1923171 into charm-sysconfig:master

Proposed by Peter Sabaini
Status: Merged
Approved by: Drew Freiberger
Approved revision: 0695c4b340f03ec457590eb6478e2fbfb458c69a
Merged at revision: 505ab8823cb78953449391976a81fb6dc9abec3b
Proposed branch: charm-sysconfig:bug/1923171
Merge into: charm-sysconfig:master
Diff against target: 188 lines (+42/-34)
2 files modified
src/lib/lib_sysconfig.py (+21/-23)
src/tests/unit/test_lib.py (+21/-11)
Reviewer Review Type Date Requested Status
Drew Freiberger (community) Approve
🤖 prod-jenkaas-bootstack (community) continuous-integration Approve
Paul Goins Approve
Review via email: mp+400888@code.launchpad.net

Commit message

Fix missing linux-modules-extra

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Paul Goins (vultaire) wrote :

I'm +1 for this change, but note that CI is failing:

./lib/lib_sysconfig.py:360:5: C901 'SysConfigHelper.update_grub_file' is too complex (11)

If possible to fix things for CI, please do so.

review: Approve
Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Xav Paice (xavpaice) wrote :

CI test fail seems to be a genuine failure here, we'll need that fixed before merging.

Revision history for this message
Celia Wang (ziyiwang) wrote :

unittests passed on charmlab: https://pastebin.canonical.com/p/3DN7Bk8BqN/
func tests also passed: https://pastebin.canonical.com/p/726YpJBShc/

CI failed with unit tests:
tests/unit/test_lib.py::TestLib::test_update_grub_file FAILED [ 37%]
tests/unit/test_lib.py::TestLib::test_grub_legacy_reservation FAILED [ 40%]
tests/unit/test_lib.py::TestLib::test_legacy_grub_config_flags FAILED [ 42%]

Revision history for this message
Drew Freiberger (afreiberger) wrote (last edit ):

I also get successful unit testing on my Hirsuite laptop.

I think that with the unit tests, we need to mock the lib_sysconfig.host.is_container() with return_value = False to make this unit test pass.

It may be that the jenkins worker is triggering is_container() to be True, and we're just not mocking that during unit testing and have been lucky with running this on VMs and laptops.

Issue is not caused by this commit, but I'm going to add in the mock to see if it resolves this CI issue.

Revision history for this message
Drew Freiberger (afreiberger) wrote :

When testing this patch, I did set is_container = True and got the same failure as jenkins. setting to = False resolves. Let's pray for CI.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :

A CI job is currently in progress. A follow up comment will be added when it completes.

Revision history for this message
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote :
review: Approve (continuous-integration)
Revision history for this message
Drew Freiberger (afreiberger) wrote :

lgtm and passes CI now.

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 505ab8823cb78953449391976a81fb6dc9abec3b

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/lib/lib_sysconfig.py b/src/lib/lib_sysconfig.py
2index d2c4baa..be5de9d 100644
3--- a/src/lib/lib_sysconfig.py
4+++ b/src/lib/lib_sysconfig.py
5@@ -357,11 +357,7 @@ class SysConfigHelper:
6
7 return valid
8
9- def update_grub_file(self):
10- """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration.
11-
12- Will call update-grub if update-grub config is set to True.
13- """
14+ def _assemble_context(self):
15 context = {}
16
17 # The isolcpus boot option can be used to isolate one or more CPUs at
18@@ -372,14 +368,11 @@ class SysConfigHelper:
19
20 # This is to keep the old method of specifying the isolcpus
21 # by specifying the reservation and the cpu_range
22- if self.isolcpus:
23- context["isolcpus"] = self.isolcpus
24- if self.hugepages:
25- context["hugepages"] = self.hugepages
26- if self.hugepagesz:
27- context["hugepagesz"] = self.hugepagesz
28- if self.default_hugepagesz:
29- context["default_hugepagesz"] = self.default_hugepagesz
30+ for attr in ["isolcpus", "hugepages", "hugepagesz", "default_hugepagesz"]:
31+ val = getattr(self, attr, None)
32+ if val:
33+ context[attr] = val
34+
35 if self.raid_autodetection:
36 context["raid"] = self.raid_autodetection
37 if not self.enable_pti:
38@@ -401,6 +394,14 @@ class SysConfigHelper:
39 if self.kernel_version and not self._is_kernel_already_running():
40 context["grub_default"] = GRUB_DEFAULT.format(self.kernel_version)
41
42+ return context
43+
44+ def update_grub_file(self):
45+ """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration.
46+
47+ Will call update-grub if update-grub config is set to True.
48+ """
49+ context = self._assemble_context()
50 self._render_boot_resource(GRUB_CONF_TMPL, GRUB_CONF, context)
51 hookenv.log("grub configuration updated")
52 self._update_grub()
53@@ -441,18 +442,15 @@ class SysConfigHelper:
54
55 Will install kernel and matching modules-extra package
56 """
57- if not self.kernel_version or self._is_kernel_already_running():
58- hookenv.log("Kernel is already running the required version", hookenv.DEBUG)
59- return
60-
61 configured = self.kernel_version
62- pkgs = [
63- tmpl.format(configured)
64- for tmpl in ["linux-image-{}", "linux-modules-extra-{}"]
65- ]
66+ if not configured:
67+ return
68 apt_update()
69- apt_install(pkgs)
70- hookenv.log("installing: {}".format(pkgs))
71+ apt_install("linux-modules-extra-{}".format(configured))
72+ if self._is_kernel_already_running():
73+ hookenv.log("Kernel is already running the required version", hookenv.DEBUG)
74+ return
75+ apt_install("linux-image-{}".format(configured))
76 self.boot_resources.set_resource(KERNEL)
77
78 def update_cpufreq(self):
79diff --git a/src/tests/unit/test_lib.py b/src/tests/unit/test_lib.py
80index d23feb1..ad9a140 100644
81--- a/src/tests/unit/test_lib.py
82+++ b/src/tests/unit/test_lib.py
83@@ -190,15 +190,17 @@ class TestLib:
84 restart.assert_not_called()
85 check_call.assert_not_called()
86
87+ @mock.patch("lib_sysconfig.host.is_container")
88 @mock.patch("lib_sysconfig.subprocess.check_call")
89 @mock.patch("lib_sysconfig.hookenv.config")
90 @mock.patch("lib_sysconfig.hookenv.log")
91 @mock.patch("lib_sysconfig.render")
92- def test_update_grub_file(self, render, log, config, check_call):
93+ def test_update_grub_file(self, render, log, config, check_call, is_container):
94 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
95
96 Expect file is rendered with correct config and updated-grub is called.
97 """
98+ is_container.return_value = False
99 config.return_value = {
100 "reservation": "off",
101 "isolcpus": "0-10",
102@@ -240,15 +242,19 @@ class TestLib:
103 )
104 check_call.assert_called()
105
106+ @mock.patch("lib_sysconfig.host.is_container")
107 @mock.patch("lib_sysconfig.subprocess.check_call")
108 @mock.patch("lib_sysconfig.hookenv.config")
109 @mock.patch("lib_sysconfig.hookenv.log")
110 @mock.patch("lib_sysconfig.render")
111- def test_grub_legacy_reservation(self, render, log, config, check_call):
112+ def test_grub_legacy_reservation(
113+ self, render, log, config, check_call, is_container
114+ ):
115 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
116
117 Expect file is rendered with correct config and updated-grub is called.
118 """
119+ is_container.return_value = False
120 config.return_value = {
121 "reservation": "isolcpus",
122 "cpu-range": "0-10",
123@@ -290,15 +296,19 @@ class TestLib:
124 )
125 check_call.assert_called()
126
127+ @mock.patch("lib_sysconfig.host.is_container")
128 @mock.patch("lib_sysconfig.subprocess.check_call")
129 @mock.patch("lib_sysconfig.hookenv.config")
130 @mock.patch("lib_sysconfig.hookenv.log")
131 @mock.patch("lib_sysconfig.render")
132- def test_legacy_grub_config_flags(self, render, log, config, check_call):
133+ def test_legacy_grub_config_flags(
134+ self, render, log, config, check_call, is_container
135+ ):
136 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
137
138 Expect file is rendered with correct config and updated-grub is called.
139 """
140+ is_container.return_value = False
141 config.return_value = {
142 "reservation": "off",
143 "isolcpus": "",
144@@ -485,7 +495,7 @@ class TestLib:
145 ):
146 """Set config kernel=4.15.0-38-generic and running kernel is different.
147
148- Expect apt install is called.
149+ Expect apt install is called twice.
150 """
151 config.return_value = {"kernel-version": "4.15.0-38-generic"}
152
153@@ -493,12 +503,10 @@ class TestLib:
154 sysh = lib_sysconfig.SysConfigHelper()
155 sysh.install_configured_kernel()
156
157- apt_install.assert_called_with(
158- [
159- "linux-image-{}".format("4.15.0-38-generic"),
160- "linux-modules-extra-{}".format("4.15.0-38-generic"),
161- ]
162+ apt_install.assert_any_call(
163+ "linux-modules-extra-{}".format("4.15.0-38-generic")
164 )
165+ apt_install.assert_any_call("linux-image-{}".format("4.15.0-38-generic"))
166
167 @mock.patch("lib_sysconfig.apt_install")
168 @mock.patch("lib_sysconfig.apt_update")
169@@ -510,7 +518,7 @@ class TestLib:
170 ):
171 """Set config kernel=4.15.0-38-generic and running kernel is the same.
172
173- Expect apt install is not called.
174+ Expect apt install is called once for linux-modules-extra.
175 """
176 kernel_version = "4.15.0-38-generic"
177 config.return_value = {"kernel-version": kernel_version}
178@@ -519,7 +527,9 @@ class TestLib:
179 sysh = lib_sysconfig.SysConfigHelper()
180 sysh.install_configured_kernel()
181
182- apt_install.assert_not_called()
183+ apt_install.assert_called_with(
184+ "linux-modules-extra-{}".format("4.15.0-38-generic")
185+ )
186
187 @mock.patch("lib_sysconfig.apt_install")
188 @mock.patch("lib_sysconfig.apt_update")

Subscribers

No one subscribed via source and target branches