Skip to content

Commit

Permalink
wip: properly start nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
frankiejol committed Apr 12, 2024
1 parent bb60cb9 commit e4f1839
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 16 deletions.
7 changes: 5 additions & 2 deletions lib/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5684,8 +5684,11 @@ sub _cmd_shutdown_node($self, $request) {

sub _cmd_start_node($self, $request) {
my $id_node = $request->args('id_node');
my $node = Ravada::VM->open($id_node);
$node->start();
my $node;
eval{ $node = Ravada::VM->open($id_node);
$node->start() if$node;
};
Ravada::VM::_wake_on_lan($id_node) if !$node;
}

sub _cmd_connect_node($self, $request) {
Expand Down
1 change: 1 addition & 0 deletions lib/Ravada/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ our %COMMAND = (
,priority => 4
,commands => ['shutdown','shutdown_now', 'enforce_limits', 'set_time'
,'remove_domain', 'remove', 'refresh_machine_ports'
,'connect_node','start_node','shutdown_node'
]
}

Expand Down
25 changes: 18 additions & 7 deletions lib/Ravada/VM.pm
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ sub open {
$args{security} = decode_json($row->{security}) if $row->{security};

my $vm = $self->new(%args);
return if !$vm || !$vm->vm;
$VM{$args{id}} = $vm unless $args{readonly};

eval {
$VM{$args{id}} = $vm unless $args{readonly} || !$vm->vm;
};
return $vm;

}
Expand Down Expand Up @@ -2399,17 +2401,26 @@ sub _store_mac_address($self, $force=0 ) {
}
}

sub _wake_on_lan( $self ) {
return if $self->is_local;
sub _wake_on_lan( $self=undef ) {
return if $self && ref($self) && $self->is_local;

die "Error: I don't know the MAC address for node ".$self->name
if !$self->_data('mac');
my ($mac_addr, $id_node);
if (ref($self)) {
$mac_addr = $self->_data('mac');
$id_node = $self->id;
} else {
$id_node = $self;
my $sth = $$CONNECTOR->dbh->prepare("SELECT mac FROM vms WHERE id=?");
$sth->execute($id_node);
$mac_addr = $sth->fetchrow();
}
die "Error: I don't know the MAC address for node $id_node"
if !$mac_addr;

my $sock = new IO::Socket::INET(Proto=>'udp', Timeout => 60)
or die "Error: I can't create an UDP socket";
my $host = '255.255.255.255';
my $port = 9;
my $mac_addr = $self->_data('mac');

my $ip_addr = inet_aton($host);
my $sock_addr = sockaddr_in($port, $ip_addr);
Expand Down
2 changes: 1 addition & 1 deletion t/lib/Test/Ravada.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1382,7 +1382,7 @@ sub wait_request {
my $error = ($req->error or '');
next if $error =~ /waiting for processes/i;
if ($req->command =~ m{rsync_back|set_base_vm|start}) {
like($error,qr{^($|.*port \d+ already used|rsync done)}) or confess $req->command;
like($error,qr{^($|.*port \d+ already used|.*rsync)}) or confess $req->command;
} elsif($req->command eq 'refresh_machine_ports') {
like($error,qr{^($|.*is not up|.*has ports down|nc: |Connection)});
$req->status('done');
Expand Down
12 changes: 6 additions & 6 deletions t/mojo/70_volatile.t
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ sub _clean_old_known($vm_name) {
}
}

sub _clean_old_bases($vm_name) {
sub _clean_old_bases($vm_name, $wait=1) {
my $sth = connector->dbh->prepare("SELECT name FROM domains "
." WHERE is_base=1 AND (id_base IS NULL or id_base=0)"
." AND name like 'zz-test%'"
Expand All @@ -476,11 +476,11 @@ sub _clean_old_bases($vm_name) {
);
}
}
wait_request();
wait_request() if$wait;
}

sub _clean_old($vm_name) {
_clean_old_bases($vm_name);
sub _clean_old($vm_name, $wait=1) {
_clean_old_bases($vm_name, $wait);
_clean_old_known($vm_name);
_remove_unused_volumes();
}
Expand Down Expand Up @@ -511,15 +511,15 @@ Test::Ravada::_discover();
_init_mojo_client();
login();

for my $vm_name (reverse @{rvd_front->list_vm_types} ) {
for my $vm_name (@{rvd_front->list_vm_types} ) {
diag("Testing volatile clones in $vm_name");

_clean_old($vm_name);

test_clone($vm_name);
_clean_old($vm_name);
}

remove_old_domains_req(0); # 0=do not wait for them
remove_networks_req();

end();
Expand Down

0 comments on commit e4f1839

Please sign in to comment.