Skip to content

Commit

Permalink
Locate actual wheels in WHEELS_DIR
Browse files Browse the repository at this point in the history
- The wheels need to be stored in a way that they can be
modified easily rather than pool which is volatile.
- By default the pool is used as always.
- When cloning the path is explicitly logged.

Fixes: https://progress.opensuse.org/issues/134390
  • Loading branch information
kalikiana committed Sep 6, 2023
1 parent fb060dc commit 07d86f2
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 27 deletions.
3 changes: 1 addition & 2 deletions OpenQA/Isotovideo/Runner.pm
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ sub checkout_code ($self) {

$bmwqemu::vars{TEST_GIT_HASH} = checkout_git_refspec($bmwqemu::vars{CASEDIR} => 'TEST_GIT_REFSPEC');

$bmwqemu::vars{WHEELS_DIR} ||= $bmwqemu::vars{CASEDIR};
checkout_wheels($bmwqemu::vars{WHEELS_DIR});
checkout_wheels($bmwqemu::vars{CASEDIR}, $bmwqemu::vars{WHEELS_DIR});
}

sub _flush_std ($) {
Expand Down
14 changes: 9 additions & 5 deletions OpenQA/Isotovideo/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use Mojo::Base -base, -signatures;
use Mojo::URL;
use Mojo::File qw(path);
use JSON::Validator;
use Cwd 'cwd';
use YAML::XS; # Required by JSON::Validator as a runtime dependency
use YAML::PP;

Expand Down Expand Up @@ -42,7 +43,7 @@ sub clone_git ($local_path, $clone_url, $clone_depth, $branch, $dir, $dir_variab
bmwqemu::diag "Skipping to clone '$clone_url'; $local_path already exists";
return 1;
}
bmwqemu::fctinfo "Cloning git URL '$clone_url'";
bmwqemu::fctinfo "Cloning git URL '$clone_url' into '" . cwd . "'";
my $branch_args = '';
if ($branch) {
bmwqemu::fctinfo "Checking out git refspec/branch '$branch'";
Expand Down Expand Up @@ -138,8 +139,8 @@ optional git refspec to checkout.
If no wheels are configured the function returns early.
=cut
sub checkout_wheels ($dir) {
my $specfile = path($dir, 'wheels.yaml');
sub checkout_wheels ($case_dir, $wheels_dir = undef) {
my $specfile = path($case_dir, 'wheels.yaml');
return 1 unless -e $specfile;
my $schema_file = "$bmwqemu::scriptdir/schema/Wheels-01.yaml";
Expand All @@ -150,15 +151,18 @@ sub checkout_wheels ($dir) {
$validator->schema($schema_file);
my $spec = YAML::PP->new->load_file($specfile);
my @errors = $validator->validate($spec);
die 'Invalid YAML: ' . join(',', @errors) if @errors;
die 'Unsupported version: Version must be "v0.1"' if $spec->{version} ne 'v0.1';
die "Invalid YAML ($specfile): " . join(',', @errors) if @errors;
die "Unsupported version ($specfile): Version must be 'v0.1'" if $spec->{version} ne 'v0.1';
my $old_cwd = cwd;
chdir $wheels_dir if defined $wheels_dir;
foreach my $repo (@{$spec->{wheels}}) {
$repo = "https://github.com/$repo.git" unless $repo =~ qr/^http/;
if (my $clone = checkout_git_repo_and_branch($specfile, repo => $repo)) {
unshift @INC, "$clone/lib";
}
}
chdir $old_cwd;
return 0;
}
Expand Down
5 changes: 4 additions & 1 deletion autotest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ loadtest is called.
=cut

sub find_script ($script) {
if (defined(my $wheel = (glob Cwd::getcwd . "/*/tests/$script"))) {
my $wheels_dir = $bmwqemu::vars{WHEELS_DIR} // Cwd::getcwd . "/*/tests/";
# XXX: The tests pass even if the code is wrong?
# XXX: my $wheels_dir = $bmwqemu::vars{WHEELS_DIR} // Cwd::getcwd;
if (defined(my $wheel = (glob $wheels_dir . "/*/tests/$script"))) {
return $wheel;
}
my $casedir = $bmwqemu::vars{CASEDIR};
Expand Down
50 changes: 31 additions & 19 deletions t/14-isotovideo.t
Original file line number Diff line number Diff line change
Expand Up @@ -130,47 +130,58 @@ subtest 'isotovideo with wheels' => sub {
unlink('vars.json') if -e 'vars.json';

$bmwqemu::scriptdir = "$Bin/..";
my $wheels_dir = "$data_dir";
my $specfile = path("$wheels_dir/wheels.yaml");
my $case_dir = "$data_dir/tests";
my $wheels_dir = "$data_dir/wheels_dir";
my $specfile = path($case_dir)->make_path->child('wheels.yaml');
$specfile->spurt("wheels: [foo/bar]");
throws_ok { checkout_wheels(
"$wheels_dir") } qr@Invalid.*Missing property@, 'invalid YAML causes error';
$case_dir, $wheels_dir) } qr@Invalid.*\Q$specfile\E.*Missing property@, 'invalid YAML causes error';
$specfile->spurt("version: v99\nwheels: [foo/bar]");
throws_ok { checkout_wheels(
"$wheels_dir") } qr@Unsupported version@, 'unsupported version';
$case_dir, $wheels_dir) } qr@Unsupported version.*\Q$specfile\E.*@, 'unsupported version';
$specfile->spurt("version: v0.1\nwheels: [https://github.com/foo/bar.git]");
my $utils_mock = Test::MockModule->new('OpenQA::Isotovideo::Utils');
my @repos;
$utils_mock->redefine(checkout_git_repo_and_branch => sub ($dir_variable, %args) { push @repos, $args{repo} });
checkout_wheels("$wheels_dir");
checkout_wheels($case_dir, $wheels_dir);
is($repos[0], 'https://github.com/foo/bar.git', 'repo with full URL');
is(scalar @repos, 1, 'one wheel');
$specfile->spurt("version: v0.1\nwheels: [https://github.com/foo/bar.git#branch]");
checkout_wheels("$wheels_dir");
checkout_wheels($case_dir, $wheels_dir);
is($repos[1], 'https://github.com/foo/bar.git#branch', 'repo URL with branch');
is(scalar @repos, 2, 'one wheel');
$specfile->spurt("version: v0.1\nwheels: [foo/bar]");
checkout_wheels("$wheels_dir");
checkout_wheels($case_dir, $wheels_dir);
is(scalar @repos, 3, 'one wheel');
is($repos[2], 'https://github.com/foo/bar.git', 'only wheel');
$specfile->spurt("version: v0.1\nwheels: [foo/bar, spam/eggs]");
checkout_wheels("$wheels_dir");
checkout_wheels($case_dir, $wheels_dir);
is($repos[4], 'https://github.com/spam/eggs.git', 'second wheel');
is(scalar @repos, 5, 'two wheels');
$specfile->remove;
is(checkout_wheels("$wheels_dir"), 1, 'no wheels');
is(checkout_wheels($case_dir, $wheels_dir), 1, 'no wheels');
is(scalar @repos, 5, 'git never called');

# also verify that isotovideo invokes the wheel code correctly
$bmwqemu::vars{CASEDIR} = "$data_dir/tests";
$specfile->spurt("version: v0.1\nwheels: [copy/writer]");
path($pool_dir, 'writer', 'lib', 'Copy', 'Writer')->make_path->child('Content.pm')->spurt("package Copy::Writer::Content; use Mojo::Base 'Exporter'; our \@EXPORT_OK = qw(write); sub write {}; 1");
path($pool_dir, 'writer', 'tests', 'pen')->make_path->child('ink.pm')->spurt("use Mojo::Base 'basetest'; use Copy::Writer::Content 'write'; sub run {}; 1");
my $log = combined_from { isotovideo(
opts => "wheels_dir=$wheels_dir casedir=$data_dir/tests schedule=pen/ink _exit_after_schedule=1") };
like $log, qr@Skipping to clone.+copy/writer@, 'already cloned wheel picked up';
like $log, qr/scheduling ink/, 'module from the wheel scheduled';
rmtree "$pool_dir/writer";
$bmwqemu::vars{CASEDIR} = $case_dir;

for my $dir (("$data_dir/wheels_dir", undef)) {
chdir $pool_dir;
$bmwqemu::vars{WHEELS_DIR} = $dir;
$wheels_dir = $dir // $pool_dir;

subtest "wheels in $wheels_dir" => sub {
$specfile->spurt("version: v0.1\nwheels: [copy/writer]");
path($wheels_dir, 'writer', 'lib', 'Copy', 'Writer')->make_path->child('Content.pm')->spurt("package Copy::Writer::Content; use Mojo::Base 'Exporter'; our \@EXPORT_OK = qw(write); sub write {}; 1");
path($wheels_dir, 'writer', 'tests', 'pen')->make_path->child('ink.pm')->spurt("use Mojo::Base 'basetest'; use Copy::Writer::Content 'write'; sub run {}; 1");
my $log = combined_from { isotovideo(
opts => "wheels_dir=$wheels_dir casedir=$case_dir schedule=pen/ink _exit_after_schedule=1") };
like $log, qr@Skipping to clone.+copy/writer@, 'already cloned wheel picked up';
like $log, qr/scheduling ink/, 'module from the wheel scheduled';
rmtree "$wheels_dir/writer";
};
}
$specfile->remove;
};

subtest 'productdir variable relative/absolute' => sub {
Expand Down Expand Up @@ -310,5 +321,6 @@ done_testing();

END {
rmtree "$Bin/data/tests/product";
unlink("$data_dir/wheels.yaml") if -e "$data_dir/wheels.yaml";
rmtree "$data_dir/wheels_dir";
unlink "$data_dir/tests/wheels.yaml" if -e "$data_dir/tests/wheels.yaml";
}

0 comments on commit 07d86f2

Please sign in to comment.