Makes the default_loader for wsl.conf testable

This commit is contained in:
Carlos Nihelton 2022-09-15 16:08:35 -03:00
parent 80869d23f2
commit b4734ad587
No known key found for this signature in database
GPG Key ID: 6FE346D245197E9A
4 changed files with 15 additions and 11 deletions

View File

@ -56,11 +56,11 @@ config_adv_default = {
}
conf_type_to_file = {
"wsl": "/etc/wsl.conf",
"wsl": "etc/wsl.conf",
}
def wsl_config_loader(config_ref, id):
def wsl_config_loader(pathname, config_ref, id):
"""
Loads the configuration from the given file type,
section and reference config.
@ -70,9 +70,6 @@ def wsl_config_loader(config_ref, id):
return the data loaded
"""
data = {}
pathname = conf_type_to_file[id]
if not os.path.exists(pathname):
return data
config = ConfigParser()
config.read(pathname)
for conf_sec in config:
@ -97,15 +94,19 @@ def wsl_config_loader(config_ref, id):
return data
def default_loader(is_advanced=False):
def default_loader(root_dir, is_advanced=False):
"""
This will load the default WSL config for the given type.
:param is_advanced: boolean, True if it is WSLConfigurationAdvanced,
else is WSLConfigurationBase
"""
id = "wsl"
pathname = os.path.join(root_dir, conf_type_to_file[id])
if not os.path.exists(pathname):
return {}
conf_ref = config_adv_default if is_advanced else config_base_default
data = wsl_config_loader(conf_ref, "wsl")
data = wsl_config_loader(pathname, conf_ref, id)
return data
@ -134,7 +135,7 @@ def wsl_config_update(config_class, root_dir):
config.BasicInterpolation = None
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:])
conf_file = os.path.join(root_dir, conf_type_to_file[config_type])
config.read(conf_file)

View File

@ -49,7 +49,8 @@ class WSLConfigurationAdvancedController(SubiquityController):
super().__init__(app)
# load the config file
data = default_loader(is_advanced=True)
root_dir = self.app.base_model.root
data = default_loader(root_dir, is_advanced=True)
if data:
proc_data = \

View File

@ -48,7 +48,8 @@ class WSLConfigurationBaseController(SubiquityController):
super().__init__(app)
# load the config file
data = default_loader()
root_dir = self.app.base_model.root
data = default_loader(root_dir)
if data:
proc_data = \

View File

@ -45,7 +45,8 @@ class WSLSetupOptionsController(SubiquityController):
super().__init__(app)
# load the config file
data = default_loader()
root_dir = self.app.base_model.root
data = default_loader(root_dir)
conf_data = WSLSetupOptions()
if data: