system_setup: update the detection logic

This commit is contained in:
Patrick Wu 2021-09-20 14:37:55 +08:00
parent ceae8e9d19
commit 1aac580dfd
10 changed files with 83 additions and 32 deletions

View File

@ -114,6 +114,8 @@ class SubiquityClient(TuiApplication):
"Progress", "Progress",
] ]
variant_to_controllers = {}
def __init__(self, opts): def __init__(self, opts):
if is_linux_tty(): if is_linux_tty():
self.input_filter = KeyCodesFilter() self.input_filter = KeyCodesFilter()
@ -321,6 +323,16 @@ class SubiquityClient(TuiApplication):
]) ])
print(line) print(line)
return return
# Get the variant from the server and reload desired
# controllers if an override exists
variant = await self.client.meta.client_variant.GET()
if variant != self.variant:
self.variant = variant
controllers = self.variant_to_controllers.get(variant)
if controllers:
self.load_controllers(controllers)
await super().start() await super().start()
# Progress uses systemd to collect and display the installation # Progress uses systemd to collect and display the installation
# logs. Although some system don't have systemd, so we disable # logs. Although some system don't have systemd, so we disable

View File

@ -105,8 +105,6 @@ class SubiquityModel:
if root != '/': if root != '/':
self.target = root self.target = root
self.client_variant = ''
self.debconf_selections = DebconfSelectionsModel() self.debconf_selections = DebconfSelectionsModel()
self.filesystem = FilesystemModel() self.filesystem = FilesystemModel()
self.identity = IdentityModel() self.identity = IdentityModel()
@ -137,7 +135,6 @@ class SubiquityModel:
self._postinstall_event = asyncio.Event() self._postinstall_event = asyncio.Event()
def set_source_variant(self, variant): def set_source_variant(self, variant):
self.client_variant = variant
self._cur_install_model_names = \ self._cur_install_model_names = \
self._install_model_names.for_variant(variant) self._install_model_names.for_variant(variant)
self._cur_postinstall_model_names = \ self._cur_postinstall_model_names = \

View File

@ -123,9 +123,10 @@ class MetaController:
self.app.controllers.Source.configured() self.app.controllers.Source.configured()
else: else:
self.app.base_model.set_source_variant(variant) self.app.base_model.set_source_variant(variant)
self.app.variant = variant
async def client_variant_GET(self) -> str: async def client_variant_GET(self) -> str:
return self.app.base_model.client_variant return self.app.variant
async def ssh_info_GET(self) -> Optional[LiveSessionSSHInfo]: async def ssh_info_GET(self) -> Optional[LiveSessionSSHInfo]:
ips = [] ips = []
@ -250,6 +251,7 @@ class SubiquityServer(Application):
def __init__(self, opts, block_log_dir): def __init__(self, opts, block_log_dir):
super().__init__(opts) super().__init__(opts)
self.set_source_variant(self.supported_variants[0])
self.block_log_dir = block_log_dir self.block_log_dir = block_log_dir
self.cloud = None self.cloud = None
self.cloud_init_ok = None self.cloud_init_ok = None
@ -297,6 +299,9 @@ class SubiquityServer(Application):
self._proxy_set) self._proxy_set)
self.geoip = GeoIP(self) self.geoip = GeoIP(self)
def set_source_variant(self, variant):
self.variant = variant
def load_serialized_state(self): def load_serialized_state(self):
for controller in self.controllers.instances: for controller in self.controllers.instances:
controller.load_state() controller.load_state()

View File

@ -72,10 +72,17 @@ class Application:
self.hub = MessageHub() self.hub = MessageHub()
self.aio_loop = asyncio.get_event_loop() self.aio_loop = asyncio.get_event_loop()
self.aio_loop.set_exception_handler(self._exception_handler) self.aio_loop.set_exception_handler(self._exception_handler)
self.controllers = ControllerSet( self.load_controllers(self.controllers)
self.controllers_mod, self.controllers, init_args=(self,))
self.context = Context.new(self) self.context = Context.new(self)
def load_controllers(self, controllers):
""" Load the corresponding list of controllers
Those will need to be restarted if already started """
self.controllers = ControllerSet(
self.controllers_mod, controllers,
init_args=(self,))
def _exception_handler(self, loop, context): def _exception_handler(self, loop, context):
exc = context.get('exception') exc = context.get('exception')
if exc: if exc:

View File

