Commit 32ec132a authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(backend); work around removed VMs

also minor improvements on mojo tests
parent cfb22b5d
......@@ -1282,6 +1282,7 @@ sub open($class, @args) {
die "ERROR: Domain not found id=$id\n"
if !keys %$row;
my $vm_changed;
if (!$vm && ( $id_vm || defined $row->{id_vm} ) ) {
eval {
$vm = Ravada::VM->open(id => ( $id_vm or $row->{id_vm} )
......@@ -1290,6 +1291,7 @@ sub open($class, @args) {
warn $@ if $@;
if ($@ && $@ =~ /I can't find VM id=/) {
$vm = Ravada::VM->open( type => $self->type );
$vm_changed = $vm;
}
}
my $vm_local;
......@@ -1299,6 +1301,7 @@ sub open($class, @args) {
bless $vm_local, $vm_class;
$vm = $vm_local->new( );
$vm_changed = $vm;
}
my $domain;
eval { $domain = $vm->search_domain($row->{name}, $force) };
......@@ -1311,9 +1314,10 @@ sub open($class, @args) {
$vm = $vm_local->new();
$domain = $vm->search_domain($row->{name}, $force) or return;
$domain->_data(id_vm => $vm->id);
$vm_changed = $vm;
}
$domain->_insert_db_extra() if $domain && !$domain->is_known_extra();
$domain->_data('id_vm' => $vm_changed->id) if $vm_changed;
return $domain;
}
......@@ -3106,7 +3110,10 @@ sub _remove_iptables {
push @{$rule{$id_vm}},[ $id, $iptables ];
}
for my $id_vm (keys %rule) {
my $vm = Ravada::VM->open($id_vm);
my $vm;
eval { $vm = Ravada::VM->open($id_vm) };
next if !$vm || $@ =~ /can't find VM/i;
die $@ if $@;
for my $entry (@ {$rule{$id_vm}}) {
my ($id, $iptables) = @$entry;
$self->_delete_ip_rule($iptables, $vm) if !$>;
......
use warnings;
use strict;
use Carp qw(confess);
use Data::Dumper;
use HTML::Lint;
use Test::More;
......@@ -46,6 +47,8 @@ sub _wait_request(@args) {
sub login( $user=$USERNAME, $pass=$PASSWORD ) {
$t->ua->get($URL_LOGOUT);
confess "Error: missing user" if !defined $user;
$t->post_ok('/login' => form => {login => $user, password => $pass});
like($t->tx->res->code(),qr/^(200|302)$/);
# ->status_is(302);
......@@ -143,7 +146,7 @@ sub test_login_fail {
$t->get_ok("/admin/machines")->status_is(401);
is($t->tx->res->dom->at("button#submit")->text,'Login') or exit;
login();
login( user_admin->name, "$$ $$");
$t->post_ok('/login' => form => {login => "fail", password => 'bigtime'});
is($t->tx->res->code(),403);
......@@ -322,6 +325,8 @@ for my $vm_name (@{rvd_front->list_vm_types} ) {
my $name = new_domain_name()."-".$vm_name;
remove_machines($name,"$name-".user_admin->name);
$name .= "-".$$;
_init_mojo_client();
$t->post_ok('/new_machine.html' => form => {
......
......@@ -81,6 +81,7 @@ sub _create_bases($t, $vm_name) {
}
sub test_bases($t, $bases) {
mojo_check_login($t);
my $n_bases = 0;
my $n_machines = scalar(@$bases);
for my $base ( @$bases ) {
......
......@@ -7,7 +7,8 @@ use Test::More;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
no warnings "experimental::signatures";
use feature qw(signatures);
my $RVD_BACK = rvd_back();
......@@ -187,6 +188,17 @@ sub touch_mtime {
}
sub test_vm_removed($vm) {
my $domain = create_domain($vm);
$domain->_data(id_vm => -1 );
my $domain2 = rvd_back->search_domain_by_id($domain->id);
$domain2->check_status();
isnt($domain2->_data('id_vm'), -1);
}
#######################################################################33
......@@ -220,6 +232,8 @@ for my $vm_name (@VMS) {
test_remove_domain($vm_name);
test_remove_domain_base($vm_name);
test_dont_remove_father($vm_name);
test_vm_removed($vm);
}
}
......
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