system_setup: shutdown/reboot tests

This commit is contained in:
Patrick Wu 2021-10-15 16:29:35 +08:00
parent 3c32cb773c
commit ec04a6833a
No known key found for this signature in database
GPG Key ID: 9DD33DF28FC324F1
4 changed files with 44 additions and 8 deletions

View File

@ -25,4 +25,4 @@ wslconfadvanced:
motd_wslnewsenabled: false
automount_enabled: false
automount_mountfstab: false
shutdown: 'reboot'
shutdown: 'poweroff'

View File

@ -0,0 +1,16 @@
version: 1
early-commands:
- echo a
- ["sleep", "1"]
- echo a
locale: en_US
identity:
realname: Ubuntu
username: ubuntu
# ubuntu
password: '$6$wdAcoXrU039hKYPd$508Qvbe7ObUnxoj15DRCkzC3qO7edjH0VV7BPNRDYK4QR8ofJaEEF2heacn0QgD.f8pO8SNp83XNdWG6tocBM1'
wslconfbase:
automount_root: '/custom_mnt_path'
automount_options: 'metadata'
network_generatehosts: false
network_generateresolvconf: false

View File

@ -29,7 +29,23 @@ validate () {
elif [ "${mode}" = "system_setup" ]; then
setup_mode="$2"
echo "system setup validation for $setup_mode"
[ -d ".subiquity/run/subiquity/" ] || (echo "run/subiquity/ dir not created for status"; exit 1)
[ -e ".subiquity/run/subiquity/launcher-status" ] || (echo "run/subiquity/launcher-status not created"; exit 1)
expected_status="reboot"
if [ "${setup_mode}" = "autoinstall-full" ]; then
expected_status="shutdown"
elif [ "${setup_mode}" = "autoinstall-no-shutdown" ]; then
expected_status="complete"
fi
result_status="$(cat .subiquity/run/subiquity/launcher-status)"
if [ "${result_status}" != "${expected_status}" ]; then
echo "incorrect run/subiquity/launcher-status: expect ${expected_status}, got ${result_status}"
exit 1
fi
[ -d ".subiquity/etc/" ] || (echo "etc/ dir not created for config"; exit 1)
if [ "${setup_mode}" = "autoinstall-no-shutdown" ]; then
setup_mode="autoinstall"
fi
[ -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})
@ -121,13 +137,11 @@ grep -q 'finish: subiquity/Install/install/postinstall/run_unattended_upgrades:
# The OOBE doesn't exist in WSL < 20.04
if [ "${RELEASE%.*}" -ge 20 ]; then
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"
clean
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --autoinstall examples/autoinstall-system-setup-full.yaml --dry-run"
validate "system_setup" "autoinstall-full"
for mode in "" "-full" "-no-shutdown"; do
clean
timeout --foreground 60 sh -c "LANG=C.UTF-8 python3 -m system_setup.cmd.tui --autoinstall examples/autoinstall-system-setup${mode}.yaml --dry-run"
validate "system_setup" "autoinstall${mode}"
done
python3 -m system_setup.cmd.schema > "$testschema"
scripts/schema-cmp.py "autoinstall-system-setup-schema.json" "$testschema" --ignore-tz

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/>.
import enum
import os
import logging
@ -23,6 +24,10 @@ from subiquity.server.controllers import ShutdownController
log = logging.getLogger("system_setup.server.controllers.restart")
class WSLShutdownMode(enum.Enum):
COMPLETE = -1
class SetupShutdownController(ShutdownController):
def __init__(self, app):
@ -31,6 +36,7 @@ class SetupShutdownController(ShutdownController):
super().__init__(app)
self.root_dir = app.base_model.root
self.app.controllers.Install = self.app.controllers.Configure
self.mode = WSLShutdownMode.COMPLETE # allow the complete mode
def start(self):
self.app.aio_loop.create_task(self._wait_install())