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
diff --git a/src/lib/lib_sysconfig.py b/src/lib/lib_sysconfig.py
index d2c4baa..be5de9d 100644
--- a/src/lib/lib_sysconfig.py
+++ b/src/lib/lib_sysconfig.py
@@ -357,11 +357,7 @@ class SysConfigHelper:
357357
358 return valid358 return valid
359359
360 def update_grub_file(self):360 def _assemble_context(self):
361 """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration.
362
363 Will call update-grub if update-grub config is set to True.
364 """
365 context = {}361 context = {}
366362
367 # The isolcpus boot option can be used to isolate one or more CPUs at363 # The isolcpus boot option can be used to isolate one or more CPUs at
@@ -372,14 +368,11 @@ class SysConfigHelper:
372368
373 # This is to keep the old method of specifying the isolcpus369 # This is to keep the old method of specifying the isolcpus
374 # by specifying the reservation and the cpu_range370 # by specifying the reservation and the cpu_range
375 if self.isolcpus:371 for attr in ["isolcpus", "hugepages", "hugepagesz", "default_hugepagesz"]:
376 context["isolcpus"] = self.isolcpus372 val = getattr(self, attr, None)
377 if self.hugepages:373 if val:
378 context["hugepages"] = self.hugepages374 context[attr] = val
379 if self.hugepagesz:375
380 context["hugepagesz"] = self.hugepagesz
381 if self.default_hugepagesz:
382 context["default_hugepagesz"] = self.default_hugepagesz
383 if self.raid_autodetection:376 if self.raid_autodetection:
384 context["raid"] = self.raid_autodetection377 context["raid"] = self.raid_autodetection
385 if not self.enable_pti:378 if not self.enable_pti:
@@ -401,6 +394,14 @@ class SysConfigHelper:
401 if self.kernel_version and not self._is_kernel_already_running():394 if self.kernel_version and not self._is_kernel_already_running():
402 context["grub_default"] = GRUB_DEFAULT.format(self.kernel_version)395 context["grub_default"] = GRUB_DEFAULT.format(self.kernel_version)
403396
397 return context
398
399 def update_grub_file(self):
400 """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration.
401
402 Will call update-grub if update-grub config is set to True.
403 """
404 context = self._assemble_context()
404 self._render_boot_resource(GRUB_CONF_TMPL, GRUB_CONF, context)405 self._render_boot_resource(GRUB_CONF_TMPL, GRUB_CONF, context)
405 hookenv.log("grub configuration updated")406 hookenv.log("grub configuration updated")
406 self._update_grub()407 self._update_grub()
@@ -441,18 +442,15 @@ class SysConfigHelper:
441442
442 Will install kernel and matching modules-extra package443 Will install kernel and matching modules-extra package
443 """444 """
444 if not self.kernel_version or self._is_kernel_already_running():
445 hookenv.log("Kernel is already running the required version", hookenv.DEBUG)
446 return
447
448 configured = self.kernel_version445 configured = self.kernel_version
449 pkgs = [446 if not configured:
450 tmpl.format(configured)447 return
451 for tmpl in ["linux-image-{}", "linux-modules-extra-{}"]
452 ]
453 apt_update()448 apt_update()
454 apt_install(pkgs)449 apt_install("linux-modules-extra-{}".format(configured))
455 hookenv.log("installing: {}".format(pkgs))450 if self._is_kernel_already_running():
451 hookenv.log("Kernel is already running the required version", hookenv.DEBUG)
452 return
453 apt_install("linux-image-{}".format(configured))
456 self.boot_resources.set_resource(KERNEL)454 self.boot_resources.set_resource(KERNEL)
457455
458 def update_cpufreq(self):456 def update_cpufreq(self):
diff --git a/src/tests/unit/test_lib.py b/src/tests/unit/test_lib.py
index d23feb1..ad9a140 100644
--- a/src/tests/unit/test_lib.py
+++ b/src/tests/unit/test_lib.py
@@ -190,15 +190,17 @@ class TestLib:
190 restart.assert_not_called()190 restart.assert_not_called()
191 check_call.assert_not_called()191 check_call.assert_not_called()
192192
193 @mock.patch("lib_sysconfig.host.is_container")
193 @mock.patch("lib_sysconfig.subprocess.check_call")194 @mock.patch("lib_sysconfig.subprocess.check_call")
194 @mock.patch("lib_sysconfig.hookenv.config")195 @mock.patch("lib_sysconfig.hookenv.config")
195 @mock.patch("lib_sysconfig.hookenv.log")196 @mock.patch("lib_sysconfig.hookenv.log")
196 @mock.patch("lib_sysconfig.render")197 @mock.patch("lib_sysconfig.render")
197 def test_update_grub_file(self, render, log, config, check_call):198 def test_update_grub_file(self, render, log, config, check_call, is_container):
198 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.199 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
199200
200 Expect file is rendered with correct config and updated-grub is called.201 Expect file is rendered with correct config and updated-grub is called.
201 """202 """
203 is_container.return_value = False
202 config.return_value = {204 config.return_value = {
203 "reservation": "off",205 "reservation": "off",
204 "isolcpus": "0-10",206 "isolcpus": "0-10",
@@ -240,15 +242,19 @@ class TestLib:
240 )242 )
241 check_call.assert_called()243 check_call.assert_called()
242244
245 @mock.patch("lib_sysconfig.host.is_container")
243 @mock.patch("lib_sysconfig.subprocess.check_call")246 @mock.patch("lib_sysconfig.subprocess.check_call")
244 @mock.patch("lib_sysconfig.hookenv.config")247 @mock.patch("lib_sysconfig.hookenv.config")
245 @mock.patch("lib_sysconfig.hookenv.log")248 @mock.patch("lib_sysconfig.hookenv.log")
246 @mock.patch("lib_sysconfig.render")249 @mock.patch("lib_sysconfig.render")
247 def test_grub_legacy_reservation(self, render, log, config, check_call):250 def test_grub_legacy_reservation(
251 self, render, log, config, check_call, is_container
252 ):
248 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.253 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
249254
250 Expect file is rendered with correct config and updated-grub is called.255 Expect file is rendered with correct config and updated-grub is called.
251 """256 """
257 is_container.return_value = False
252 config.return_value = {258 config.return_value = {
253 "reservation": "isolcpus",259 "reservation": "isolcpus",
254 "cpu-range": "0-10",260 "cpu-range": "0-10",
@@ -290,15 +296,19 @@ class TestLib:
290 )296 )
291 check_call.assert_called()297 check_call.assert_called()
292298
299 @mock.patch("lib_sysconfig.host.is_container")
293 @mock.patch("lib_sysconfig.subprocess.check_call")300 @mock.patch("lib_sysconfig.subprocess.check_call")
294 @mock.patch("lib_sysconfig.hookenv.config")301 @mock.patch("lib_sysconfig.hookenv.config")
295 @mock.patch("lib_sysconfig.hookenv.log")302 @mock.patch("lib_sysconfig.hookenv.log")
296 @mock.patch("lib_sysconfig.render")303 @mock.patch("lib_sysconfig.render")
297 def test_legacy_grub_config_flags(self, render, log, config, check_call):304 def test_legacy_grub_config_flags(
305 self, render, log, config, check_call, is_container
306 ):
298 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.307 """Update /etc/default/grub.d/90-sysconfig.cfg and update-grub true.
299308
300 Expect file is rendered with correct config and updated-grub is called.309 Expect file is rendered with correct config and updated-grub is called.
301 """310 """
311 is_container.return_value = False
302 config.return_value = {312 config.return_value = {
303 "reservation": "off",313 "reservation": "off",
304 "isolcpus": "",314 "isolcpus": "",
@@ -485,7 +495,7 @@ class TestLib:
485 ):495 ):
486 """Set config kernel=4.15.0-38-generic and running kernel is different.496 """Set config kernel=4.15.0-38-generic and running kernel is different.
487497
488 Expect apt install is called.498 Expect apt install is called twice.
489 """499 """
490 config.return_value = {"kernel-version": "4.15.0-38-generic"}500 config.return_value = {"kernel-version": "4.15.0-38-generic"}
491501
@@ -493,12 +503,10 @@ class TestLib:
493 sysh = lib_sysconfig.SysConfigHelper()503 sysh = lib_sysconfig.SysConfigHelper()
494 sysh.install_configured_kernel()504 sysh.install_configured_kernel()
495505
496 apt_install.assert_called_with(506 apt_install.assert_any_call(
497 [507 "linux-modules-extra-{}".format("4.15.0-38-generic")
498 "linux-image-{}".format("4.15.0-38-generic"),
499 "linux-modules-extra-{}".format("4.15.0-38-generic"),
500 ]
501 )508 )
509 apt_install.assert_any_call("linux-image-{}".format("4.15.0-38-generic"))
502510
503 @mock.patch("lib_sysconfig.apt_install")511 @mock.patch("lib_sysconfig.apt_install")
504 @mock.patch("lib_sysconfig.apt_update")512 @mock.patch("lib_sysconfig.apt_update")
@@ -510,7 +518,7 @@ class TestLib:
510 ):518 ):
511 """Set config kernel=4.15.0-38-generic and running kernel is the same.519 """Set config kernel=4.15.0-38-generic and running kernel is the same.
512520
513 Expect apt install is not called.521 Expect apt install is called once for linux-modules-extra.
514 """522 """
515 kernel_version = "4.15.0-38-generic"523 kernel_version = "4.15.0-38-generic"
516 config.return_value = {"kernel-version": kernel_version}524 config.return_value = {"kernel-version": kernel_version}
@@ -519,7 +527,9 @@ class TestLib:
519 sysh = lib_sysconfig.SysConfigHelper()527 sysh = lib_sysconfig.SysConfigHelper()
520 sysh.install_configured_kernel()528 sysh.install_configured_kernel()
521529
522 apt_install.assert_not_called()530 apt_install.assert_called_with(
531 "linux-modules-extra-{}".format("4.15.0-38-generic")
532 )
523533
524 @mock.patch("lib_sysconfig.apt_install")534 @mock.patch("lib_sysconfig.apt_install")
525 @mock.patch("lib_sysconfig.apt_update")535 @mock.patch("lib_sysconfig.apt_update")

Subscribers

No one subscribed via source and target branches