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",
]
variant_to_controllers = {}
def __init__(self, opts):
if is_linux_tty():
self.input_filter = KeyCodesFilter()
@ -321,6 +323,16 @@ class SubiquityClient(TuiApplication):
])
print(line)
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()
# Progress uses systemd to collect and display the installation
# logs. Although some system don't have systemd, so we disable

View File

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

View File

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

View File

@ -72,10 +72,17 @@ class Application:
self.hub = MessageHub()
self.aio_loop = asyncio.get_event_loop()
self.aio_loop.set_exception_handler(self._exception_handler)
self.controllers = ControllerSet(
self.controllers_mod, self.controllers, init_args=(self,))
self.load_controllers(self.controllers)
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):
exc = context.get('exception')
if exc:

View File

@ -15,7 +15,7 @@
import logging
import sys
from system_setup.common.helpers import is_reconfigure
import os
from subiquity.client.client import SubiquityClient
@ -39,12 +39,41 @@ class SystemSetupClient(SubiquityClient):
"Summary",
]
def __init__(self, opts):
if is_reconfigure(opts.dry_run):
self.variant = "wsl_configuration"
self.controllers = [
variant_to_controllers = {
"wsl_setup": controllers,
"wsl_configuration": [
"WSLConfigurationBase",
"WSLConfigurationAdvanced",
"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):
data = await self.endpoint.GET()
variant = "wsl_setup"
onsite_variant = getattr(self.app, "variant")
if onsite_variant is not None:
variant = onsite_variant
return WSLConfigurationBaseView(self, data, variant)
return WSLConfigurationBaseView(self, data)
def run_answers(self):
if all(elem in self.answers for elem in

View File

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

View File

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

View File

@ -13,6 +13,7 @@
# 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 system_setup.common.helpers import is_reconfigure
from subiquity.server.server import SubiquityServer
from system_setup.models.system_setup import SystemSetupModel
from subiquity.models.subiquity import ModelNames
@ -51,6 +52,11 @@ class SystemSetupServer(SubiquityServer):
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):
root = '/'
if self.opts.dry_run:

View File

@ -95,12 +95,9 @@ class WSLConfigurationBaseView(BaseView):
excerpt = _(
"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.is_conf = variant == "wsl_configuration"
if self.is_conf:
self.title = _("WSL configuration - Base options")
initial = {
'custom_path': configuration_data.custom_path,
'custom_mount_opt': configuration_data.custom_mount_opt,