From 011963f991e4f090f39a71a8d0788729c9553e49 Mon Sep 17 00:00:00 2001 From: mloviska Date: Wed, 14 Aug 2024 10:14:49 +0200 Subject: [PATCH] Create non-root user in jeos-firstboot wizard A new feature has been implemented and jeos-firstboot wizard can create a non root user directly in the UI. As of now the feature has landed in sle-micro 6.1 only. If `WIZARD_SKIP_USER` test variable is set, the user creation in UI will be skipped. - ticket: [test fails in firstrun - handle non-root user creation screen](https://progress.opensuse.org/issues/165180) --- tests/jeos/firstrun.pm | 65 ++++++++++++++++++++++++++++++++++++------ variables.md | 1 + 2 files changed, 57 insertions(+), 9 deletions(-) diff --git a/tests/jeos/firstrun.pm b/tests/jeos/firstrun.pm index 0a52b04f400f..6c72eb6c1a1e 100644 --- a/tests/jeos/firstrun.pm +++ b/tests/jeos/firstrun.pm @@ -20,6 +20,7 @@ use jeos qw(expect_mount_by_uuid); use utils qw(assert_screen_with_soft_timeout ensure_serialdev_permissions); use serial_terminal 'prepare_serial_console'; +my $user_created = 0; sub post_fail_hook { assert_script_run('timedatectl'); @@ -114,6 +115,54 @@ sub verify_partition_label { script_output('sfdisk -l') =~ m/Disklabel type:\s+$label/ or die "Wrong partion label found, expected '$label'"; } +sub create_user_in_terminal { + if ($user_created) { + record_info('user', sprintf("%s has already been created", script_output("getent passwd $username"))); + return; + } + + assert_script_run "useradd -m $username -c '$realname'"; + assert_script_run "echo $username:$password | chpasswd"; + + $user_created = 1; +} + +sub enter_root_passwd { + foreach my $password_needle (qw(jeos-root-password jeos-confirm-root-password)) { + assert_screen $password_needle; + type_password; + send_key 'ret'; + } +} + +sub create_user_in_ui { + assert_screen 'jeos-create-non-root'; + + if (get_var('WIZARD_SKIP_USER', 0)) { + record_info('skip user', 'skipping user creation in wizard'); + for (1 .. 2) { + wait_screen_change(sub { + send_key 'tab'; + }, 10); + } + send_key 'ret'; + return; + } + + assert_screen_change { type_string $username }; + send_key "down"; + assert_screen_change { type_string $realname }; + assert_screen 'jeos-create-non-root-check'; + send_key "down"; + + type_password; + wait_screen_change(sub { send_key "down" }, 25); + type_password; + send_key 'ret'; + + $user_created = 1; +} + sub run { my ($self) = @_; my $lang = is_sle('15+') ? 'en_US' : get_var('JEOSINSTLANG', 'en_US'); @@ -187,11 +236,7 @@ sub run { send_key 'ret'; # Enter password & Confirm - foreach my $password_needle (qw(jeos-root-password jeos-confirm-root-password)) { - assert_screen $password_needle; - type_password; - send_key 'ret'; - } + enter_root_passwd; if (is_bootloader_sdboot) { send_key_until_needlematch 'jeos-fde-option-enroll-root-pw', 'down' unless check_screen('jeos-fde-option-enroll-root-pw', 1); @@ -234,6 +279,10 @@ sub run { send_key 'n'; } + if ((is_tumbleweed && check_var('STAGING', 'K')) || is_sle_micro('>6.0')) { + create_user_in_ui(); + } + if (is_generalhw && is_aarch64 && !is_leap("<15.4") && !is_tumbleweed) { assert_screen 'jeos-please-configure-wifi'; send_key 'n'; @@ -296,10 +345,8 @@ sub run { # Create user account, if image doesn't already contain user # (which is the case for SLE images that were already prepared by openQA) - if (script_run("getent passwd $username") != 0) { - assert_script_run "useradd -m $username -c '$realname'"; - assert_script_run "echo $username:$password | chpasswd"; - } + # new jeos-firstboot supports non-root user creation + create_user_in_terminal; if (check_var('FLAVOR', 'JeOS-for-RaspberryPi')) { assert_script_run("echo 'PermitRootLogin yes' > /etc/ssh/sshd_config.d/permit-root-login.conf"); diff --git a/variables.md b/variables.md index 957f7e2cb020..72a3cc41a99e 100644 --- a/variables.md +++ b/variables.md @@ -224,6 +224,7 @@ VIDEOMODE | string | | Indicates/defines video mode used for the installation. E VIRSH_OPENQA_BASEDIR | string | /var/lib | The OPENQA_BASEDIR configured on the svirt host (only relevant for the svirt backend). UNENCRYPTED_BOOT | boolean | false | Indicates/defines existence of unencrypted boot partition in the SUT. WAYLAND | boolean | false | Enables wayland tests in the system. +WIZARD_SKIP_USER | boolean | false | Skip non-root user creation in jeos-firstboot. This feature was added from sle-micro 6.1 XDMUSED | boolean | false | Indicates availability of xdm. XFS_MKFS_OPTIONS | string | | Define additional mkfs parameters. Used only in publiccloud test runs. XFS_TEST_DEVICE | string | | Define the device used for xfs tests. Used only in publiccloud test runs.