Skip to content

Commit

Permalink
Create non-root user in jeos-firstboot wizard
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
mloviska committed Aug 15, 2024
1 parent cdfd608 commit 011963f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
65 changes: 56 additions & 9 deletions tests/jeos/firstrun.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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");
Expand Down
1 change: 1 addition & 0 deletions variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 011963f

Please sign in to comment.