From e6ccfcc11882a414e6c0e41cd2037c787683e61f Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 26 Jun 2023 20:02:25 +0200 Subject: [PATCH] oem: allow to disable install on desktop and force install on server By default, OEM meta-packages get installed on ubuntu-desktop and don't get installed on ubuntu-server. Using autoinstall, we can now give more control. The autoinstall section supports the following: Install on server and desktop: oem: install: true Do not install even on desktop: oem: install: false Install only on desktop (the default): oem: install: auto Signed-off-by: Olivier Gayot --- autoinstall-schema.json | 19 +++++++++++++++ documentation/autoinstall-reference.md | 15 ++++++++++++ documentation/autoinstall-schema.md | 19 +++++++++++++++ subiquity/models/oem.py | 33 +++++++++++++++++++++++++- subiquity/server/controllers/oem.py | 32 +++++++++++++++++++++---- 5 files changed, 113 insertions(+), 5 deletions(-) diff --git a/autoinstall-schema.json b/autoinstall-schema.json index 708239d0..5684adbc 100644 --- a/autoinstall-schema.json +++ b/autoinstall-schema.json @@ -489,6 +489,25 @@ } } }, + "oem": { + "type": "object", + "properties": { + "install": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string", + "const": "auto" + } + ] + } + }, + "required": [ + "install" + ] + }, "timezone": { "type": "string" }, diff --git a/documentation/autoinstall-reference.md b/documentation/autoinstall-reference.md index 65288a77..8b808e71 100644 --- a/documentation/autoinstall-reference.md +++ b/documentation/autoinstall-reference.md @@ -575,6 +575,21 @@ Whether to install the ubuntu-restricted-addons package. Whether to install the available third-party drivers. + + +### oem + +**type:** mapping, see below +**default:** see below +**can be interactive:** no + +#### install + +**type:** boolean or string (special value `auto`) +**default:**: `auto` + +Whether to install the available OEM meta-packages. The special value `auto` - which is the default - enables the installation on ubuntu-desktop but not on ubuntu-server. + ### snaps diff --git a/documentation/autoinstall-schema.md b/documentation/autoinstall-schema.md index e49b1922..5645f7d7 100644 --- a/documentation/autoinstall-schema.md +++ b/documentation/autoinstall-schema.md @@ -509,6 +509,25 @@ The [JSON schema](https://json-schema.org/) for autoinstall data is as follows: } } }, + "oem": { + "type": "object", + "properties": { + "install": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string", + "const": "auto" + } + ] + } + }, + "required": [ + "install" + ] + }, "timezone": { "type": "string" }, diff --git a/subiquity/models/oem.py b/subiquity/models/oem.py index eccc9436..c01e0076 100644 --- a/subiquity/models/oem.py +++ b/subiquity/models/oem.py @@ -14,7 +14,7 @@ # along with this program. If not, see . import logging -from typing import List, Optional +from typing import Any, Dict, List, Optional, Union import attr @@ -32,3 +32,34 @@ class OEMModel: # List of OEM metapackages relevant to the current hardware. # When the list is None, it has not yet been retrieved. self.metapkgs: Optional[List[OEMMetaPkg]] = None + + # By default, skip looking for OEM meta-packages if we are running + # ubuntu-server. OEM meta-packages expect the default kernel flavor to + # be HWE (which is only true for ubuntu-desktop). + self.install_on = { + "server": False, + "desktop": True, + } + + def make_autoinstall(self) -> Dict[str, Union[str, bool]]: + server = self.install_on["server"] + desktop = self.install_on["desktop"] + + if server and desktop: + return {"install": True} + if not server and not desktop: + return {"install": False} + + # Having server = True and desktop = False is not supported. + assert desktop and not server + + return {"install": "auto"} + + def load_autoinstall_data(self, data: Dict[str, Any]) -> None: + if data["install"] == "auto": + self.install_on["server"] = False + self.install_on["desktop"] = True + return + + self.install_on["server"] = data["install"] + self.install_on["desktop"] = data["install"] diff --git a/subiquity/server/controllers/oem.py b/subiquity/server/controllers/oem.py index 0092f3db..c9412b2b 100644 --- a/subiquity/server/controllers/oem.py +++ b/subiquity/server/controllers/oem.py @@ -39,7 +39,25 @@ class OEMController(SubiquityController): endpoint = API.oem - model_name = "oem" + autoinstall_key = model_name = "oem" + autoinstall_schema = { + "type": "object", + "properties": { + "install": { + "oneOf": [ + { + "type": "boolean", + }, + { + "type": "string", + "const": "auto", + }, + ], + }, + }, + "required": ["install"], + } + autoinstall_default = {"install": "auto"} def __init__(self, app) -> None: super().__init__(app) @@ -67,6 +85,12 @@ class OEMController(SubiquityController): self.load_metapkgs_task = asyncio.create_task( list_and_mark_configured()) + def make_autoinstall(self): + return self.model.make_autoinstall() + + def load_autoinstall_data(self, *args, **kwargs) -> None: + self.model.load_autoinstall_data(*args, **kwargs) + async def wants_oem_kernel(self, pkgname: str, *, context, overlay) -> bool: """ For a given package, tell whether it wants the OEM or the default @@ -103,9 +127,9 @@ class OEMController(SubiquityController): # Skip looking for OEM meta-packages if we are running ubuntu-server. # OEM meta-packages expect the default kernel flavor to be HWE (which # is only true for ubuntu-desktop). - if self.app.base_model.source.current.variant == "server": - log.debug("not listing OEM meta-packages since we are installing" - " ubuntu-server") + variant: str = self.app.base_model.source.current.variant + if not self.model.install_on[variant]: + log.debug("listing of OEM meta-packages disabled on %s", variant) self.model.metapkgs = [] return