Commit ffb26146 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

wip: fixed for edge cases

parent 9af5a947
......@@ -2903,7 +2903,7 @@ sub remove_domain {
eval { $domain = Ravada::Domain->open(id => $id, _force => 1, id_vm => $vm->id) };
warn $@ if $@;
if (!$domain) {
warn "Warning: I can't find domain '$id', maybe already removed.";
warn "Warning: I can't find domain '$id', maybe already removed.\n";
Ravada::Domain::_remove_domain_data_db($id);
return;
};
......
......@@ -1021,7 +1021,6 @@ sub create_ldap_user($name, $password, $keep=0) {
for my $field (qw(cn uid)) {
if (my $user = Ravada::Auth::LDAP::search_user(field => $field, name => $name) ) {
return if $keep;
diag("Removing ".$user->dn);
my $mesg;
for ( 1 .. 2 ) {
$mesg = $user->delete()->update($ldap);
......@@ -1178,7 +1177,7 @@ sub wait_request {
$done{$req->{id}}++;
if ($check_error) {
if ($req->command =~ /remove/) {
like($req->error,qr(^$|Unknown domain));
like($req->error,qr(^$|Unknown domain|Domain not found));
} elsif($req->command eq 'set_time') {
like($req->error,qr(^$|libvirt error code));
} else {
......
......@@ -830,7 +830,7 @@ for my $vm_name ( @{rvd_front->list_vm_types} ) {
push @bases,($base0->name);
test_admin_can_do_anything($t, $base0);
my $base2 =test_create_base($t, $vm_name, new_domain_name()."-$vm_name");
my $base2 =test_create_base($t, $vm_name, new_domain_name()."-$vm_name-$$");
push @bases,($base2->name);
mojo_request($t, "add_hardware", { id_domain => $base0->id, name => 'network' });
......@@ -863,6 +863,7 @@ for my $vm_name ( @{rvd_front->list_vm_types} ) {
test_login_non_admin($t, $base1, $base2);
delete_request('set_time','screenshot','refresh_machine_ports');
remove_machines(reverse @bases);
remove_old_domains_req(0); # 0=do not wait for them
}
ok(@bases,"Expecting some machines created");
delete_request('set_time','screenshot','refresh_machine_ports');
......
......@@ -446,7 +446,7 @@ sub test_too_big($vm) {
like($@, qr(out of space),$vm->type) or exit;
ok(!$file);
my $free_disk2 = $vm->free_disk();
is($free_disk2, $free_disk);
is(int($free_disk2/1024), int($free_disk/1024));
$domain->remove(user_admin);
}
......
......@@ -3,6 +3,7 @@ use strict;
use Carp qw(confess);
use Data::Dumper;
use Mojo::JSON qw(decode_json);
use POSIX qw(WNOHANG);
use Test::More;
......@@ -56,7 +57,7 @@ sub test_volatile_clone_req {
,remote_ip => $remote_ip
,start => 1
);
rvd_back->_process_requests_dont_fork();
wait_request();
my $clone2 = rvd_back->search_domain($clone_name2);
is($clone2->is_active, 1);
......@@ -362,16 +363,32 @@ sub test_old_machine_req {
$domain->remove(user_admin);
}
sub _search_ips {
my $out = `ip -4 -j route`;
my $info = decode_json($out);
my @ips;
my %net;
for my $ip (@$info) {
my ($down) = grep /^linkdown$/,@{$ip->{flags}};
next if $down;
next if !$ip->{prefsrc};
my $dst = $ip->{dst};
my $metric = $ip->{metric};
my $metric_old = ($net{$dst}->[1] or 0 );
next if $metric_old && $metric>$metric_old;
$net{$dst} = [$ip->{prefsrc}, $metric];
}
for (keys %net) {
push @ips,($net{$_}->[0]);
}
return @ips;
}
sub test_ips {
my $vm = shift;
my $public_ip = $vm->_data('public_ip');
my $out = `ip -4 -o a`;
my @ips;
for my $line (split /\n/, $out) {
my ($if, $ip) = $line =~ /\s(\w+)\s+inet\s+(\d+\.\d+\.\d+\.\d+)/;
push @ips ,($ip) if (($if) && ($if !~ /^virbr/));
}
my @ips = _search_ips();
for my $ip (@ips) {
diag("Testing ip $ip");
......
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