diff --git a/po/POTFILES.in b/po/POTFILES.in index 3352ae07..f3bb5283 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -6,6 +6,7 @@ subiquity/client/controllers/keyboard.py subiquity/client/controllers/progress.py subiquity/client/controllers/refresh.py subiquity/client/controllers/welcome.py +subiquity/client/controllers/zdev.py subiquity/client/__init__.py subiquity/client/keyboard.py subiquity/client/keycodes.py @@ -41,7 +42,6 @@ subiquity/controllers/snaplist.py subiquity/controllers/ssh.py subiquity/controllers/tests/__init__.py subiquity/controllers/tests/test_filesystem.py -subiquity/controllers/zdev.py subiquitycore/async_helpers.py subiquitycore/contextlib38.py subiquitycore/context.py @@ -126,6 +126,7 @@ subiquity/server/controllers/package.py subiquity/server/controllers/refresh.py subiquity/server/controllers/reporting.py subiquity/server/controllers/userdata.py +subiquity/server/controllers/zdev.py subiquity/server/dryrun.py subiquity/server/errors.py subiquity/server/__init__.py diff --git a/subiquity/client/client.py b/subiquity/client/client.py index 21554fc4..92057241 100644 --- a/subiquity/client/client.py +++ b/subiquity/client/client.py @@ -93,6 +93,7 @@ class SubiquityClient(TuiApplication): "Welcome", "Refresh", "Keyboard", + "Zdev", "Progress", ] diff --git a/subiquity/client/controllers/__init__.py b/subiquity/client/controllers/__init__.py index 313baf40..49a224cf 100644 --- a/subiquity/client/controllers/__init__.py +++ b/subiquity/client/controllers/__init__.py @@ -17,10 +17,12 @@ from .keyboard import KeyboardController from .progress import ProgressController from .refresh import RefreshController from .welcome import WelcomeController +from .zdev import ZdevController __all__ = [ 'KeyboardController', 'ProgressController', 'RefreshController', 'WelcomeController', + 'ZdevController', ] diff --git a/subiquity/client/controllers/zdev.py b/subiquity/client/controllers/zdev.py new file mode 100644 index 00000000..92c7d590 --- /dev/null +++ b/subiquity/client/controllers/zdev.py @@ -0,0 +1,45 @@ +# Copyright 2019 Canonical, Ltd. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +import logging + +from subiquity.client.controller import SubiquityTuiController +from subiquity.ui.views import ZdevView + + +log = logging.getLogger("subiquity.client.controller.zdev") + + +class ZdevController(SubiquityTuiController): + + endpoint_name = 'zdev' + + async def make_ui(self): + infos = await self.endpoint.GET() + return ZdevView(self, infos) + + def run_answers(self): + if 'accept-default' in self.answers: + self.done() + + def cancel(self): + self.app.prev_screen() + + def done(self): + # switch to next screen + self.app.next_screen() + + async def chzdev(self, action, zdevinfo): + return await self.endpoint.chzdev.POST(action, zdevinfo) diff --git a/subiquity/common/apidef.py b/subiquity/common/apidef.py index f209ec4f..6a4f6056 100644 --- a/subiquity/common/apidef.py +++ b/subiquity/common/apidef.py @@ -24,6 +24,7 @@ from subiquity.common.types import ( InstallState, InstallStatus, RefreshStatus, + ZdevInfo, ) @@ -61,7 +62,6 @@ class API: class crash: def GET() -> None: """Requests to this method will fail with a HTTP 500.""" - class refresh: def GET(wait: bool = False) -> RefreshStatus: """Get information about the snap refresh status. @@ -74,6 +74,12 @@ class API: class progress: def GET(change_id: int) -> dict: ... + class zdev: + def GET() -> List[ZdevInfo]: ... + + class chzdev: + def POST(action: str, zdev: ZdevInfo) -> List[ZdevInfo]: ... + class install: class status: def GET(cur: Optional[InstallState] = None) -> InstallStatus: ... diff --git a/subiquity/common/types.py b/subiquity/common/types.py index fb82e8b9..8ea578bb 100644 --- a/subiquity/common/types.py +++ b/subiquity/common/types.py @@ -115,6 +115,13 @@ class ZdevInfo: return self.type +class Bootloader(enum.Enum): + NONE = "NONE" # a system where the bootloader is external, e.g. s390x + BIOS = "BIOS" # BIOS, where the bootloader dd-ed to the start of a device + UEFI = "UEFI" # UEFI, ESPs and /boot/efi and all that (amd64 and arm64) + PREP = "PREP" # ppc64el, which puts grub on a PReP partition + + @attr.s(auto_attribs=True) class IdentityData: realname: str = '' diff --git a/subiquity/controllers/__init__.py b/subiquity/controllers/__init__.py index de9e3df0..06805c66 100644 --- a/subiquity/controllers/__init__.py +++ b/subiquity/controllers/__init__.py @@ -22,7 +22,6 @@ from .proxy import ProxyController from .reboot import RebootController from .snaplist import SnapListController from .ssh import SSHController -from .zdev import ZdevController __all__ = [ 'FilesystemController', @@ -34,5 +33,4 @@ __all__ = [ 'RepeatedController', 'SnapListController', 'SSHController', - 'ZdevController', ] diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index dfa292d8..8e4384a9 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -34,10 +34,10 @@ from subiquitycore.utils import ( from subiquity.common.errorreport import ErrorReportKind +from subiquity.common.types import Bootloader from subiquity.controller import SubiquityTuiController from subiquity.models.filesystem import ( align_up, - Bootloader, DeviceAction, dehumanize_size, Partition, diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index b2eabf02..e6cf2218 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -34,6 +34,8 @@ from probert.storage import StorageInfo from subiquitycore.gettext38 import pgettext +from subiquity.common.types import Bootloader + log = logging.getLogger('subiquity.models.filesystem') @@ -1308,13 +1310,6 @@ def align_down(size, block_size=1 << 20): return size & ~(block_size - 1) -class Bootloader(enum.Enum): - NONE = "NONE" # a system where the bootloader is external, e.g. s390x - BIOS = "BIOS" # BIOS, where the bootloader dd-ed to the start of a device - UEFI = "UEFI" # UEFI, ESPs and /boot/efi and all that (amd64 and arm64) - PREP = "PREP" # ppc64el, which puts grub on a PReP partition - - class FilesystemModel(object): lower_size_limit = 128 * (1 << 20) diff --git a/subiquity/server/controllers/__init__.py b/subiquity/server/controllers/__init__.py index 47fbb36c..a960c3c6 100644 --- a/subiquity/server/controllers/__init__.py +++ b/subiquity/server/controllers/__init__.py @@ -22,6 +22,7 @@ from .package import PackageController from .refresh import RefreshController from .reporting import ReportingController from .userdata import UserdataController +from .zdev import ZdevController __all__ = [ 'DebconfController', @@ -35,4 +36,5 @@ __all__ = [ 'RefreshController', 'ReportingController', 'UserdataController', + 'ZdevController', ] diff --git a/subiquity/controllers/zdev.py b/subiquity/server/controllers/zdev.py similarity index 98% rename from subiquity/controllers/zdev.py rename to subiquity/server/controllers/zdev.py index 933c3980..233d7e3c 100644 --- a/subiquity/controllers/zdev.py +++ b/subiquity/server/controllers/zdev.py @@ -17,20 +17,18 @@ import asyncio import logging import platform import random +from typing import List from collections import OrderedDict -from subiquitycore.tuicontroller import ( - Skip, - ) from subiquitycore.utils import arun_command, run_command -from subiquity.common.types import ZdevInfo -from subiquity.controller import SubiquityTuiController -from subiquity.ui.views import ZdevView +from subiquity.common.apidef import API +from subiquity.common.types import Bootloader, ZdevInfo +from subiquity.server.controller import SubiquityController -log = logging.getLogger("subiquitycore.controller.zdev") +log = logging.getLogger("subiquity.server.controller.zdev") lszdev_cmd = ['lszdev', '--pairs', '--columns', 'id,type,on,exists,pers,auto,failed,names'] @@ -592,7 +590,9 @@ id="0.0.f1fe:0.0.f1ff" type="ctc" on="no" exists="yes" pers="no" auto="no" faile id="0.0.c0fe" type="generic-ccw" on="no" exists="yes" pers="no" auto="no" failed="yes" names=""''' # noqa: E501 -class ZdevController(SubiquityTuiController): +class ZdevController(SubiquityController): + + endpoint = API.zdev def __init__(self, app): super().__init__(app) @@ -605,35 +605,23 @@ class ZdevController(SubiquityTuiController): zdevinfos = [ZdevInfo.from_row(row) for row in devices] self.zdevinfos = OrderedDict([(i.id, i) for i in zdevinfos]) - def make_ui(self): - if not self.app.opts.bootloader == 'none' \ - and platform.machine() != 's390x': - raise Skip - return ZdevView(self, self.get_zdevinfos()) + def interactive(self): + if self.app.base_model.filesystem.bootloader != Bootloader.NONE: + return False + return super().interactive() - def run_answers(self): - if 'accept-default' in self.answers: - self.done() - - def cancel(self): - self.app.prev_screen() - - def done(self): - # switch to next screen - self.app.next_screen() - - async def chzdev(self, action, zdevinfo): + async def chzdev_POST(self, action: str, zdev: ZdevInfo) -> List[ZdevInfo]: if self.opts.dry_run: await asyncio.sleep(random.random()*0.4) on = action == 'enable' - self.zdevinfos[zdevinfo.id].on = on - self.zdevinfos[zdevinfo.id].pers = on + self.zdevinfos[zdev.id].on = on + self.zdevinfos[zdev.id].pers = on else: - chzdev_cmd = ['chzdev', '--%s' % action, zdevinfo.id] + chzdev_cmd = ['chzdev', '--%s' % action, zdev.id] await arun_command(chzdev_cmd) - return self.get_zdevinfos() + return await self.GET() - def get_zdevinfos(self): + async def GET(self) -> List[ZdevInfo]: if self.opts.dry_run: return self.zdevinfos.values() else: diff --git a/subiquity/server/server.py b/subiquity/server/server.py index e8241a27..c277a424 100644 --- a/subiquity/server/server.py +++ b/subiquity/server/server.py @@ -121,6 +121,7 @@ class SubiquityServer(Application): "Locale", "Refresh", "Keyboard", + "Zdev", "Install", "Late", ]