Skip to content

Commit

Permalink
Improve WSL system prep and install
Browse files Browse the repository at this point in the history
As the enable WSL method has become obsolete and is causing some issues, we've decided to change the way how WSL is installed in the system. Also, to optimize the process, we will create a qcow image with WSL already enabled to save redundant test time
  • Loading branch information
Pablo Herranz Ramírez committed Nov 20, 2023
1 parent 8f86a67 commit 474df6e
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 267 deletions.
18 changes: 18 additions & 0 deletions lib/windowsbasetest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,22 @@ sub install_wsl2_kernel {
);
}

sub power_configuration {
my $self = shift;

# turn off hibernation and fast startup
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' -Name HiberbootEnabled -Value 0}
);
$self->run_in_powershell(cmd => 'powercfg /hibernate off');

# disable screen's fade to black
$self->run_in_powershell(cmd => 'powercfg -change -monitor-timeout-ac 0');

# adjust visual effects to best performance
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects' -Name VisualFXSetting -Value 2}
);
}

1;
11 changes: 2 additions & 9 deletions schedule/wsl/wsl_main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,9 @@ name: wsl_main.yaml
description: >
WSL smoke test on Windows 10 image
conditional_schedule:
install_WSL:
WSL_INSTALL_FROM:
'msstore':
- wsl/install_from_MSStore
'build':
- wsl/prepare_wsl_feature

schedule:
- wsl/boot_windows
- '{{install_WSL}}'
- wsl/prepare_wsl
- wsl/install_wsl
- wsl/firstrun
- wsl/wsl_cmd_check
18 changes: 15 additions & 3 deletions tests/wsl/firstrun.pm
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,12 @@ sub run {
assert_screen [qw(yast2-wsl-firstboot-welcome wsl-installing-prompt)], 480;

if (match_has_tag 'yast2-wsl-firstboot-welcome') {
assert_and_click 'window-max';
# The new process of installing, appears in an already maximized window,
# but sometimes it loses focus. So I created another needle to check if
# the window is already maximized and click somewhere else to bring it to focus.
assert_screen(['window-max', 'window-minimize']);
assert_and_click 'window-max' if match_has_tag 'window-max';
assert_and_click 'window-minimize' if match_has_tag 'window-minimize';
wait_still_screen stilltime => 3, timeout => 10;
is_fake_scc_url_needed && set_fake_scc_url();
send_key 'alt-n';
Expand All @@ -136,8 +141,15 @@ sub run {
# SLED Workstation license agreement
license if (check_var('SLE_PRODUCT', 'sled'));
# And done!
assert_screen ['trust_nvidia_gpg_keys', 'wsl-installation-completed'], timeout => 240;
send_key 'alt-t' if (match_has_tag 'trust_nvidia_gpg_keys');

# This is an ongoing discussion and it seems that the screen only appears
# during the "development period". Also, it looks like that code was
# duplicated in L98 of this file. Didn't want to remove it completely
# just in case it returns...

# assert_screen ['trust_nvidia_gpg_keys', 'wsl-installation-completed'], timeout => 240;
# send_key 'alt-t' if (match_has_tag 'trust_nvidia_gpg_keys');

assert_screen 'wsl-installation-completed', 240;
send_key 'alt-f';
# Back to CLI
Expand Down
14 changes: 1 addition & 13 deletions tests/wsl/install/ms_win_firstboot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,7 @@ sub run {
assert_and_click 'windows-select-picture';

# turn off hibernation and fast startup
$self->open_powershell_as_admin;
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Power' -Name HiberbootEnabled -Value 0}
);
$self->run_in_powershell(cmd => 'powercfg /hibernate off');

# disable screen's fade to black
$self->run_in_powershell(cmd => 'powercfg -change -monitor-timeout-ac 0');

# adjust visusal effects to best performance
$self->run_in_powershell(cmd =>
q{Set-ItemProperty -Path 'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VisualEffects' -Name VisualFXSetting -Value 2}
);
$self->power_configuration;

# remove skype and xbox
$self->run_in_powershell(cmd =>
Expand Down
102 changes: 0 additions & 102 deletions tests/wsl/install_from_MSStore.pm

This file was deleted.

92 changes: 92 additions & 0 deletions tests/wsl/install_wsl.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# SUSE's openQA tests
#
# Copyright 2022 SUSE LLC
# SPDX-License-Identifier: FSFAP

# Summary: Install SUSE or openSUSE WSL images from the MS Store directly
# Maintainer: qa-c <[email protected]>

use Mojo::Base "windowsbasetest";
use testapi;
use version_utils;
use Utils::Architectures 'is_aarch64';

sub install_certificates {
my ($self) = @_;
my $certs = {
opensuse => 'wsl/openSUSE-UEFI-CA-Certificate.crt',
sle => 'wsl/SLES-UEFI-CA-Certificate.crt'
};
my $ms_cert_store = 'cert:\\LocalMachine\\Root';
my $cert_file_path = 'C:\Users\Public\image-ca.cert';
# The certificates should be downloaded from the web
$self->run_in_powershell(
cmd => 'Invoke-WebRequest -Uri "' . data_url($certs->{get_required_var('DISTRI')}) . '" -O "' . $cert_file_path . '" -UseBasicParsing',
);
$self->run_in_powershell(
cmd => 'Import-Certificate -FilePath "' . $cert_file_path . '" -CertStoreLocation ' . $ms_cert_store . ' -Verbose',
timeout => 120
);
}

sub run {
my ($self) = @_;
assert_screen 'windows-desktop';

$self->open_powershell_as_admin;
# Set the version for WSL1
$self->run_in_powershell(
cmd => 'wsl --set-default-version 1',
timeout => 30
) unless (get_var('WSL2'));

my $WSL_version = '';
if (is_sle('<=15-sp4')) {
$WSL_version = "SUSE-Linux-Enterprise-Server-" . get_required_var("VERSION");
} elsif (is_sle('>=15-sp5')) {
$WSL_version = "SUSE-Linux-Enterprise-" . get_required_var("VERSION");
} elsif (is_leap) {
$WSL_version = "openSUSE-Leap-" . get_required_var("VERSION");
} else {
$WSL_version = "openSUSE-Tumbleweed";
}
my $install_from = get_required_var('WSL_INSTALL_FROM');
if ($install_from eq 'build') {
my $wsl_appx_filename = (split /\//, get_required_var('ASSET_1'))[-1];
my $wsl_appx_uri = "\\\\10.0.2.4\\qemu\\$wsl_appx_filename";
# Enable the 'developer mode' in Windows
$self->run_in_powershell(
cmd => 'New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock" -Name AllowDevelopmentWithoutDevLicense -PropertyType DWORD -Value 1'
);
# On Win 11 for Arm Build 25931, smb transfers don't work (poo#126083)
$wsl_appx_uri = data_url('ASSET_1') if is_aarch64;
$self->run_in_powershell(
cmd => "Start-BitsTransfer -Source $wsl_appx_uri -Destination C:\\\\$wsl_appx_filename",
timeout => 60
);

$self->install_certificates;

$self->run_in_powershell(
cmd => "Add-AppxPackage -Path C:\\$wsl_appx_filename",
timeout => 60
);
record_info 'Port close', 'Closing serial port...';
$self->run_in_powershell(cmd => '$port.close()', code => sub { });
$self->run_in_powershell(cmd => 'exit', code => sub { });
$self->use_search_feature($WSL_version);
assert_and_click 'wsl-suse-startup-search';
} elsif ($install_from eq 'msstore') {
# Install required SUSE distro from the MS Store
$self->run_in_powershell(
cmd => "wsl --install --distribution $WSL_version",
code => sub {
assert_screen("yast2-wsl-firstboot-welcome", timeout => 300);
}
);
} else {
die("The value entered for WSL_INSTALL_FROM is not 'build' neither 'msstore'");
}
}

1;
60 changes: 60 additions & 0 deletions tests/wsl/prepare_wsl.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# SUSE's openQA tests
#
# Copyright 2012-2019 SUSE LLC
# SPDX-License-Identifier: FSFAP
#
# Summary: Configure windows 10 to host WSL image
# Currently we have self signed images as sle12sp5 and leap
# tumbleweed and sle15sp2 or higher contain a chain of certificates
# In case of chain certificates, store only CA certificate
# 1) Download the image and CA cert if any
# 2) Enable developer mode Import certificates
# 3) Import downloaded or embedded certificate
# 4) Enable WSL feature
# 5) Reboot
# 6) Install WSL image
# Maintainer: qa-c <[email protected]>

use Mojo::Base qw(windowsbasetest);
use Utils::Architectures qw(is_aarch64);
use testapi;
use version_utils qw(is_sle is_opensuse);

sub run {
my ($self) = @_;

$self->open_powershell_as_admin;

$self->power_configuration if (is_aarch64);

if (get_var('WSL2')) {
# WSL2 platform must be enabled from the MSstore from now on
$self->run_in_powershell(
cmd => "wsl --install --no-distribution",
code => sub {
unless (is_aarch64) {
assert_screen(["windows-user-account-ctl-hidden", "windows-user-acount-ctl-allow-make-changes"], 240);
assert_and_click "windows-user-account-ctl-hidden" if match_has_tag("windows-user-account-ctl-hidden");
assert_and_click "windows-user-acount-ctl-yes";
}
assert_screen("windows-wsl-cli-install-finished", timeout => 900);
}
);
# Disable HyperV in WSL2
$self->run_in_powershell(
cmd => 'Disable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V-Hypervisor -NoRestart',
timeout => 60
);
} else {
# WSL1 will still be enabled in the legacy mode
$self->run_in_powershell(
cmd => 'Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux -NoRestart',
timeout => 300
);
}

$self->reboot_or_shutdown(is_reboot => 1);
$self->wait_boot_windows;
}

1;
Loading

0 comments on commit 474df6e

Please sign in to comment.