move zdev controller to new world

This commit is contained in:
Michael Hudson-Doyle 2020-10-12 13:43:35 +13:00
parent 45a85c554e
commit e9071a00ca
12 changed files with 88 additions and 42 deletions

View File

@ -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

View File

@ -93,6 +93,7 @@ class SubiquityClient(TuiApplication):
"Welcome",
"Refresh",
"Keyboard",
"Zdev",
"Progress",
]

View File

@ -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',
]

View File

@ -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 <http://www.gnu.org/licenses/>.
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)

View File

@ -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: ...

View File

@ -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 = ''

View File

@ -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',
]

View File

@ -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,

View File

@ -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)

View File

@ -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',
]

View File

@ -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:

View File

@ -121,6 +121,7 @@ class SubiquityServer(Application):
"Locale",
"Refresh",
"Keyboard",
"Zdev",
"Install",
"Late",
]