diff --git a/lib/modularity.pm b/lib/modularity.pm new file mode 100644 index 00000000..402f1a4c --- /dev/null +++ b/lib/modularity.pm @@ -0,0 +1,48 @@ +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|^$/) { + if ($profile =~ /,$/) { + $profile = substr($profile, 0, -1); + } + 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; +} diff --git a/tests/modularity_enable_disable_module.pm b/tests/modularity_enable_disable_module.pm index e4732292..d645322a 100644 --- a/tests/modularity_enable_disable_module.pm +++ b/tests/modularity_enable_disable_module.pm @@ -1,25 +1,88 @@ 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(); + # List all available modules on the system and have this list ready for further + # purposes. + # + my $modlist = script_output('dnf module list --disablerepo=updates-modular --disablerepo=updates-testing-modular', timeout => 270); + my @modules = parse_module_list($modlist); - # 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'); + # Pick up a random module from the list to test that it can be enabled. + my $random_module = $modules [rand @modules]; + # Enable the module. + my $name = $random_module->{module}; + my $stream = $random_module->{stream}; + assert_script_run("dnf module enable -y $name:$stream"); - # 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 listed in the enabled list. + my $enabled = script_output('dnf module list --enabled'); + my @enabled_modules = parse_module_list($enabled); + my $found = is_listed($name, $stream, \@enabled_modules); + unless ($found) { + die "The enabled module is not listed in the list of enabled modules but it should be."; + } + + # 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); + $found = is_listed($name, $stream, \@disabled_modules); + if ($found) { + die "The enabled module is listed in the list of disabled modules but it should not be."; + } - # Upload the modular log file. - upload_logs '/root/modular.log', failok=>1; + # Pick up a random module from the list to test that it can be disabled. + my $random_module = $modules [rand @modules]; + # Disable the module. + my $name_alt = $random_module->{module}; + my $stream_alt = $random_module->{stream}; + 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); + $found = is_listed($name_alt, $stream_alt, \@disabled_modules); + unless ($found) { + 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); + $found = is_listed($name_alt, $stream_alt, \@enabled_modules); + if ($found) { + 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); + $found = is_listed($name, $stream, \@disabled_modules); + if ($found) { + 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); + $found = is_listed($name, $stream, \@enabled_modules); + if ($found) { + 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"); + } 1; diff --git a/tests/modularity_install_module.pm b/tests/modularity_install_module.pm index d674191c..8aa79d9e 100644 --- a/tests/modularity_install_module.pm +++ b/tests/modularity_install_module.pm @@ -1,23 +1,54 @@ 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(); + # List all available modules on the system and have this list ready for further + # purposes. + # + my $modlist = script_output('dnf module list --disablerepo=updates-modular --disablerepo=updates-testing-modular', timeout => 270); + my @modules = parse_module_list($modlist); - # 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'); + # Pick up a random module from the list to test that it can be installed. + my $random_module = $modules [rand @modules]; + # Enable the module. + my $name = $random_module->{module}; + my $stream = $random_module->{stream}; + my $profile = $random_module->{profile}; + assert_script_run("dnf module install -y $name:$stream/$profile"); - # 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 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 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; diff --git a/tests/modularity_module_list.pm b/tests/modularity_module_list.pm index 6e7f605d..4f2d170a 100644 --- a/tests/modularity_module_list.pm +++ b/tests/modularity_module_list.pm @@ -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); }