Skip to content
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

Merged
merged 1 commit into from
Mar 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions products/microos/main.pm
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sub load_feature_tests {
loadtest 'console/kubeadm';
}
elsif (check_var 'SYSTEM_ROLE', 'container-host') {
loadtest 'microos/toolbox';
loadtest 'containers/podman';
loadtest 'containers/podman_image';
}
Expand Down
1 change: 1 addition & 0 deletions schedule/sle-micro/containers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ description: >
schedule:
- microos/disk_boot
- console/suseconnect_scc
- microos/toolbox
- containers/containers_3rd_party
- containers/podman
- containers/podman_image
96 changes: 96 additions & 0 deletions tests/microos/toolbox.pm
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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 keep userdel -rf $user anyways.

Copy link
Member

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 ... :

  1. leave things as it is right now .
  2. call cleanup from containers/common.pm here to avoid duplication with podman part of cleanup
  3. increase amount of if's in containers/common.pm and merge altogether

each choice has down and up sides so I am not sure ....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option 2 for now :)

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you testing zypper here ? than I would go for something less error prone and more stable to not dive into all surprises which python3 might bring ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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;