Add do_install state in API response for drivers

The drivers GET call returned only the value of "has_drivers" (when
known). In order to have the client be able to know the current value of
install/do_install, we now embed the value into the response as well:

Before, the call would return either:

true   -> meaning that there are drivers available to install
false  -> meaning that there are no drivers available to install
null   -> retry later - we don't know yet

Now we have:

  {
      "has_drivers": boolean or null if we don't know yet
      "install": boolean
  }

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2022-01-25 14:34:36 +01:00
parent 43f71a02be
commit 6f183a39ca
3 changed files with 20 additions and 6 deletions

View File

@ -39,6 +39,7 @@ from subiquity.common.types import (
ModifyPartitionV2,
RefreshStatus,
ShutdownMode,
DriversResponse,
SnapInfo,
SnapListResponse,
SnapSelection,
@ -294,8 +295,8 @@ class API:
-> StorageResponseV2: ...
class drivers:
def GET(wait: bool = False) -> Optional[bool]: ...
def POST(install: bool): ...
def GET(wait: bool = False) -> DriversResponse: ...
def POST(install: bool) -> None: ...
class snaplist:
def GET(wait: bool = False) -> SnapListResponse: ...

View File

@ -369,6 +369,17 @@ class SnapInfo:
channels: List[ChannelSnapInfo] = attr.Factory(list)
@attr.s(auto_attribs=True)
class DriversResponse:
""" Response to GET request to drivers.
:install: tells whether third-party drivers will be installed (if any is
available).
:has_drivers: tells if any third-party driver is available. It will bet set
to None until we figure out what drivers are available. """
install: bool
has_drivers: Optional[bool]
@attr.s(auto_attribs=True)
class SnapSelection:
name: str

View File

@ -20,6 +20,7 @@ from typing import Optional
from subiquitycore.context import with_context
from subiquity.common.apidef import API
from subiquity.common.types import DriversResponse
from subiquity.server.controller import SubiquityController
from subiquity.server.curtin import run_curtin_command
from subiquity.server.types import InstallerChannels
@ -42,7 +43,7 @@ class DriversController(SubiquityController):
}
autoinstall_default = {"install": False}
has_drivers = None
has_drivers: Optional[bool] = None
def make_autoinstall(self):
return {
@ -86,11 +87,12 @@ class DriversController(SubiquityController):
if not self.has_drivers:
await self.configured()
async def GET(self, wait: bool = False) -> Optional[bool]:
async def GET(self, wait: bool = False) -> DriversResponse:
if wait:
await self._drivers_task
return self.has_drivers
return DriversResponse(install=self.model.do_install,
has_drivers=self.has_drivers)
async def POST(self, install: bool):
async def POST(self, install: bool) -> None:
self.model.do_install = install
await self.configured()