Commit 7e8955b2 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(test): fixed some tests when set time

The new set time request made some test fail because
it wasn't expected before.

issue #1279
parent 506b62bf
......@@ -36,6 +36,7 @@ our $IPTABLES_CHAIN = 'RAVADA';
our %PROPAGATE_FIELD = map { $_ => 1} qw( run_timeout );
our $TIME_CACHE_NETSTAT = 60; # seconds to cache netstat data output
our $RETRY_SET_TIME=10;
_init_connector();
......@@ -2293,9 +2294,16 @@ sub _pre_shutdown {
$self->resume(user => Ravada::Utils::user_daemon);
}
$self->list_disks;
$self->_remove_start_requests();
}
sub _remove_start_requests($self) {
for my $req ($self->list_requests(1)) {
$req->_delete if $req->command =~ /^set_time$/;
}
}
sub _post_shutdown {
my $self = shift;
......@@ -2969,7 +2977,7 @@ sub _post_start {
}
Ravada::Request->set_time(uid => Ravada::Utils::user_daemon->id
, id_domain => $self->id
, retry => 10
, retry => $RETRY_SET_TIME
);
Ravada::Request->enforce_limits(at => time + 60);
Ravada::Request->manage_pools(
......
......@@ -565,7 +565,10 @@ sub post_resume_aux($self) {
eval {
$self->set_time();
};
die "$@\n" if $@ && $@ !~ /libvirt error code: 86,/;
# 55: domain is not running
# 74: not configured
# 86: no agent
die "$@\n" if $@ && $@ !~ /libvirt error code: (55|74|86),/;
}
sub set_time($self) {
......@@ -792,7 +795,7 @@ Resumes a paused the domain
sub resume {
my $self = shift;
eval { $self->domain->resume() };
die $@ if $@ && $@ !~ /libvirt error code: 55/;
confess $@ if $@ && $@ !~ /libvirt error code: 55/;
}
......
......@@ -1211,6 +1211,11 @@ sub _requested($command, %fields) {
}
sub _delete($self) {
my $sth = $$CONNECTOR->dbh->prepare("DELETE FROM requests where id=?");
$sth->execute($self->id);
}
sub stop($self) {
my $stale = '';
my $run_time = '';
......
......@@ -405,7 +405,8 @@ sub test_already_started_twice($vm_name, $node) {
eval { $clone2->start(user => user_admin) };
like($@,qr/already running/) if $@;
is($clone2->list_requests,2);
# includes set_time request
is($clone2->list_requests,3);
for ( 1 .. 6 ) {
for ( 1 .. 10 ) {
last if !$clone->is_active
......
......@@ -760,7 +760,7 @@ sub wait_request {
$timeout = 60 if !defined $timeout && $background;
my $debug = ( delete $args{debug} or 0 );
my $skip = ( delete $args{skip} or ['enforce_limits','manage_pools','refresh_vms'] );
my $skip = ( delete $args{skip} or ['enforce_limits','manage_pools','refresh_vms','set_time'] );
$skip = [ $skip ] if !ref($skip);
my %skip = map { $_ => 1 } @$skip;
%skip = ( enforce_limits => 1 ) if !keys %skip;
......@@ -791,6 +791,8 @@ sub wait_request {
if ($check_error) {
if ($req->command eq 'remove') {
like($req->error,qr(^$|Unknown domain));
} elsif($req->command eq 'set_time') {
like($req->error,qr(^$|libvirt error code));
} else {
is($req->error,'') or confess $req->command;
}
......
......@@ -78,7 +78,7 @@ sub test_request_iptables($vm_name) {
is($req->status, 'done');
is($req->error,'');
is(scalar($domain->list_requests), 0);
is(scalar($domain->list_requests), 1);
is($domain->remote_ip,'127.0.0.1');
......
......@@ -240,7 +240,7 @@ sub test_shutdown {
my @req_other = grep { $_->command ne 'refresh_machine' } @reqs;
is(scalar(@req_other),0);
is(scalar @reqs,1,$domain->name) or exit;
is(scalar @reqs,1,$domain->name) or die Dumper([ map { [$_->id,$_->command,$_->status,$_->error] } @reqs]);
$domain->remove(user_admin);
}
......@@ -458,7 +458,7 @@ sub test_create_domain_nocd {
,id_owner => $USER->id
,iso_file => '<NONE>'
);};
is($@,'');
is(''.$@,'');
ok($domain,"Expecting a domain");
my ($cdrom) = grep { /iso/ } $domain->list_volumes;
......
......@@ -774,7 +774,7 @@ sub test_domain_limit_already_requested {
is(rvd_back->list_domains(user => $user, active => 1),1);
$domain2->start( $user );
my @list_requests = $domain->list_requests;
my @list_requests = grep { $_->command ne 'set_time'} $domain->list_requests;
is(scalar @list_requests,0,"Expecting 0 requests ".Dumper(\@list_requests));
is(rvd_back->list_domains(user => $user, active => 1),2);
......
......@@ -182,13 +182,11 @@ sub test_fw_ssh {
sub test_jump {
my ($vm_name, $domain_name) = @_;
my $out = `iptables -L INPUT -n`;
my $count = 0;
my $out = `iptables-save`;
for my $line ( split /\n/,$out ) {
next if $line !~ /^[A-Z]+ /;
$count++;
next if $line !~ /^RAVADA/;
`iptables -D INPUT $count`;
next if $line !~ /^-A (.*RAVADA.*)/;
my $rule = $1;
`iptables -D $rule`;
}
$out = `iptables -L INPUT -n`;
ok(! grep(/^RAVADA /, split(/\n/,$out)),"Expecting no RAVADA jump in $out");
......
......@@ -37,7 +37,7 @@ sub test_no_dupe($vm) {
is(grep(m{^ACCEPT.*192.168.\d+\.0/24\sstate NEW},@out),0);
$domain->start(user => user_admin, remote_ip => $remote_ip);
my @request = $domain->list_requests();
my @request = grep { $_->command ne 'set_time'} $domain->list_requests();
# No requests because no ports exposed
is(scalar @request,0) or exit;
......@@ -519,7 +519,7 @@ sub test_clone_exports_add_ports($vm) {
is(scalar @clone_ports,2 );
my @req = $clone->list_requests;
is(scalar(@req) , 1);
is(scalar(@req) , 2);
for my $n ( 0 .. 1 ) {
is($base_ports[$n]->{internal_port}, $clone_ports[$n]->{internal_port});
......@@ -529,6 +529,7 @@ sub test_clone_exports_add_ports($vm) {
_wait_ip($vm, $clone);
wait_request( debug => 0, request => \@req );
for (@req) {
next if $_->command eq 'set_time';
is($_->status,'done') or exit;
is($_->error,'') or exit;
}
......
......@@ -62,7 +62,7 @@ sub test_active($domain, $n_start) {
$domain->pool_start($n_start);
is($domain->pool_start, $n_start);
_remove_enforce_limits();
wait_request(skip => 'enforce_limits');
wait_request(skip => ['set_time','enforce_limits']);
Ravada::Request->manage_pools(uid => user_admin->id);
_remove_enforce_limits();
......@@ -77,7 +77,7 @@ sub test_active($domain, $n_start) {
sub _remove_enforce_limits {
my $sth = connector->dbh->prepare("DELETE FROM requests "
."WHERE command = 'enforce_limits'"
."WHERE command = 'enforce_limits' OR command = 'set_time'"
);
$sth->execute();
$sth->finish;
......@@ -108,7 +108,7 @@ sub test_user_create($base, $n_start) {
,remote_ip => '1.2.3.4'
);
ok($req);
wait_request(debug => 0,skip => 'enforce_limits');
wait_request(debug => 0,skip => ['enforce_limits','set_time']);
_remove_enforce_limits();
is($req->status,'done');
is($req->error,'');
......@@ -140,7 +140,7 @@ sub test_user($base, $n_start) {
,remote_ip => '1.2.3.4'
);
ok($req);
wait_request(debug => 0,skip => 'enforce_limits');
wait_request(debug => 1,skip => ['enforce_limits','set_time']);
_remove_enforce_limits();
is($req->status,'done');
is($req->error,'');
......@@ -185,7 +185,7 @@ sub test_user($base, $n_start) {
);
ok($req);
_remove_enforce_limits();
wait_request( skip => 'enforce_limits');
wait_request( skip => ['enforce_limits','set_time']);
is($req->status,'done');
is($req->error,'');
......
......@@ -42,7 +42,7 @@ sub test_run_timeout {
is($clone->run_timeout(),$timeout);
$clone->start(user => $USER);
is(scalar($clone->list_requests(1)),1) or exit;
is(scalar($clone->list_requests(1)),2) or exit;
is($clone->is_active,1);
rvd_back->_process_all_requests_dont_fork();
......
Markdown is supported
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