Skip to content

Commit

Permalink
Fix node options (#2034)
Browse files Browse the repository at this point in the history
fix: read options directly from DB

closes #2032
  • Loading branch information
frankiejol committed Mar 11, 2024
1 parent 07a4953 commit f27b71c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

**Implemented enhancements:**

- Users can share virtual machines [\#2021]
- Virtual networks management [\#1984]
- GPU Mediated devices [\#1955]
- Allow remove users via GUI [\#2023]

**Bugfixes**

**Refactors**
32 changes: 27 additions & 5 deletions lib/Ravada/WebSocket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -345,12 +345,34 @@ sub _get_node_info($rvd, $args) {

return {} if!$user->is_admin;

my $node = Ravada::VM->open(id => $id_node, readonly => 1);
$node->_data('hostname');
$node->{_data}->{is_local} = $node->is_local;
$node->{_data}->{has_bases} = scalar($node->list_bases);
return $node->{_data};
my $sth = $rvd->_dbh->prepare("SELECT * FROM vms WHERE id=?");
$sth->execute($id_node);
my $data = $sth->fetchrow_hashref;
$data->{is_local}=0;
$data->{is_local}=1 if $data->{hostname} eq 'localhost'
|| $data->{hostname} eq '127.0.0,1'
|| !$data->{hostname};

$data->{bases}=_list_bases_node($rvd, $data->{id});

return $data;
}

sub _list_bases_node($rvd, $id_node) {
my $sth = $rvd->_dbh->prepare(
"SELECT d.id FROM domains d,bases_vm bv"
." WHERE d.is_base=1"
." AND d.id = bv.id_domain "
." AND bv.id_vm=?"
." AND bv.enabled=1"
);
my @bases;
$sth->execute($id_node);
while ( my ($id_domain) = $sth->fetchrow ) {
push @bases,($id_domain);
}
$sth->finish;
return \@bases;
}

sub _list_recent_requests($rvd, $seconds) {
Expand Down
32 changes: 32 additions & 0 deletions t/mojo/20_ws.t
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,36 @@ sub test_remove_booking_entry_non_admin($t, $id) {

}

sub test_node_info($vm_name) {
my $sth = connector->dbh->prepare("SELECT * FROM vms WHERE vm_type=?");
$sth->execute($vm_name);

my $user = create_user(new_domain_name(), $$);

while ( my $node = $sth->fetchrow_hashref) {
my $ws_args = {
channel => '/'.$node->{id}
,login => user_admin->name
};

my $node_info = Ravada::WebSocket::_get_node_info
(rvd_front(), $ws_args);
if ($node->{hostname} =~ /localhost|127.0.0.1/) {
is($node_info->{is_local},1);
} else {
is($node_info->{is_local},0);
}

$ws_args->{login} = $user->name;

$node_info = Ravada::WebSocket::_get_node_info
(rvd_front(), $ws_args);

is_deeply($node_info,{});
}

}

########################################################################################

init('/etc/ravada.conf',0);
Expand Down Expand Up @@ -379,6 +409,8 @@ for my $vm_name ( @{rvd_front->list_vm_types} ) {

diag("Testing Web Services in $vm_name");

test_node_info($vm_name);

mojo_login($t, $USERNAME, $PASSWORD);
test_bookings($t);
my @bases = _create_bases($t, $vm_name);
Expand Down

0 comments on commit f27b71c

Please sign in to comment.