system_setup: refactor the testing system

1. updating testing system with the proper autoinstall schema
2. reconf mode testing included
This commit is contained in:
Patrick Wu 2021-10-06 23:00:06 +08:00
parent 8cf0b5350f
commit 07b0407815
No known key found for this signature in database
GPG Key ID: 9DD33DF28FC324F1
9 changed files with 102 additions and 4 deletions

View File

@ -0,0 +1,18 @@
WSLConfigurationBase:
automount_root: '/custom_mnt_path'
automount_options: 'metadata'
network_generatehosts: false
network_generateresolvconf: false
WSLConfigurationAdvanced:
interop_enabled: false
interop_appendwindowspath: false
gui_theme: 'light'
gui_followwintheme: true
interop_guiintegration: true
interop_audiointegration: true
interop_advancedipdetection: true
motd_wslnewsenabled: false
automount_enabled: false
automount_mountfstab: false
Summary:
reboot: yes

View File

@ -14,4 +14,15 @@ wslconfbase:
automount_options: 'metadata' automount_options: 'metadata'
network_generatehosts: false network_generatehosts: false
network_generateresolvconf: false network_generateresolvconf: false
wslconfadvanced:
interop_enabled: false
interop_appendwindowspath: false
gui_theme: 'light'
gui_followwintheme: true
interop_guiintegration: true
interop_audiointegration: true
interop_advancedipdetection: true
motd_wslnewsenabled: false
automount_enabled: false
automount_mountfstab: false
shutdown: 'reboot' shutdown: 'reboot'

View File

@ -22,8 +22,15 @@ validate () {
fi fi
netplan generate --root .subiquity netplan generate --root .subiquity
elif [ "${mode}" = "system_setup" ]; then elif [ "${mode}" = "system_setup" ]; then
# TODO WSL: Compare generated wsl.conf to oracle setup_mode="$2"
echo "system setup validation" echo "system setup validation for $setup_mode"
[ -d ".subiquity/etc/" ] || (echo "etc/ dir not created for config"; exit 1)
[ -d "system_setup/tests/golden/${setup_mode}" ] || (echo "tests/golden not found in system_setup"; exit 1)
for file in system_setup/tests/golden/${setup_mode}/*.conf; do
filename=$(basename ${file})
conf_filepath=".subiquity/etc/${filename}"
diff -Nup "${file}" "${conf_filepath}" || exit 1
done
else else
echo "W: Unknown validation mode: ${mode}" echo "W: Unknown validation mode: ${mode}"
fi fi
@ -34,6 +41,7 @@ clean () {
rm -f .subiquity/subiquity-*.log rm -f .subiquity/subiquity-*.log
rm -f "$testschema" rm -f "$testschema"
rm -rf .subiquity/run/ rm -rf .subiquity/run/
rm -rf .subiquity/etc/*.conf
rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg
} }
@ -66,8 +74,15 @@ for answers in examples/answers*.yaml; do
else else
# The OOBE doesn't exist in WSL < 20.04 # The OOBE doesn't exist in WSL < 20.04
if [ "${RELEASE%.*}" -ge 20 ]; then if [ "${RELEASE%.*}" -ge 20 ]; then
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --answers $answers --dry-run " < $tty # check if it is reconf
validate "system_setup" reconf_settings="false"
validate_subtype="answers"
if echo $answers|grep -q reconf; then
reconf_settings="true"
validate_subtype="answers-reconf"
fi
timeout --foreground 60 sh -c "DRYRUN_RECONFIG=$reconf_settings LANG=C.UTF-8 python3 -m system_setup.cmd.tui --answers $answers --dry-run " < $tty
validate "system_setup" "$validate_subtype"
fi fi
fi fi
done done
@ -105,6 +120,7 @@ if [ "${RELEASE%.*}" -ge 20 ]; then
# Like generating a wsl.conf file and comparing it to the oracle. # Like generating a wsl.conf file and comparing it to the oracle.
clean clean
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --autoinstall examples/autoinstall-system-setup.yaml --dry-run" timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --autoinstall examples/autoinstall-system-setup.yaml --dry-run"
validate "system_setup" "autoinstall"
python3 -m system_setup.cmd.schema > "$testschema" python3 -m system_setup.cmd.schema > "$testschema"
scripts/schema-cmp.py "autoinstall-system-setup-schema.json" "$testschema" --ignore-tz scripts/schema-cmp.py "autoinstall-system-setup-schema.json" "$testschema" --ignore-tz

View File

@ -17,6 +17,7 @@
# original code from ubuntuwslctl.core.loader # original code from ubuntuwslctl.core.loader
# Copyright (C) 2021 Canonical Ltd. # Copyright (C) 2021 Canonical Ltd.
import collections
import os import os
import logging import logging
from configparser import ConfigParser from configparser import ConfigParser
@ -161,6 +162,16 @@ def wsl_config_update(config_class, root_dir):
config.add_section(config_section) config.add_section(config_section)
config[config_section][config_setting] = config_value config[config_section][config_setting] = config_value
# sort config in ascii order
for section in config._sections:
config._sections[section] = \
collections.OrderedDict(
sorted(config._sections[section].items(),
key=lambda t: t[0]))
config._sections = \
collections.OrderedDict(sorted(config._sections.items(),
key=lambda t: t[0]))
with open(conf_file + ".new", 'w+') as configfile: with open(conf_file + ".new", 'w+') as configfile:
config.write(configfile) config.write(configfile)

View File

@ -0,0 +1,12 @@
[GUI]
followwintheme = true
theme = light
[Interop]
advancedipdetection = true
audiointegration = true
guiintegration = true
[Motd]
wslnewsenabled = false

View File

@ -0,0 +1,14 @@
[automount]
enabled = false
mountfstab = false
options = metadata
root = /custom_mnt_path
[interop]
appendwindowspath = false
enabled = false
[network]
generatehosts = false
generateresolvconf = false

View File

@ -0,0 +1,8 @@
[automount]
options = metadata
root = /custom_mnt_path
[network]
generatehosts = false
generateresolvconf = false

View File

@ -0,0 +1,8 @@
[automount]
options = metadata
root = /custom_mnt_path
[network]
generatehosts = false
generateresolvconf = false