os-autoinst-distri-rocky-mi.../lib/modularity.pm
Lukáš Růžička 114610bf90 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.
2021-05-03 19:13:09 +00:00

46 lines
1.3 KiB
Perl

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