Merge charm-sysconfig:bug/1923171 into charm-sysconfig:master
- Git
- lp:charm-sysconfig
- bug/1923171
- Merge into master
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) |
||||
Related bugs: |
|
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
Description of the change
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
A CI job is currently in progress. A follow up comment will be added when it completes.
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:a7fe8945f54
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Paul Goins (vultaire) wrote : | # |
I'm +1 for this change, but note that CI is failing:
./lib/lib_
If possible to fix things for CI, please do so.
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
A CI job is currently in progress. A follow up comment will be added when it completes.
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
FAILED: Continuous integration, rev:5e66cf6e2e7
https:/
Executed test runs:
FAILURE: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Xav Paice (xavpaice) wrote : | # |
CI test fail seems to be a genuine failure here, we'll need that fixed before merging.
Celia Wang (ziyiwang) wrote : | # |
unittests passed on charmlab: https:/
func tests also passed: https:/
CI failed with unit tests:
tests/unit/
tests/unit/
tests/unit/
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.
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.
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.
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
A CI job is currently in progress. A follow up comment will be added when it completes.
🤖 prod-jenkaas-bootstack (prod-jenkaas-bootstack) wrote : | # |
PASSED: Continuous integration, rev:0695c4b340f
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Drew Freiberger (afreiberger) wrote : | # |
lgtm and passes CI now.
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote : | # |
Change successfully merged at revision 505ab8823cb7895
Preview Diff
1 | diff --git a/src/lib/lib_sysconfig.py b/src/lib/lib_sysconfig.py | |||
2 | index 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 | 357 | 357 | ||
7 | 358 | return valid | 358 | return valid |
8 | 359 | 359 | ||
14 | 360 | def update_grub_file(self): | 360 | def _assemble_context(self): |
10 | 361 | """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration. | ||
11 | 362 | |||
12 | 363 | Will call update-grub if update-grub config is set to True. | ||
13 | 364 | """ | ||
15 | 365 | context = {} | 361 | context = {} |
16 | 366 | 362 | ||
17 | 367 | # The isolcpus boot option can be used to isolate one or more CPUs at | 363 | # The isolcpus boot option can be used to isolate one or more CPUs at |
18 | @@ -372,14 +368,11 @@ class SysConfigHelper: | |||
19 | 372 | 368 | ||
20 | 373 | # This is to keep the old method of specifying the isolcpus | 369 | # This is to keep the old method of specifying the isolcpus |
21 | 374 | # by specifying the reservation and the cpu_range | 370 | # by specifying the reservation and the cpu_range |
30 | 375 | if self.isolcpus: | 371 | for attr in ["isolcpus", "hugepages", "hugepagesz", "default_hugepagesz"]: |
31 | 376 | context["isolcpus"] = self.isolcpus | 372 | val = getattr(self, attr, None) |
32 | 377 | if self.hugepages: | 373 | if val: |
33 | 378 | context["hugepages"] = self.hugepages | 374 | context[attr] = val |
34 | 379 | if self.hugepagesz: | 375 | |
27 | 380 | context["hugepagesz"] = self.hugepagesz | ||
28 | 381 | if self.default_hugepagesz: | ||
29 | 382 | context["default_hugepagesz"] = self.default_hugepagesz | ||
35 | 383 | if self.raid_autodetection: | 376 | if self.raid_autodetection: |
36 | 384 | context["raid"] = self.raid_autodetection | 377 | context["raid"] = self.raid_autodetection |
37 | 385 | if not self.enable_pti: | 378 | if not self.enable_pti: |
38 | @@ -401,6 +394,14 @@ class SysConfigHelper: | |||
39 | 401 | if self.kernel_version and not self._is_kernel_already_running(): | 394 | if self.kernel_version and not self._is_kernel_already_running(): |
40 | 402 | context["grub_default"] = GRUB_DEFAULT.format(self.kernel_version) | 395 | context["grub_default"] = GRUB_DEFAULT.format(self.kernel_version) |
41 | 403 | 396 | ||
42 | 397 | return context | ||
43 | 398 | |||
44 | 399 | def update_grub_file(self): | ||
45 | 400 | """Update /etc/default/grub.d/90-sysconfig.cfg according to charm configuration. | ||
46 | 401 | |||
47 | 402 | Will call update-grub if update-grub config is set to True. | ||
48 | 403 | """ | ||
49 | 404 | context = self._assemble_context() | ||
50 | 404 | self._render_boot_resource(GRUB_CONF_TMPL, GRUB_CONF, context) | 405 | self._render_boot_resource(GRUB_CONF_TMPL, GRUB_CONF, context) |
51 | 405 | hookenv.log("grub configuration updated") | 406 | hookenv.log("grub configuration updated") |
52 | 406 | self._update_grub() | 407 | self._update_grub() |
53 | @@ -441,18 +442,15 @@ class SysConfigHelper: | |||
54 | 441 | 442 | ||
55 | 442 | Will install kernel and matching modules-extra package | 443 | Will install kernel and matching modules-extra package |
56 | 443 | """ | 444 | """ |
57 | 444 | if not self.kernel_version or self._is_kernel_already_running(): | ||
58 | 445 | hookenv.log("Kernel is already running the required version", hookenv.DEBUG) | ||
59 | 446 | return | ||
60 | 447 | |||
61 | 448 | configured = self.kernel_version | 445 | configured = self.kernel_version |
66 | 449 | pkgs = [ | 446 | if not configured: |
67 | 450 | tmpl.format(configured) | 447 | return |
64 | 451 | for tmpl in ["linux-image-{}", "linux-modules-extra-{}"] | ||
65 | 452 | ] | ||
68 | 453 | apt_update() | 448 | apt_update() |
71 | 454 | apt_install(pkgs) | 449 | apt_install("linux-modules-extra-{}".format(configured)) |
72 | 455 | hookenv.log("installing: {}".format(pkgs)) | 450 | if self._is_kernel_already_running(): |
73 | 451 | hookenv.log("Kernel is already running the required version", hookenv.DEBUG) | ||
74 | 452 | return | ||
75 | 453 | apt_install("linux-image-{}".format(configured)) | ||
76 | 456 | self.boot_resources.set_resource(KERNEL) | 454 | self.boot_resources.set_resource(KERNEL) |
77 | 457 | 455 | ||
78 | 458 | def update_cpufreq(self): | 456 | def update_cpufreq(self): |
79 | diff --git a/src/tests/unit/test_lib.py b/src/tests/unit/test_lib.py | |||
80 | index 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 | 190 | restart.assert_not_called() | 190 | restart.assert_not_called() |
85 | 191 | check_call.assert_not_called() | 191 | check_call.assert_not_called() |
86 | 192 | 192 | ||
87 | 193 | @mock.patch("lib_sysconfig.host.is_container") | ||
88 | 193 | @mock.patch("lib_sysconfig.subprocess.check_call") | 194 | @mock.patch("lib_sysconfig.subprocess.check_call") |
89 | 194 | @mock.patch("lib_sysconfig.hookenv.config") | 195 | @mock.patch("lib_sysconfig.hookenv.config") |
90 | 195 | @mock.patch("lib_sysconfig.hookenv.log") | 196 | @mock.patch("lib_sysconfig.hookenv.log") |
91 | 196 | @mock.patch("lib_sysconfig.render") | 197 | @mock.patch("lib_sysconfig.render") |
93 | 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): |
94 | 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. |
95 | 199 | 200 | ||
96 | 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. |
97 | 201 | """ | 202 | """ |
98 | 203 | is_container.return_value = False | ||
99 | 202 | config.return_value = { | 204 | config.return_value = { |
100 | 203 | "reservation": "off", | 205 | "reservation": "off", |
101 | 204 | "isolcpus": "0-10", | 206 | "isolcpus": "0-10", |
102 | @@ -240,15 +242,19 @@ class TestLib: | |||
103 | 240 | ) | 242 | ) |
104 | 241 | check_call.assert_called() | 243 | check_call.assert_called() |
105 | 242 | 244 | ||
106 | 245 | @mock.patch("lib_sysconfig.host.is_container") | ||
107 | 243 | @mock.patch("lib_sysconfig.subprocess.check_call") | 246 | @mock.patch("lib_sysconfig.subprocess.check_call") |
108 | 244 | @mock.patch("lib_sysconfig.hookenv.config") | 247 | @mock.patch("lib_sysconfig.hookenv.config") |
109 | 245 | @mock.patch("lib_sysconfig.hookenv.log") | 248 | @mock.patch("lib_sysconfig.hookenv.log") |
110 | 246 | @mock.patch("lib_sysconfig.render") | 249 | @mock.patch("lib_sysconfig.render") |
112 | 247 | def test_grub_legacy_reservation(self, render, log, config, check_call): | 250 | def test_grub_legacy_reservation( |
113 | 251 | self, render, log, config, check_call, is_container | ||
114 | 252 | ): | ||
115 | 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. |
116 | 249 | 254 | ||
117 | 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. |
118 | 251 | """ | 256 | """ |
119 | 257 | is_container.return_value = False | ||
120 | 252 | config.return_value = { | 258 | config.return_value = { |
121 | 253 | "reservation": "isolcpus", | 259 | "reservation": "isolcpus", |
122 | 254 | "cpu-range": "0-10", | 260 | "cpu-range": "0-10", |
123 | @@ -290,15 +296,19 @@ class TestLib: | |||
124 | 290 | ) | 296 | ) |
125 | 291 | check_call.assert_called() | 297 | check_call.assert_called() |
126 | 292 | 298 | ||
127 | 299 | @mock.patch("lib_sysconfig.host.is_container") | ||
128 | 293 | @mock.patch("lib_sysconfig.subprocess.check_call") | 300 | @mock.patch("lib_sysconfig.subprocess.check_call") |
129 | 294 | @mock.patch("lib_sysconfig.hookenv.config") | 301 | @mock.patch("lib_sysconfig.hookenv.config") |
130 | 295 | @mock.patch("lib_sysconfig.hookenv.log") | 302 | @mock.patch("lib_sysconfig.hookenv.log") |
131 | 296 | @mock.patch("lib_sysconfig.render") | 303 | @mock.patch("lib_sysconfig.render") |
133 | 297 | def test_legacy_grub_config_flags(self, render, log, config, check_call): | 304 | def test_legacy_grub_config_flags( |
134 | 305 | self, render, log, config, check_call, is_container | ||
135 | 306 | ): | ||
136 | 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. |
137 | 299 | 308 | ||
138 | 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. |
139 | 301 | """ | 310 | """ |
140 | 311 | is_container.return_value = False | ||
141 | 302 | config.return_value = { | 312 | config.return_value = { |
142 | 303 | "reservation": "off", | 313 | "reservation": "off", |
143 | 304 | "isolcpus": "", | 314 | "isolcpus": "", |
144 | @@ -485,7 +495,7 @@ class TestLib: | |||
145 | 485 | ): | 495 | ): |
146 | 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. |
147 | 487 | 497 | ||
149 | 488 | Expect apt install is called. | 498 | Expect apt install is called twice. |
150 | 489 | """ | 499 | """ |
151 | 490 | config.return_value = {"kernel-version": "4.15.0-38-generic"} | 500 | config.return_value = {"kernel-version": "4.15.0-38-generic"} |
152 | 491 | 501 | ||
153 | @@ -493,12 +503,10 @@ class TestLib: | |||
154 | 493 | sysh = lib_sysconfig.SysConfigHelper() | 503 | sysh = lib_sysconfig.SysConfigHelper() |
155 | 494 | sysh.install_configured_kernel() | 504 | sysh.install_configured_kernel() |
156 | 495 | 505 | ||
162 | 496 | apt_install.assert_called_with( | 506 | apt_install.assert_any_call( |
163 | 497 | [ | 507 | "linux-modules-extra-{}".format("4.15.0-38-generic") |
159 | 498 | "linux-image-{}".format("4.15.0-38-generic"), | ||
160 | 499 | "linux-modules-extra-{}".format("4.15.0-38-generic"), | ||
161 | 500 | ] | ||
164 | 501 | ) | 508 | ) |
165 | 509 | apt_install.assert_any_call("linux-image-{}".format("4.15.0-38-generic")) | ||
166 | 502 | 510 | ||
167 | 503 | @mock.patch("lib_sysconfig.apt_install") | 511 | @mock.patch("lib_sysconfig.apt_install") |
168 | 504 | @mock.patch("lib_sysconfig.apt_update") | 512 | @mock.patch("lib_sysconfig.apt_update") |
169 | @@ -510,7 +518,7 @@ class TestLib: | |||
170 | 510 | ): | 518 | ): |
171 | 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. |
172 | 512 | 520 | ||
174 | 513 | Expect apt install is not called. | 521 | Expect apt install is called once for linux-modules-extra. |
175 | 514 | """ | 522 | """ |
176 | 515 | kernel_version = "4.15.0-38-generic" | 523 | kernel_version = "4.15.0-38-generic" |
177 | 516 | config.return_value = {"kernel-version": kernel_version} | 524 | config.return_value = {"kernel-version": kernel_version} |
178 | @@ -519,7 +527,9 @@ class TestLib: | |||
179 | 519 | sysh = lib_sysconfig.SysConfigHelper() | 527 | sysh = lib_sysconfig.SysConfigHelper() |
180 | 520 | sysh.install_configured_kernel() | 528 | sysh.install_configured_kernel() |
181 | 521 | 529 | ||
183 | 522 | apt_install.assert_not_called() | 530 | apt_install.assert_called_with( |
184 | 531 | "linux-modules-extra-{}".format("4.15.0-38-generic") | ||
185 | 532 | ) | ||
186 | 523 | 533 | ||
187 | 524 | @mock.patch("lib_sysconfig.apt_install") | 534 | @mock.patch("lib_sysconfig.apt_install") |
188 | 525 | @mock.patch("lib_sysconfig.apt_update") | 535 | @mock.patch("lib_sysconfig.apt_update") |
This merge proposal is being monitored by mergebot. Change the status to Approved to merge.