-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2074 from Chris-Peterson444/kernel-crash-dumps-in…
…troduction Kernel crash dumps autoinstall
- Loading branch information
Showing
14 changed files
with
260 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ debconf | |
debian | ||
dir | ||
el | ||
enablement | ||
flavor | ||
geoip | ||
geolocation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
from typing import Any | ||
|
||
log = logging.getLogger("subiquity.models.kernel_crash_dumps") | ||
|
||
|
||
class KernelCrashDumpsModel: | ||
# Set to True/False via autoinstall. Defaults to None to let curtin know | ||
# to do dynamic enablement based on release, arch, etc. | ||
enabled: bool | None = None | ||
|
||
def render(self) -> dict[str, Any]: | ||
return { | ||
"kernel-crash-dumps": { | ||
"enabled": self.enabled, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
from subiquity.models.kernel_crash_dumps import KernelCrashDumpsModel | ||
from subiquitycore.tests import SubiTestCase | ||
|
||
|
||
class TestKernelCrashDumpsModel(SubiTestCase): | ||
def setUp(self): | ||
self.model = KernelCrashDumpsModel() | ||
|
||
def test_automatic_decision(self): | ||
"""Test the curtin config for curtin automatic enablement.""" | ||
expected = {"kernel-crash-dumps": {"enabled": None}} | ||
self.assertEqual(expected, self.model.render()) | ||
|
||
def test_render_formatting(self): | ||
"""Test the curtin config populates with correct formatting.""" | ||
config = {} | ||
self.model.enabled = config["enabled"] = True | ||
expected = {"kernel-crash-dumps": config} | ||
self.assertEqual(expected, self.model.render()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import logging | ||
from typing import TypedDict | ||
|
||
from subiquity.server.controller import NonInteractiveController | ||
|
||
log = logging.getLogger("subiquity.server.controllers.kernel_crash_dumps") | ||
|
||
|
||
class KernelCrashDumpsConfig(TypedDict, total=True): | ||
enabled: bool | None | ||
|
||
|
||
class KernelCrashDumpsController(NonInteractiveController): | ||
model_name = "kernel_crash_dumps" | ||
autoinstall_key = "kernel-crash-dumps" | ||
autoinstall_schema = { | ||
"type": "object", | ||
"properties": { | ||
"enabled": {"type": ["boolean", "null"]}, | ||
}, | ||
"required": ["enabled"], | ||
"additionalProperties": False, | ||
} | ||
|
||
def load_autoinstall_data(self, data: KernelCrashDumpsConfig | None) -> None: | ||
if data is None: | ||
return | ||
self.model.enabled = data["enabled"] | ||
|
||
def make_autoinstall(self) -> dict[str, KernelCrashDumpsConfig]: | ||
# Automatic determination implies no autoinstall | ||
if self.model.enabled is None: | ||
return {} | ||
|
||
return {"enabled": self.model.enabled} |
68 changes: 68 additions & 0 deletions
68
subiquity/server/controllers/tests/test_kernel_crash_dumps.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2024 Canonical, Ltd. | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, version 3. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import jsonschema | ||
from jsonschema.validators import validator_for | ||
|
||
from subiquity.models.kernel_crash_dumps import KernelCrashDumpsModel | ||
from subiquity.server.autoinstall import AutoinstallValidationError | ||
from subiquity.server.controllers.kernel_crash_dumps import KernelCrashDumpsController | ||
from subiquitycore.tests import SubiTestCase | ||
from subiquitycore.tests.mocks import make_app | ||
from subiquitycore.tests.parameterized import parameterized | ||
|
||
|
||
class TestKernelCrashDumpsSchema(SubiTestCase): | ||
def test_valid_schema(self): | ||
"""Test that the expected autoinstall JSON schema is valid""" | ||
|
||
JsonValidator: jsonschema.protocols.Validator = validator_for( | ||
KernelCrashDumpsController.autoinstall_schema | ||
) | ||
|
||
JsonValidator.check_schema(KernelCrashDumpsController.autoinstall_schema) | ||
|
||
|
||
class TestKernelCrashDumpsAutoinstall(SubiTestCase): | ||
def setUp(self): | ||
app = make_app() | ||
self.controller = KernelCrashDumpsController(app) | ||
self.controller.model = KernelCrashDumpsModel() | ||
|
||
@parameterized.expand( | ||
( | ||
# (config, valid) | ||
# Valid configs | ||
({"enabled": True}, True), | ||
({"enabled": False}, True), | ||
({"enabled": None}, True), | ||
# Invalid configs | ||
({}, False), | ||
) | ||
) | ||
def test_valid_configs(self, config, valid): | ||
"""Test autoinstall config validation behavior.""" | ||
if valid: | ||
self.controller.validate_autoinstall(config) | ||
else: | ||
with self.assertRaises(AutoinstallValidationError): | ||
self.controller.validate_autoinstall(config) | ||
|
||
def test_make_autoinstall__default_empty(self): | ||
self.assertEqual(self.controller.make_autoinstall(), {}) | ||
|
||
def test_make_autoinstall__non_default_format(self): | ||
self.controller.model.enabled = False | ||
expected = {"enabled": False} | ||
self.assertEqual(self.controller.make_autoinstall(), expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters