1
0
mirror of https://pagure.io/fedora-qa/os-autoinst-distri-fedora.git synced 2024-11-22 05:53:09 +00:00

Rewrite Modularity tests to use Perl only.

The Modularity tests rely on an external script to test the modular
behaviour of DNF. There is a potentional risk that the connection
is be down and the script cannot be downloaded.

This enhancement uses a regular OpenQA perl test case script to only
invoke DNF commands and parse their output to test the same behaviour
that we have been testing already.

This enhancement picks a random module for each of the operations,
and thus tries to mimick reality a little bit more.
This commit is contained in:
Lukáš Růžička 2021-03-25 11:27:58 +01:00 committed by adamwill
parent 6c5507b174
commit 114610bf90
5 changed files with 166 additions and 30 deletions

46
lib/modularity.pm Normal file
View File

@ -0,0 +1,46 @@
package modularity;
use strict;
use base 'Exporter';
use Exporter;
use lockapi;
use testapi;
use utils;
our @EXPORT = qw(parse_module_list is_listed);
# This subroutine takes the output from the dnf module list command
# and deletes all unnecessary stuff and returns an array of hash
# references where each hash consists of (module, stream, profile).
# The subroutine only recognizes one profile but it is enough
# for the sake of the modularity testing.
sub parse_module_list {
my $output = shift;
my @output_lines = split(/\n/, $output);
my @parsed_list;
foreach my $line (@output_lines) {
my ($module, $stream, $profile) = split(/\s+/, $line);
unless ($module =~ /Fedora|Last|Hint|Name|^$/) {
$profile =~ s/,$//;
my %module = ("module" => $module, "stream" => $stream, "profile" => $profile);
push(@parsed_list, \%module);
}
}
return @parsed_list;
}
# This subroutine iterates over the given list of module hashes and returns True
# if it finds it in the list.
sub is_listed {
my ($module, $stream, $listref) = @_;
my $found = 0;
foreach (@{ $listref }) {
if ($_->{module} eq $module and $_->{stream} eq $stream) {
$found = 1;
}
}
return $found;
}

View File

@ -1,25 +1,72 @@
use base "installedtest";
use strict;
use modularity;
use testapi;
use utils;
sub run {
my $self=shift;
my $hook_run = 0;
# switch to tty and login as root
$self->root_console(tty=>3);
# Download the testing script
download_modularity_tests();
# Enable the module.
my $name = "swig";
my $stream = "4.0";
assert_script_run("dnf module enable -y $name:$stream");
# Check that modularity works, that a particular module is available in the system,
# and display information about that module.
assert_script_run('/root/test.py -m dwm -s 6.1 -a list');
# Check that it is listed in the enabled list.
my $enabled = script_output('dnf module list --enabled');
my @enabled_modules = parse_module_list($enabled);
unless (is_listed($name, $stream, \@enabled_modules)) {
die "The enabled module is not listed in the list of enabled modules but it should be.";
}
# Check that module can be enabled and disabled.
assert_script_run('/root/test.py -m dwm -s 6.1 -a enable,disable -f hard');
# Check that it is not listed in the disabled list.
my $disabled = script_output('dnf module list --disabled');
my @disabled_modules = parse_module_list($disabled);
if (is_listed($name, $stream, \@disabled_modules)) {
die "The enabled module is listed in the list of disabled modules but it should not be.";
}
# Disable some other module.
my $name_alt = "postgresql";
my $stream_alt = "13";
assert_script_run("dnf module disable -y $name_alt:$stream_alt");
# Check that it is listed in the disabled list.
$disabled = script_output('dnf module list --disabled');
@disabled_modules = parse_module_list($disabled);
unless (is_listed($name_alt, $stream_alt, \@disabled_modules)) {
die "The disabled module is not listed in the list of disabled modules but it should be.";
}
# Check that it is not listed in the enabled list.
$enabled = script_output('dnf module list --enabled');
@enabled_modules = parse_module_list($enabled);
if (is_listed($name_alt, $stream_alt, \@enabled_modules)) {
die "The disabled module is listed in the list of enabled modules but it should not be.";
}
# Reset the first module to its original state and do the list checks.
assert_script_run("dnf module reset -y $name");
# Check that the module has disappeared from both the lists.
$disabled = script_output('dnf module list --disabled');
@disabled_modules = parse_module_list($disabled);
if (is_listed($name, $stream, \@disabled_modules)) {
die "The disabled module is listed in the list of disabled modules but it should not be.";
}
$enabled = script_output('dnf module list --enabled');
@enabled_modules = parse_module_list($enabled);
if (is_listed($name, $stream, \@enabled_modules)) {
die "The disabled module is listed in the list of enabled modules but it should not be.";
}
# Reset the second module but do not perform any list checks.
assert_script_run("dnf module reset -y $name_alt");
# Upload the modular log file.
upload_logs '/root/modular.log', failok=>1;
}
1;

View File