@ -15,7 +15,7 @@
import logging import logging
import sys import sys
from system_setup.common.helpers import is_reconfigure import os
from subiquity.client.client import SubiquityClient from subiquity.client.client import SubiquityClient
@ -37,14 +37,43 @@ class SystemSetupClient(SubiquityClient):
"WSLIdentity", "WSLIdentity",
"WSLConfigurationBase", "WSLConfigurationBase",
"Summary", "Summary",
] ]
def __init__(self, opts): variant_to_controllers = {
if is_reconfigure(opts.dry_run): "wsl_setup": controllers,
self.variant = "wsl_configuration" "wsl_configuration": [
self.controllers = [ "WSLConfigurationBase",
"WSLConfigurationBase", "WSLConfigurationAdvanced",
"WSLConfigurationAdvanced", "Summary",
"Summary", ]
] }
super().__init__(opts)
def restart(self, remove_last_screen=True, restart_server=False):
log.debug(f"restart {remove_last_screen} {restart_server}")
if self.fg_proc is not None:
log.debug(
"killing foreground process %s before restarting",
self.fg_proc)
self.restarting = True
self.aio_loop.create_task(
self._kill_fg_proc(remove_last_screen, restart_server))
return
if remove_last_screen:
self._remove_last_screen()
if restart_server:
self.restarting = True
self.ui.block_input = True
self.aio_loop.create_task(self._restart_server())
return
if self.urwid_loop is not None:
self.urwid_loop.stop()
cmdline = sys.argv
if self.opts.dry_run:
cmdline = [
sys.executable, '-m', 'system_setup.cmd.tui',
] + sys.argv[1:] + ['--socket', self.opts.socket]
if self.opts.server_pid is not None:
cmdline.extend(['--server-pid', self.opts.server_pid])
log.debug("restarting %r", cmdline)
os.execvp(cmdline[0], cmdline)

View File

@ -12,11 +12,7 @@ class WSLConfigurationBaseController(SubiquityTuiController):
async def make_ui(self): async def make_ui(self):
data = await self.endpoint.GET() data = await self.endpoint.GET()
variant = "wsl_setup" return WSLConfigurationBaseView(self, data)
onsite_variant = getattr(self.app, "variant")
if onsite_variant is not None:
variant = onsite_variant
return WSLConfigurationBaseView(self, data, variant)
def run_answers(self): def run_answers(self):
if all(elem in self.answers for elem in if all(elem in self.answers for elem in

View File

@ -18,14 +18,15 @@ import os
def is_reconfigure(is_dryrun): def is_reconfigure(is_dryrun):
is_dryrun_reconfigure = is_dryrun and \ if is_dryrun and \
os.getenv("DRYRUN_RECONFIG") == "true" os.getenv("DRYRUN_RECONFIG") == "true":
count = 0 return True
if_normaluser = False
with open('/etc/passwd', 'r') as f: with open('/etc/passwd', 'r') as f:
for line in f: for line in f:
# check every normal user except nobody (65534) # check every normal user except nobody (65534)
if int(line.split(':')[2]) >= 1000 and \ if int(line.split(':')[2]) >= 1000 and \
int(line.split(':')[2]) != 65534: int(line.split(':')[2]) != 65534:
count += 1 if_normaluser = True
is_none_dryrun_normaluser = not is_dryrun and count != 0 break
return is_dryrun_reconfigure or is_none_dryrun_normaluser return not is_dryrun and if_normaluser

View File

@ -33,6 +33,7 @@ class ConfigureController(SubiquityController):
def __init__(self, app): def __init__(self, app):
super().__init__(app) super().__init__(app)
self.app = app
self.model = app.base_model self.model = app.base_model
def start(self): def start(self):

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from system_setup.common.helpers import is_reconfigure
from subiquity.server.server import SubiquityServer from subiquity.server.server import SubiquityServer
from system_setup.models.system_setup import SystemSetupModel from system_setup.models.system_setup import SystemSetupModel
from subiquity.models.subiquity import ModelNames from subiquity.models.subiquity import ModelNames
@ -51,6 +52,11 @@ class SystemSetupServer(SubiquityServer):
supported_variants = ["wsl_setup", "wsl_configuration"] supported_variants = ["wsl_setup", "wsl_configuration"]
def __init__(self, opts, block_log_dir):
super().__init__(opts, block_log_dir)
if is_reconfigure(opts.dry_run):
self.set_source_variant("wsl_configuration")
def make_model(self): def make_model(self):
root = '/' root = '/'
if self.opts.dry_run: if self.opts.dry_run:

View File

@ -95,12 +95,9 @@ class WSLConfigurationBaseView(BaseView):
excerpt = _( excerpt = _(
"In this page, you can configure Ubuntu WSL options to your needs.\n") "In this page, you can configure Ubuntu WSL options to your needs.\n")
def __init__(self, controller, configuration_data, variant): def __init__(self, controller, configuration_data):
self.controller = controller self.controller = controller
self.is_conf = variant == "wsl_configuration"
if self.is_conf:
self.title = _("WSL configuration - Base options")
initial = { initial = {
'custom_path': configuration_data.custom_path, 'custom_path': configuration_data.custom_path,
'custom_mount_opt': configuration_data.custom_mount_opt, 'custom_mount_opt': configuration_data.custom_mount_opt,