Skip to content

Commit

Permalink
wip: properly check timed cache and test networks
Browse files Browse the repository at this point in the history
issue #2144
  • Loading branch information
frankiejol committed Feb 26, 2025
1 parent b988da5 commit dd24390
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3658,7 +3658,7 @@ sub list_vms($self) {
return @{$self->vm};
}

sub list_vms_id($self) {
sub _list_vms_id($self) {
my $sth = $CONNECTOR->dbh->prepare(
"SELECT id FROM vms"
);
Expand Down Expand Up @@ -6132,7 +6132,7 @@ sub _clean_requests($self, $command, $request=undef, $status='requested') {
sub _refresh_active_vms ($self) {

my %active_vm;
for my $id ($self->list_vms_id) {
for my $id ($self->_list_vms_id) {
my $vm;
eval{ $vm = Ravada::VM->open($id) };
next if !$vm;
Expand Down
2 changes: 1 addition & 1 deletion lib/Ravada/Domain.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5605,7 +5605,7 @@ sub list_vms($self, $check_host_devices=0, $only_available=0) {
next if $only_available && ( !$is_active || !$enabled);
my $t1 = time;
if ($only_available && $cached_down) {
next if time-$cached_down < $self->timeout_down_cache();
next if time-$cached_down < $self->_vm->timeout_down_cache();
}
if ($id_request && $only_available) {
$sth_req->execute($id_request);
Expand Down
2 changes: 1 addition & 1 deletion lib/Ravada/Domain/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ sub _new_network($self) {
,address => ''
,type => 'nat'
,driver => 'virtio'
,name => "net".(scalar(@$list)+1)
,network => "net".(scalar(@$list)+1)
};
}

Expand Down
7 changes: 6 additions & 1 deletion lib/Ravada/Front/Domain/Void.pm
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ sub _get_controller_generic($self, $item) {
}

sub _get_controller_network($self) {
return $self->_get_controller_generic('network');
my @networks = $self->_get_controller_generic('network');
for my $net ( @networks ) {
$net->{_name} = $net->{network} if
!exists $net->{name} && !exists $net->{_name};
}
return @networks;
}

1;
11 changes: 11 additions & 0 deletions lib/Ravada/VM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1735,6 +1735,17 @@ sub _around_list_networks($orig, $self) {
return @list;
}

=head2 list_virtual_networks_data
Returns a list of information of the virtual networks in this virtual
machines manager (VM) from the database
Arguments:
Pass either the VM object or an id_vm
=cut

sub list_virtual_networks_data($id_vm) {
if (ref($id_vm)) {
my $self = $id_vm;
Expand Down
6 changes: 5 additions & 1 deletion t/request/30_hardware.t
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,11 @@ sub test_remove_hardware_by_index($vm, $hardware) {
is($items2->[0], $items1->[0]);
is($items2->[1], $items1->[2]);
} elsif ($hardware !~ /^(usb controller|video)$/) {
die "Error: no $name_field in ".Dumper($items2) if !exists $items2->[0]->{$name_field};
for my $n ( 0 .. scalar(@$items2)-1) {
my $curr = $items2->[$n];
die "Error: no $name_field for ".$domain->name
." in $hardware\[$n\] ".Dumper($items2) if !exists $curr->{$name_field};
}

is($items2->[0]->{$name_field},$items1->[0]->{$name_field});
is($items2->[1]->{$name_field},$items1->[2]->{$name_field});
Expand Down

0 comments on commit dd24390

Please sign in to comment.