@ -1,23 +1,46 @@
use base "installedtest";
use strict;
use modularity;
use testapi;
use utils;
sub run {
my $self=shift;
# switch to tty and login as root
$self->root_console(tty=>3);
# Download the testing script
download_modularity_tests();
# Install a Ruby module.
my $name = "nodejs";
my $stream = "14";
my $profile = "default";
assert_script_run("dnf module install -y $name:$stream/$profile");
# Check that modularity works and that a particular module is available in the system.
assert_script_run('/root/test.py -m nodejs -s 12 -a list');
# Check that it is listed in the installed list.
my $enabled = script_output('dnf module list --installed');
my @enabled_modules = parse_module_list($enabled);
my $found = is_listed($name, $stream, \@enabled_modules);
unless ($found) {
die "The installed module is not listed in the list of installed modules but it should be.";
}
# Check that module can be enabled and removed.
assert_script_run('/root/test.py -m nodejs -s 12 -p default -a install,remove,reset -f hard', 120);
# Check that it is listed in the enabled list.
my $disabled = script_output('dnf module list --enabled');
my @disabled_modules = parse_module_list($disabled);
$found = is_listed($name, $stream, \@disabled_modules);
unless ($found) {
die "The installed module is not listed in the list of enabled modules but it should be.";
}
# Upload modular logs
upload_logs '/root/modular.log', failok=>1;
# Remove the module again.
assert_script_run("dnf module remove -y $name:$stream");
# Check that it is not listed in the installed list.
my $enabled = script_output('dnf module list --installed');
my @enabled_modules = parse_module_list($enabled);
my $found = is_listed($name, $stream, \@enabled_modules);
if ($found) {
die "The installed module is listed in the list of installed modules but it should not be.";
}
}
1;

View File

@ -1,5 +1,6 @@
use base "installedtest";
use strict;
use modularity;
use testapi;
use utils;
@ -10,24 +11,39 @@ sub run {
# The test case will check that dnf has modular functions and that
# it is possible to invoke modular commands to work with modularity.
# It does not check the content of the further listed lists for any
# particular packages, modules or streams.
# Check that modular repositories are installed and enabled.
# If the repository does not exist, the output of the command is empty.
my $mfedora_output = script_output("dnf repolist --enabled fedora-modular");
die "The fedora-modular repo seems not to be installed." unless (length $mfedora_output);
my $mupdates_output = script_output("dnf repolist --enabled updates-modular");
die "The updates-modular repo seems not to be installed." unless (length $mupdates_output);
# Check that modularity works and dnf can list the modules.
assert_script_run('dnf module list');
my $modules = script_output('dnf module list --disablerepo=updates-modular --disablerepo=updates-testing-modular', timeout => 270);
my @modules = parse_module_list($modules);
die "The module list seems to be empty when it should not be." if (scalar @modules == 0);
# Check that modularity works and dnf can list the modules
# with the -all option.
assert_script_run('dnf module list --all');
$modules = script_output('dnf module list --all --disablerepo=updates-modular --disablerepo=updates-testing-modular', timeout => 270);
@modules = parse_module_list($modules);
die "The module list seems to be empty when it should not be." if (scalar @modules == 0);
# Check that dnf lists the enabled modules.
assert_script_run('dnf module list --enabled');
$modules = script_output('dnf module list --enabled', timeout => 270);
@modules = parse_module_list($modules);
die "There seem to be enabled modules when the list should be empty." unless (scalar @modules == 0);
# Check that dnf lists the disabled modules.
assert_script_run('dnf module list --disabled');
$modules = script_output('dnf module list --disabled', timeout => 270);
@modules = parse_module_list($modules);
die "There seem to be disabled modules when the list should be empty." unless (scalar @modules == 0);
# Check that dnf lists the installed modules.
assert_script_run('dnf module list --installed');
$modules = script_output('dnf module list --installed', timeout => 270);
@modules = parse_module_list($modules);
die "There seem to be installed modules when the list should be empty." unless (scalar @modules == 0);
}

View File

@ -2,25 +2,29 @@ use base "installedtest";
use strict;
use testapi;
use utils;
use modularity;
sub run {
my $self=shift;
# switch to tty and login as root
$self->root_console(tty=>3);
# Download the testing script
download_modularity_tests();
# Update the system
assert_script_run('dnf update -y');
# Enable and install the nodejs module, stream 8.
assert_script_run('/root/test.py -m nodejs -s 11 -a enable,install -f hard');
# Enable and install the nodejs module, stream 11.
assert_script_run('dnf module install -y nodejs:15');
# Update the system without modular repos.
assert_script_run('dnf update --disablerepo=\*modular -y');
# Check that the same version is listed in the installed modules.
assert_script_run('/root/test.py -m nodejs -s 11 -a checkinstall -f hard');
my $installed = script_output('dnf module list --installed');
my @installed_modules = parse_module_list($installed);
my $found = is_listed("nodejs", "15", \@installed_modules);
unless ($found) {
die "The expected module and version has not been found. The version might have been incorrectly changed by the upgrade command.";
}
}
1;