From 07b0407815fab35ded6f54ff444cd109fd19192d Mon Sep 17 00:00:00 2001 From: Patrick Wu Date: Wed, 6 Oct 2021 23:00:06 +0800 Subject: [PATCH] system_setup: refactor the testing system 1. updating testing system with the proper autoinstall schema 2. reconf mode testing included --- ...up.yaml => answers-system-setup-init.yaml} | 0 examples/answers-system-setup-reconf.yaml | 18 ++++++++++++++ examples/autoinstall-system-setup.yaml | 11 +++++++++ scripts/runtests.sh | 24 +++++++++++++++---- system_setup/common/wsl_conf.py | 11 +++++++++ .../golden/answers-reconf/ubuntu-wsl.conf | 12 ++++++++++ .../tests/golden/answers-reconf/wsl.conf | 14 +++++++++++ system_setup/tests/golden/answers/wsl.conf | 8 +++++++ .../tests/golden/autoinstall/wsl.conf | 8 +++++++ 9 files changed, 102 insertions(+), 4 deletions(-) rename examples/{answers-system-setup.yaml => answers-system-setup-init.yaml} (100%) create mode 100644 examples/answers-system-setup-reconf.yaml create mode 100644 system_setup/tests/golden/answers-reconf/ubuntu-wsl.conf create mode 100644 system_setup/tests/golden/answers-reconf/wsl.conf create mode 100644 system_setup/tests/golden/answers/wsl.conf create mode 100644 system_setup/tests/golden/autoinstall/wsl.conf diff --git a/examples/answers-system-setup.yaml b/examples/answers-system-setup-init.yaml similarity index 100% rename from examples/answers-system-setup.yaml rename to examples/answers-system-setup-init.yaml diff --git a/examples/answers-system-setup-reconf.yaml b/examples/answers-system-setup-reconf.yaml new file mode 100644 index 00000000..94a7d068 --- /dev/null +++ b/examples/answers-system-setup-reconf.yaml @@ -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 \ No newline at end of file diff --git a/examples/autoinstall-system-setup.yaml b/examples/autoinstall-system-setup.yaml index a3f1db74..7256a515 100644 --- a/examples/autoinstall-system-setup.yaml +++ b/examples/autoinstall-system-setup.yaml @@ -14,4 +14,15 @@ wslconfbase: automount_options: 'metadata' network_generatehosts: 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' \ No newline at end of file diff --git a/scripts/runtests.sh b/scripts/runtests.sh index bad3c5ff..9ea2cc51 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -22,8 +22,15 @@ validate () { fi netplan generate --root .subiquity elif [ "${mode}" = "system_setup" ]; then - # TODO WSL: Compare generated wsl.conf to oracle - echo "system setup validation" + setup_mode="$2" + 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 echo "W: Unknown validation mode: ${mode}" fi @@ -34,6 +41,7 @@ clean () { rm -f .subiquity/subiquity-*.log rm -f "$testschema" rm -rf .subiquity/run/ + rm -rf .subiquity/etc/*.conf rm -rf .subiquity/etc/cloud/cloud.cfg.d/99-installer.cfg } @@ -66,8 +74,15 @@ for answers in examples/answers*.yaml; do else # The OOBE doesn't exist in WSL < 20.04 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 - validate "system_setup" + # check if it is reconf + 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 done @@ -105,6 +120,7 @@ if [ "${RELEASE%.*}" -ge 20 ]; then # Like generating a wsl.conf file and comparing it to the oracle. clean 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" scripts/schema-cmp.py "autoinstall-system-setup-schema.json" "$testschema" --ignore-tz diff --git a/system_setup/common/wsl_conf.py b/system_setup/common/wsl_conf.py index bd2eeab8..341c8aca 100644 --- a/system_setup/common/wsl_conf.py +++ b/system_setup/common/wsl_conf.py @@ -17,6 +17,7 @@ # original code from ubuntuwslctl.core.loader # Copyright (C) 2021 Canonical Ltd. +import collections import os import logging from configparser import ConfigParser @@ -161,6 +162,16 @@ def wsl_config_update(config_class, root_dir): config.add_section(config_section) 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: config.write(configfile) diff --git a/system_setup/tests/golden/answers-reconf/ubuntu-wsl.conf b/system_setup/tests/golden/answers-reconf/ubuntu-wsl.conf new file mode 100644 index 00000000..a9de1305 --- /dev/null +++ b/system_setup/tests/golden/answers-reconf/ubuntu-wsl.conf @@ -0,0 +1,12 @@ +[GUI] +followwintheme = true +theme = light + +[Interop] +advancedipdetection = true +audiointegration = true +guiintegration = true + +[Motd] +wslnewsenabled = false + diff --git a/system_setup/tests/golden/answers-reconf/wsl.conf b/system_setup/tests/golden/answers-reconf/wsl.conf new file mode 100644 index 00000000..449819ba --- /dev/null +++ b/system_setup/tests/golden/answers-reconf/wsl.conf @@ -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 + diff --git a/system_setup/tests/golden/answers/wsl.conf b/system_setup/tests/golden/answers/wsl.conf new file mode 100644 index 00000000..a4a69cfe --- /dev/null +++ b/system_setup/tests/golden/answers/wsl.conf @@ -0,0 +1,8 @@ +[automount] +options = metadata +root = /custom_mnt_path + +[network] +generatehosts = false +generateresolvconf = false + diff --git a/system_setup/tests/golden/autoinstall/wsl.conf b/system_setup/tests/golden/autoinstall/wsl.conf new file mode 100644 index 00000000..a4a69cfe --- /dev/null +++ b/system_setup/tests/golden/autoinstall/wsl.conf @@ -0,0 +1,8 @@ +[automount] +options = metadata +root = /custom_mnt_path + +[network] +generatehosts = false +generateresolvconf = false +