Merge pull request #1074 from canonical/wsl_oobe_conf_calls_tmp_files

DEENG-40 - Write wsl.conf and other files in dry-run mode to .subiquity/
This commit is contained in:
Didier Roche 2021-10-07 10:44:33 +02:00 committed by GitHub
commit 58a78c0506
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 10 deletions

View File

@ -110,16 +110,13 @@ def default_loader(is_advanced=False):
return data return data
# TODO: remove dryrun and add root param once we write the option to .subiquity def wsl_config_update(config_class, root_dir):
def wsl_config_update(config_class, is_dry_run):
""" """
This update the configuration file for the given class.zzd This update the configuration file for the given class.zzd
:param config_class: WSLConfigurationBase or WSLConfigurationAdvanced :param config_class: WSLConfigurationBase or WSLConfigurationAdvanced
:param is_dry_run: boolean, True if it is a dry run :param is_dry_run: boolean, True if it is a dry run
""" """
if is_dry_run:
log.debug("mimicking setting config %s", config_class)
temp_conf_default = {} temp_conf_default = {}
temp_confname = config_class.__str__() temp_confname = config_class.__str__()
if temp_confname.startswith("WSLConfigurationBase"): if temp_confname.startswith("WSLConfigurationBase"):
@ -128,8 +125,6 @@ def wsl_config_update(config_class, is_dry_run):
temp_conf_default = config_adv_default temp_conf_default = config_adv_default
else: else:
raise TypeError("Invalid type name.") raise TypeError("Invalid type name.")
if is_dry_run:
return
# update the config file # update the config file
for config_type in temp_conf_default: for config_type in temp_conf_default:
@ -138,7 +133,8 @@ def wsl_config_update(config_class, is_dry_run):
config = ConfigParser() config = ConfigParser()
config.BasicInterpolcation = None config.BasicInterpolcation = None
conf_file = conf_type_to_file[config_type] os.makedirs(os.path.join(root_dir, "etc"), exist_ok=True)
conf_file = os.path.join(root_dir, conf_type_to_file[config_type][1:])
config.read(conf_file) config.read(conf_file)
@ -149,7 +145,7 @@ def wsl_config_update(config_class, is_dry_run):
config_api_name = \ config_api_name = \
config_section.lower() + "_" + config_setting.lower() config_section.lower() + "_" + config_setting.lower()
config_value = config_class.__dict__[config_api_name] config_value = config_class.__dict__[config_api_name]
# if the value for the setting is defualt value, drop it # if the value for the setting is default value, drop it
if config_default_value == config_value: if config_default_value == config_value:
if config_setting in config[config_section]: if config_setting in config[config_section]:
config.remove_option(config_section, config_setting) config.remove_option(config_section, config_setting)

View File

@ -68,6 +68,7 @@ class ConfigureController(SubiquityController):
dryrun = self.app.opts.dry_run dryrun = self.app.opts.dry_run
variant = self.app.variant variant = self.app.variant
root_dir = self.model.root
if variant == "wsl_setup": if variant == "wsl_setup":
wsl_id = self.model.identity.user wsl_id = self.model.identity.user
if dryrun: if dryrun:
@ -96,9 +97,9 @@ class ConfigureController(SubiquityController):
assign_grp_act.stderr)) assign_grp_act.stderr))
else: else:
wsl_config_update(self.model.wslconfadvanced.wslconfadvanced, wsl_config_update(self.model.wslconfadvanced.wslconfadvanced,
dryrun) root_dir)
wsl_config_update(self.model.wslconfbase.wslconfbase, dryrun) wsl_config_update(self.model.wslconfbase.wslconfbase, root_dir)
self.app.update_state(ApplicationState.DONE) self.app.update_state(ApplicationState.DONE)
except Exception: except Exception: