move controllers with no api presence to server

This commit is contained in:
Michael Hudson-Doyle 2020-10-09 21:25:49 +13:00
parent 3367b41cf1
commit 7faa1634ff
10 changed files with 78 additions and 62 deletions

View File

@ -27,25 +27,19 @@ subiquity/common/serialize.py
subiquity/common/tests/test_keyboard.py
subiquity/common/types.py
subiquity/controller.py
subiquity/controllers/cmdlist.py
subiquity/controllers/debconf.py
subiquity/controllers/error.py
subiquity/controllers/filesystem.py
subiquity/controllers/identity.py
subiquity/controllers/__init__.py
subiquity/controllers/keyboard.py
subiquity/controllers/mirror.py
subiquity/controllers/network.py
subiquity/controllers/package.py
subiquity/controllers/proxy.py
subiquity/controllers/reboot.py
subiquity/controllers/refresh.py
subiquity/controllers/reporting.py
subiquity/controllers/snaplist.py
subiquity/controllers/ssh.py
subiquity/controllers/tests/__init__.py
subiquity/controllers/tests/test_filesystem.py
subiquity/controllers/userdata.py
subiquity/controllers/zdev.py
subiquitycore/async_helpers.py
subiquitycore/contextlib38.py
@ -122,9 +116,14 @@ subiquity/models/tests/test_filesystem.py
subiquity/models/tests/test_mirror.py
subiquity/models/tests/test_subiquity.py
subiquity/server/controller.py
subiquity/server/controllers/cmdlist.py
subiquity/server/controllers/debconf.py
subiquity/server/controllers/__init__.py
subiquity/server/controllers/install.py
subiquity/server/controllers/locale.py
subiquity/server/controllers/package.py
subiquity/server/controllers/reporting.py
subiquity/server/controllers/userdata.py
subiquity/server/dryrun.py
subiquity/server/errors.py
subiquity/server/__init__.py

View File

@ -14,42 +14,29 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ..controller import RepeatedController
from .cmdlist import EarlyController, LateController
from .debconf import DebconfController
from .error import ErrorController
from .filesystem import FilesystemController
from .identity import IdentityController
from .keyboard import KeyboardController
from .mirror import MirrorController
from .network import NetworkController
from .package import PackageController
from .proxy import ProxyController
from .reboot import RebootController
from .refresh import RefreshController
from .reporting import ReportingController
from .snaplist import SnapListController
from .ssh import SSHController
from .userdata import UserdataController
from .zdev import ZdevController
__all__ = [
'DebconfController',
'EarlyController',
'ErrorController',
'FilesystemController',
'IdentityController',
'KeyboardController',
'LateController',
'MirrorController',
'NetworkController',
'PackageController',
'ProxyController',
'RebootController',
'RefreshController',
'RepeatedController',
'ReportingController',
'SnapListController',
'SSHController',
'UserdataController',
'ZdevController',
]

View File

@ -1,27 +0,0 @@
# 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.controllers.cmdlist import CmdListController
log = logging.getLogger('subiquity.controllers.error')
class ErrorController(CmdListController):
autoinstall_key = 'error-commands'
cmd_check = False

View File

@ -13,10 +13,22 @@
# 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/>.
from .cmdlist import EarlyController, LateController, ErrorController
from .debconf import DebconfController
from .install import InstallController
from .locale import LocaleController
from .package import PackageController
from .reporting import ReportingController
from .userdata import UserdataController
__all__ = [
'DebconfController',
'EarlyController',
'ErrorController',
'InstallController',
'LateController',
'LocaleController',
'PackageController',
'ReportingController',
'UserdataController',
]

View File

