Commit 2206ec18 authored by frankiejol's avatar frankiejol
Browse files

wip(test): improved process waiting

parent 6c357d18
......@@ -85,7 +85,7 @@ sub test_start {
$RAVADA->_process_all_requests_dont_fork(0);
}
wait_request($req);
wait_request( background => $fork, check_error => 0 );
ok($req->status eq 'done', "[$vm_name] Req ".$req->{id}." expecting status done, got ".$req->status);
like($req->error , qr/unknown/i
......@@ -176,7 +176,7 @@ sub test_screenshot {
my $dont_fork = 1;
rvd_back->process_all_requests(0,$dont_fork);
wait_request($req);
wait_request( background=> !$dont_fork );
ok($req->status('done'),"Request should be done, it is ".$req->status);
ok(!$req->error(''),"Error should be '' , it is ".$req->error);
......@@ -209,7 +209,7 @@ sub test_screenshot_file {
my $dont_fork = 1;
rvd_back->process_all_requests(0,$dont_fork);
wait_request($req);
wait_request( background => !$dont_fork );
ok($req->status('done'),"Request should be done, it is ".$req->status);
ok(!$req->error(),"Error should be '' , it is ".($req->error or ''));
......
......@@ -225,6 +225,7 @@ sub test_manage_group {
}
sub test_user_bind {
my $user = shift;
my $file_config = shift;
my $with_posix_group = shift;
......@@ -238,11 +239,11 @@ sub test_user_bind {
Ravada::Auth::LDAP::init();
_add_to_posix_group('jimmy.mcnulty', $with_posix_group);
_add_to_posix_group($user->name, $with_posix_group);
my $mcnulty;
eval { $mcnulty = Ravada::Auth::LDAP->new(name => 'jimmy.mcnulty',password => 'jameson') };
is($@,'');
eval { $mcnulty = Ravada::Auth::LDAP->new(name => $user->name,password => 'jameson') };
is($@,'') or die $file_config_bind;
ok($mcnulty,($@ or "ldap login failed ")) or return;
......@@ -288,6 +289,12 @@ sub _init_config($file_config, $with_admin, $with_posix_group, $with_filter = 0)
delete $config->{ldap}->{filter};
}
if ($with_admin) {
$config->{ldap}->{admin_group} = $ADMIN_GROUP;
} else {
delete $config->{ldap}->{admin_group};
}
$config->{vm}=['KVM','Void'];
delete $config->{ldap}->{ravada_posix_group} if !$with_posix_group;
......@@ -461,13 +468,13 @@ SKIP: {
ok($ldap) and do {
test_user_fail();
test_user( 'pepe.mcnulty', $with_posix_group );
my $user = test_user( 'pepe.mcnulty', $with_posix_group );
test_add_group();
test_manage_group($with_admin, $with_posix_group);
test_posix_group($with_posix_group);
test_user_bind($fly_config, $with_posix_group);
test_user_bind($user, $fly_config, $with_posix_group);
remove_users();
};
......
......@@ -66,7 +66,6 @@ sub test_remove_corrupt_clone {
);
for my $file ( $clone->list_disks ) {
warn $file;
open my $out, '>',$file or die "$! $file";
print $out "bogus\n";
close $out;
......
......@@ -126,9 +126,7 @@ sub add_ubuntu_minimal_iso {
,md5 => 'c7b21dea4d2ea037c3d97d5dac19af99'
});
my $device = "/var/lib/libvirt/images/".$info{$distro}->{rename_file};
warn $device;
if ( -e $device ) {
warn $device;
$info{$distro}->{device} = $device;
}
$RVD_BACK->_update_table('iso_images','name',\%info);
......@@ -594,18 +592,25 @@ sub wait_request {
my %args;
if (scalar @_ % 2 == 0 ) {
%args = @_;
$args{process} = 1 if !exists$args{process};
$args{background} = 0 if !exists $args{background};
} else {
$args{request} = [ $_[0] ];
}
my $timeout = delete $args{timeout};
my $request = ( delete $args{request} or [] );
my $process = delete $args{process};
$timeout = 60 if !defined $timeout && !$process;
my $background = delete $args{background};
$background = 1 if !defined $background;
$timeout = 60 if !defined $timeout && $background;
my $debug = ( delete $args{debug} or 0 );
my $skip = ( delete $args{skip} or [] );
$skip = [ $skip ] if !ref($skip);
my %skip = map { $_ => 1 } @$skip;
my $check_error = delete $args{check_error};
$check_error = 1 if !defined $check_error;
die "Error: uknown args ".Dumper(\%args) if keys %args;
my $t0 = time;
my %done;
......@@ -615,7 +620,7 @@ sub wait_request {
my $done_count = scalar keys %done;
$prev = '' if !defined $prev;
my @req = _list_requests();
rvd_back->_process_requests_dont_fork($debug) if $process;
rvd_back->_process_requests_dont_fork($debug) if !$background;
for my $req_id ( @req ) {
my $req = Ravada::Request->open($req_id);
next if $skip{$req->command};
......@@ -623,7 +628,7 @@ sub wait_request {
$done_all = 0;
} elsif (!$done{$req->id}) {
$done{$req->{id}}++;
is($req->error,'');
is($req->error,'') if $check_error;
}
}
my $post = join(".",_list_requests);
......@@ -639,7 +644,7 @@ sub wait_request {
}
return if $done_all && $prev eq $post && scalar(keys %done) == $done_count;;
return if defined $timeout && time - $t0 >= $timeout;
sleep 1 if !$process;
sleep 1 if !$background;
}
}
......
......@@ -92,7 +92,7 @@ sub test_req_create_domain_iso {
my $rvd_back = rvd_back();
# $rvd_back->process_requests(1);
$rvd_back->process_requests();
wait_request($req);
wait_request(background => 1);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......@@ -156,7 +156,7 @@ sub test_req_create_domain {
my $rvd_back = rvd_back();
$rvd_back->process_requests();
wait_request($req);
wait_request(background => 1);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......@@ -200,7 +200,7 @@ sub test_req_prepare_base {
rvd_back->_process_all_requests_dont_fork();
rvd_back->process_long_requests(0,1);
wait_request($req);
wait_request(background => 1);
ok(!$req->error,"Expecting error='', got '".($req->error or '')."'");
my $vm = rvd_front()->search_vm($vm_name);
......@@ -245,7 +245,7 @@ sub test_req_create_from_base {
rvd_back->process_requests();
wait_request($req);
wait_request(background => 1);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......@@ -288,7 +288,7 @@ sub test_req_create_from_base_novm {
rvd_back->process_requests();
wait_request($req);
wait_request(background => 1);
ok($req->status eq 'done'
,"Status of request is ".$req->status." it should be done");
......@@ -420,7 +420,7 @@ sub test_req_remove_base {
my $rvd_back = rvd_back();
rvd_back->process_requests();
rvd_back->process_long_requests(0,1);
wait_request($req);
wait_request(background => 1);
}
ok($req->status eq 'done', "[$vm_name] Expected req->status 'done', got "
."'".$req->status."'");
......
......@@ -72,7 +72,8 @@ sub test_display {
my ($vm_name, $domain) = @_;
my $display;
$domain->start( user_admin ) if !$domain->is_active;
$domain->shutdown_now(user_admin);
$domain->start(user => user_admin, remote_ip => '1.2.3.4' );# if !$domain->is_active;
eval { $display = $domain->display( user_admin )};
is($@,'');
ok($display,"Expecting a display URI, got '".($display or '')."'") or return;
......
......@@ -110,7 +110,7 @@ sub test_req_create_domain{
rvd_back()->process_requests();
wait_request($req);
wait_request(background => 1);
ok($req->status('done'),"Expecting status='done' , got ".$req->status);
ok(!$req->error,"Expecting error '' , got '".($req->error or '')."'");
......@@ -145,7 +145,7 @@ sub test_req_create_fail {
rvd_back->_process_all_requests_dont_fork();
}
wait_request($req);
wait_request( background => $fork, check_error => 0 );
ok($req->status('done'),"Expecting status='done' , got ".$req->status);
ok($req->error,"Expecting error creating $name , got '".($req->error or '')."'"
." with memory: $mem , disk: $disk , fork: ".($fork or 0)) or exit;
......@@ -251,8 +251,7 @@ sub test_small {
#######################################################################
remove_old_domains();
remove_old_disks();
clean();
$Data::Dumper::Sortkeys = 1;
for my $vm_name (qw( Void KVM )) {
......@@ -284,8 +283,7 @@ for my $vm_name (qw( Void KVM )) {
};
}
remove_old_domains();
remove_old_disks();
clean();
done_testing();
......@@ -87,8 +87,7 @@ sub test_fw_domain($vm_name, $domain_name, $remote_ip='99.88.77.66') {
);
ok($req);
ok($req->status);
rvd_back->_process_all_requests_dont_fork();
wait_request($req);
wait_request(background=> 0);
is($req->status,'done');
is($req->error,'');
......@@ -148,8 +147,7 @@ sub test_fw_domain_pause {
ok($req->status);
my @messages = $USER->messages();
rvd_back->process_requests();
wait_request($req);
wait_request(background => 0);
is($req->status,'done');
is($req->error,'');
......
......@@ -55,7 +55,7 @@ for my $vm_name ( @{rvd_front->list_vm_types}) {
} else {
rvd_back->_process_all_requests_dont_fork();
}
wait_request($req);
wait_request( background => $fork );
$domain = rvd_back->search_domain($domain->name);
is($domain->is_active,0);
......
......@@ -51,6 +51,10 @@ sub test_clones($domain, $n_clones) {
ok($clone);
is($domain->clones(), $n_clones+1);
is($domain->clones(is_pool => 1), $n_clones);
my $clone_f = Ravada::Front::Domain->open($clone->id);
my $info = $clone_f->info(user_admin);
is($info->{id_base}, $domain->id,Dumper($info)) or exit;
}
sub test_active($domain, $n_start) {
......@@ -123,9 +127,10 @@ sub test_user($base, $n_start) {
is($clone2->is_pool,1) or exit;
my $clone_f = Ravada::Front::Domain->open($clone2->id);
is($clone_f->{pools},undef);
is($clone_f->{is_pool},1);
is($clone_f->{comment},$user->name);
my $info = $clone_f->info(user_admin);
is($info->{pools},0);
is($info->{is_pool},1) or die Dumper($clone_f);
is($info->{comment},$user->name);
# now we should have another active
wait_request(debug => 0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment