From caff5f7dd760a0cf0f1647d26024251a94a43a4c Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Tue, 26 Apr 2022 11:23:53 +0200 Subject: [PATCH] source: add support for autoinstall data Since we added a search_drivers checkbox that is uncheckd by default, there is no longer a way for users to install third-party drivers in an autoinstall context. We now implement the autoinstall support for source so that users can specify what value they want for search_drivers. Futhermore, to be backward compatible with existing autoinstall configurations, we now make search_drivers default to true in autoinstall contexts. Signed-off-by: Olivier Gayot --- autoinstall-schema.json | 11 +++++++++ subiquity/server/controllers/source.py | 32 +++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/autoinstall-schema.json b/autoinstall-schema.json index 98db501f..a6bf8e63 100644 --- a/autoinstall-schema.json +++ b/autoinstall-schema.json @@ -118,6 +118,17 @@ ], "additionalProperties": false }, + "source": { + "type": "object", + "properties": { + "search_drivers": { + "type": "boolean" + } + }, + "required": [ + "search_drivers" + ] + }, "network": { "oneOf": [ { diff --git a/subiquity/server/controllers/source.py b/subiquity/server/controllers/source.py index 6f413da9..703cc4a8 100644 --- a/subiquity/server/controllers/source.py +++ b/subiquity/server/controllers/source.py @@ -13,7 +13,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from typing import Optional +from typing import Any, Optional import os from curtin.commands.extract import get_handler_for_source @@ -52,11 +52,41 @@ class SourceController(SubiquityController): endpoint = API.source + autoinstall_key = "source" + autoinstall_schema = { + "type": "object", + "properties": { + "search_drivers": { + "type": "boolean", + }, + }, + "required": ["search_drivers"], + } + # Defaults to true for backward compatibility with existing autoinstall + # configurations. Back then, then users were able to install third-party + # drivers without this field. + autoinstall_default = {"search_drivers": True} + def __init__(self, app): super().__init__(app) self._handler = None self.source_path: Optional[str] = None + def make_autoinstall(self): + return {"search_drivers": self.model.search_drivers} + + def load_autoinstall_data(self, data: Any) -> None: + if data is None: + # For some reason, the schema validator does not reject + # "source: null" despite "type" being "object" + data = self.autoinstall_default + + # search_drivers is marked required so the schema validator should + # reject any missing data. + assert "search_drivers" in data + + self.model.search_drivers = data["search_drivers"] + def start(self): path = '/cdrom/casper/install-sources.yaml' if self.app.opts.source_catalog is not None: