-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MicroOS: Add basic tests for Toolbox #12038
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# SUSE's openQA tests | ||
# | ||
# Copyright © 2021 SUSE LLC | ||
# | ||
# Copying and distribution of this file, with or without modification, | ||
# are permitted in any medium without royalty provided the copyright | ||
# notice and this notice are preserved. This file is offered as-is, | ||
# without any warranty. | ||
|
||
# Summary: Run simple toolbox tests | ||
# Maintainer: Jose Lausuch <[email protected]> | ||
|
||
use base "opensusebasetest"; | ||
use strict; | ||
use warnings; | ||
use testapi; | ||
use containers::common; | ||
use version_utils 'is_sle_micro'; | ||
|
||
our $user = 'test_user'; | ||
|
||
sub cleanup { | ||
record_info 'Cleanup'; | ||
clean_container_host(runtime => 'podman'); | ||
script_run "userdel -rf $user"; # script_run in case user has not been created yet | ||
} | ||
|
||
sub run { | ||
my ($self) = @_; | ||
$self->select_serial_terminal; | ||
|
||
# Create user and don't ask password for sudo commands | ||
jlausuch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert_script_run "useradd -m $user "; | ||
assert_script_run "echo \"$user ALL=(ALL) NOPASSWD:ALL\" >> /etc/sudoers"; | ||
|
||
# Display help | ||
assert_script_run 'toolbox -h'; | ||
|
||
record_info 'Test', "Run toolbox without flags"; | ||
assert_script_run 'toolbox -r id', timeout => 180; | ||
validate_script_output 'podman ps -a', sub { m/toolbox-root/ }; | ||
assert_script_run 'podman rm toolbox-root'; | ||
|
||
record_info 'Test', "Run toolbox with a given tag"; | ||
assert_script_run 'toolbox -t test_tag id', timeout => 180; | ||
validate_script_output 'podman ps -a', sub { m/toolbox-root-test_tag/ }; | ||
assert_script_run 'podman rm toolbox-root-test_tag'; | ||
|
||
record_info 'Test', "Run toolbox with a given name"; | ||
assert_script_run('toolbox -c test_name id'); | ||
validate_script_output 'podman ps -a', sub { m/test_name/ }; | ||
assert_script_run 'podman rm test_name'; | ||
|
||
|
||
record_info 'Test', "Rootless toolbox as $user"; | ||
my $prefix = "runuser -l $user -c"; | ||
my $uid = script_output "$prefix 'id -u'"; | ||
validate_script_output "$prefix 'toolbox -u id'", sub { m/uid=${uid}\(${user}\)/ }, timeout => 180; | ||
die "$user shouldn't have access to /etc/passwd!" if (script_run("$prefix 'toolbox -u touch /etc/passwd'") == 0); | ||
assert_script_run "$prefix \"podman rm toolbox-$user-user\""; | ||
|
||
record_info 'Test', "Rootfull toolbox as $user"; | ||
validate_script_output "$prefix 'toolbox -r id'", sub { m/uid=0\(root\)/ }; | ||
assert_script_run "$prefix 'toolbox -r touch /etc/passwd'", fail_message => 'Root should have access to /etc/passwd!'; | ||
assert_script_run "podman rm toolbox-$user"; | ||
|
||
|
||
record_info 'Test', 'Pulling toolbox image from different registry'; | ||
# Switch default registries for openSUSE MicroOS and SLE Micro | ||
if (is_sle_micro) { | ||
assert_script_run 'echo -e "REGISTRY=registry.opensuse.org\nIMAGE=opensuse/toolbox" > ~/.toolboxrc'; | ||
validate_script_output 'toolbox -r cat /etc/os-release', sub { m/opensuse/ }, timeout => 180; | ||
} else { | ||
assert_script_run 'echo -e "REGISTRY=registry.suse.com\nIMAGE=suse/sle-micro/5.0/toolbox" > ~/.toolboxrc'; | ||
validate_script_output 'toolbox -r cat /etc/os-release', sub { m/sles/ }, timeout => 180; | ||
} | ||
assert_script_run 'podman rm toolbox-root'; | ||
assert_script_run 'rm ~/.toolboxrc'; | ||
|
||
record_info 'Test', 'Zypper tests'; | ||
assert_script_run 'toolbox create -r -c devel'; | ||
if (!validate_script_output 'toolbox list', sub { m/devel/ }, timeout => 180, proceed_on_failure => 1) { | ||
record_info('ISSUE', 'https://github.com/kubic-project/microos-toolbox/issues/23'); | ||
} | ||
script_run 'toolbox run -c devel -- zypper lr'; # this command will fail in SLE Micro toolbox as there are no repos | ||
assert_script_run 'toolbox run -c devel -- zypper -n in python3' unless is_sle_micro; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are you testing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just followed the same thing we do in container tests. But you are right, we could just tests something more meaningful for a toolbox use case (htop, nmap, ...) |
||
assert_script_run 'podman rm devel'; | ||
|
||
cleanup; | ||
} | ||
|
||
sub post_fail_hook { | ||
cleanup; | ||
} | ||
|
||
1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it duplication of https://github.com/os-autoinst/os-autoinst-distri-opensuse/blob/master/lib/containers/common.pm#L128 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, I can call
clean_container_host
from here but I need to keepuserdel -rf $user
anyways.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 options possible and I don't have strong opinion which one is better here ... :
containers/common.pm
here to avoid duplication with podman part of cleanupif
's incontainers/common.pm
and merge altogethereach choice has down and up sides so I am not sure ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option 2 for now :)