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

Reuse parse_repo_data to validate repos #10867

Merged
merged 1 commit into from Aug 25, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 39 additions & 22 deletions lib/repo_tools.pm
Expand Up @@ -87,7 +87,7 @@ our @EXPORT = qw(
prepare_oss_repo
disable_oss_repo
generate_version
validate_repo_enablement
validate_repo_properties
parse_repo_data
verify_software
);
Expand Down Expand Up @@ -442,34 +442,51 @@ sub generate_version {
}


=head2 validate_repo_enablement
=head2 validate_repo_properties

validate_repo_enablement(%args);
validate_repo_properties($args);

Validates that repo with given name and alias has correct uri and is enabled.
C<%args> should have following keys defined:
- C<alias>: repository alias
- C<name>: repository name
- C<uri>: repository uri
Validates that repo with given search criteria (uri, alias, number)
has other properties mathing the expectations.
If one of the keys is not provided, that field will NOT be validated.
C<$args> should have following keys defined:
- C<Alias>: repository alias, optional
- C<Autorefresh>: repository Autorefresh property, optional
- C<Enabled>: repository Enabled property, optional
- C<Filter>: repository search criteria (alias, uri, number), uri is used if not defined
- C<Name>: repository name, optional
- C<URI>: repository uri, used as a search criteria if no C<Filter> provided.

=cut
sub validate_repo_enablement {
my (%args) = @_;
sub validate_repo_properties {
my ($args) = @_;
my $search_criteria = $args->{Filter} // $args->{URI};
my $actual_repo_data = parse_repo_data($search_criteria);

if ($args->{Alias}) {
assert_true($actual_repo_data->{Alias} =~ /$args->{Alias}/,
"Repository $args->{Name} has wrong alias, expected: '$args->{Alias}', got: '$actual_repo_data->{Alias}'");
}

if ($args->{Name}) {
assert_true($actual_repo_data->{Name} =~ /$args->{Name}/,
"Repository '$args->{Name}' has wrong name: '$actual_repo_data->{Name}'");
}

my $output = script_output('zypper lr --uri');
if ($args->{URI}) {
assert_true($actual_repo_data->{URI} =~ /$args->{Alias}/,
"Repository $args->{Name} has wrong URI, expected: '$args->{URI}', got: '$actual_repo_data->{URI}'");
}

assert_true($output =~ /
\d\s+\| # #
\s+$args{alias}.*\s+\| # Alias
\s+$args{name}.*\s+\| # Name
\s+Yes\s+\| # Enabled
\s+\(r\s+\)\s+Yes\s+\| # GPG Check
\s+Yes\s+\| # Refresh
\s+(?<uri>.*) # URI
/ix, "Repository $args{name} is not found in the installed system:\n$output");
if ($args->{Enabled}) {
assert_equals($actual_repo_data->{Enabled}, $args->{Enabled},
"Repository $args->{Name} has wrong value for the field 'Enabled'");
}

assert_equals($args{uri}, $+{uri},
"Repository $args{name} has system wrong url or repo is not added to the system:\n$output");
if ($args->{Autorefresh}) {
assert_equals($actual_repo_data->{Autorefresh}, $args->{Autorefresh},
"Repository $args->{Name} has wrong value for the field 'Autorefresh'");
}
}

=head2 parse_repo_data
Expand Down
10 changes: 8 additions & 2 deletions tests/console/validate_addon_repos.pm
Expand Up @@ -18,7 +18,7 @@ use strict;
use warnings;

use testapi;
use repo_tools 'validate_repo_enablement';
use repo_tools 'validate_repo_properties';

sub run {
select_console 'root-console';
Expand All @@ -28,7 +28,13 @@ sub run {
my $uri = get_required_var("ADDONURL_$uc_addon");
my $alias = get_required_var("REPO_SLE_PRODUCT_$uc_addon");
my $name = get_required_var("DISTRI") . "-$addon";
validate_repo_enablement(alias => $alias, name => $name, uri => $uri);
validate_repo_properties({
Alias => $alias,
Name => $name,
URI => $uri,
Enabled => 'Yes',
Autorefresh => 'On'
});
}
}

Expand Down
8 changes: 2 additions & 6 deletions tests/console/validate_dud_addon_repos.pm
Expand Up @@ -18,19 +18,15 @@ use strict;
use warnings;

use testapi;
use repo_tools 'parse_repo_data';
use repo_tools 'validate_repo_properties';
use scheduler 'get_test_suite_data';
use Test::Assert ':all';

sub run {
my $test_data = get_test_suite_data();
select_console 'root-console';
foreach my $expected_dud_repo (@{$test_data->{dud_repos}}) {
my $actual_dud_repo = parse_repo_data($expected_dud_repo->{URI});
assert_equals($expected_dud_repo->{Enabled}, $actual_dud_repo->{Enabled},
"Fail! It is expected that the 'Enabled' field is set to $expected_dud_repo->{Enabled}, but it is $actual_dud_repo->{Enabled}");
assert_equals($expected_dud_repo->{Autorefresh}, $actual_dud_repo->{Autorefresh},
"Fail! It is expected that the 'Autorefresh' field is set to $expected_dud_repo->{Autorefresh}, but it is $actual_dud_repo->{Autorefresh}");
validate_repo_properties($expected_dud_repo);
}
assert_script_run('zypper -v ref | grep "All repositories have been refreshed"', 120);
}
Expand Down
13 changes: 11 additions & 2 deletions tests/console/validate_mirror_repos.pm
Expand Up @@ -15,7 +15,8 @@ use strict;
use warnings;
use base "opensusebasetest";
use testapi;
use repo_tools 'validate_repo_enablement';
use repo_tools 'validate_repo_properties';
use registration 'scc_version';

sub run {
select_console 'root-console';
Expand All @@ -24,9 +25,17 @@ sub run {
my $mirror_src = get_required_var("MIRROR_$method");
$mirror_src .= '?ssl_verify=no' if ($method eq 'HTTPS');
my $sle_prod = uc get_var('SLE_PRODUCT') . get_var('VERSION');
my $name = $sle_prod . '-' . scc_version() . '-0';

record_info("Mirror Validation", "Validate $mirror_src used for installation is added in the installed system");
validate_repo_enablement(alias => $sle_prod, name => $sle_prod, uri => $mirror_src);
validate_repo_properties({
Filter => $name,
Alias => $sle_prod,
Name => $sle_prod,
URI => $mirror_src,
Enabled => 'Yes',
Autorefresh => 'On'
});
}

1;