@ -13,15 +13,19 @@
# 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 asyncio
import os
from systemd import journal
from subiquitycore.context import with_context
from subiquitycore.utils import arun_command
from subiquity.controller import SubiquityController
from subiquity.common.types import InstallState
from subiquity.server.controller import NonInteractiveController
class CmdListController(SubiquityController):
class CmdListController(NonInteractiveController):
autoinstall_default = []
autoinstall_schema = {
@ -33,6 +37,11 @@ class CmdListController(SubiquityController):
}
cmds = ()
cmd_check = True
send_to_journal = False
def __init__(self, app):
super().__init__(app)
self.run_event = asyncio.Event()
def load_autoinstall_data(self, data):
self.cmds = data
@ -44,18 +53,32 @@ class CmdListController(SubiquityController):
async def run(self, context):
env = self.env()
for i, cmd in enumerate(self.cmds):
with context.child("command_{}".format(i), cmd):
if isinstance(cmd, str):
desc = cmd
else:
desc = ' '.join(cmd)
with context.child("command_{}".format(i), desc):
if isinstance(cmd, str):
cmd = ['sh', '-c', cmd]
if self.send_to_journal:
journal.send(
" running " + desc,
SYSLOG_IDENTIFIER=self.app.early_commands_syslog_id)
cmd = [
'systemd-cat', '--level-prefix=false',
'--identifier=' + self.app.early_commands_syslog_id,
] + cmd
await arun_command(
cmd, env=env,
stdin=None, stdout=None, stderr=None,
check=self.cmd_check)
self.run_event.set()
class EarlyController(CmdListController):
autoinstall_key = 'early-commands'
send_to_journal = True
class LateController(CmdListController):
@ -67,6 +90,17 @@ class LateController(CmdListController):
env['TARGET_MOUNT_POINT'] = self.app.base_model.target
return env
@with_context()
async def apply_autoinstall_config(self, context):
await self.run(context=context)
def start(self):
self.app.aio_loop.create_task(self._run())
async def _run(self):
Install = self.app.controllers.Install
await Install.install_task
if Install.install_state == InstallState.DONE:
await self.run()
class ErrorController(CmdListController):
autoinstall_key = 'error-commands'
cmd_check = False

View File

@ -13,10 +13,10 @@
# 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/>.
from subiquity.controller import SubiquityController
from subiquity.server.controller import NonInteractiveController
class DebconfController(SubiquityController):
class DebconfController(NonInteractiveController):
model_name = "debconf_selections"
autoinstall_key = "debconf-selections"

View File

@ -13,10 +13,10 @@
# 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/>.
from subiquity.controller import SubiquityController
from subiquity.server.controller import NonInteractiveController
class PackageController(SubiquityController):
class PackageController(NonInteractiveController):
model_name = autoinstall_key = "packages"
autoinstall_default = []

View File

@ -29,7 +29,7 @@ from curtin.reporter.handlers import (
LogHandler,
)
from subiquity.controller import SubiquityController
from subiquity.server.controller import NonInteractiveController
class LogHandler(LogHandler):
@ -42,10 +42,13 @@ class LogHandler(LogHandler):
available_handlers.unregister_item('log')
available_handlers.register_item('log', LogHandler)
INITIAL_CONFIG = {'logging': {'type': 'log'}}
INITIAL_CONFIG = {
'logging': {'type': 'log'},
}
NON_INTERACTIVE_CONFIG = {'builtin': {'type': 'print'}}
class ReportingController(SubiquityController):
class ReportingController(NonInteractiveController):
autoinstall_key = "reporting"
autoinstall_schema = {
@ -61,13 +64,14 @@ class ReportingController(SubiquityController):
}
def __init__(self, app):
self.config = copy.deepcopy(INITIAL_CONFIG)
super().__init__(app)
self.config = copy.deepcopy(INITIAL_CONFIG)
app.add_event_listener(self)
def load_autoinstall_data(self, data):
if self.app.interactive():
return
self.config.update(copy.deepcopy(NON_INTERACTIVE_CONFIG))
if data is not None:
self.config.update(copy.deepcopy(data))

View File

@ -13,10 +13,10 @@
# 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/>.
from subiquity.controller import SubiquityController
from subiquity.server.controller import NonInteractiveController
class UserdataController(SubiquityController):
class UserdataController(NonInteractiveController):
model_name = 'userdata'
autoinstall_key = "user-data"

View File

@ -112,8 +112,15 @@ class SubiquityServer(Application):
project = "subiquity"
from subiquity.server import controllers as controllers_mod
controllers = [
"Early",
"Reporting",
"Error",
"Userdata",
"Package",
"Debconf",
"Locale",
"Install",
"Late",
]
def make_model(self):