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

[#202] start the domain in the last VM it started

parent c7302c88
......@@ -720,6 +720,7 @@ sub _upgrade_tables {
$self->_upgrade_table('domains','spice_password','varchar(20) DEFAULT NULL');
$self->_upgrade_table('domains','description','text DEFAULT NULL');
$self->_upgrade_table('domains','run_timeout','int DEFAULT NULL');
$self->_upgrade_table('domains','id_vm',"int default NULL");
$self->_upgrade_table('vms','security','varchar(20) default NULL');
}
......@@ -1038,7 +1039,10 @@ sub search_domain {
eval { $id = $domain->id };
# TODO import the domain in the database with an _insert_db or something
warn $@ if $@ && $DEBUG;
return $domain if $id || $import;
next if !$id && !$import;
$domain->_vm($domain->last_vm()) if $id && $domain->last_vm;
return $domain;
}
......
......@@ -1182,6 +1182,7 @@ sub _post_start {
%arg = @_;
}
$self->_add_iptable(@_);
$self->_update_id_vm();
if ($self->run_timeout) {
my $req = Ravada::Request->shutdown_domain(
......@@ -1194,6 +1195,15 @@ sub _post_start {
}
}
sub _update_id_vm {
my $self = shift;
my $sth = $$CONNECTOR->dbh->prepare(
"UPDATE domains set id_vm=? where id = ?"
);
$sth->execute($self->_vm->id, $self->id);
$sth->finish;
}
sub _add_iptable {
my $self = shift;
return if scalar @_ % 2;
......@@ -1568,6 +1578,25 @@ sub remote_ip {
}
=head2 last_vm
Returns the last virtual machine manager on which this domain was
launched.
my $vm = $domain->last_vm();
=cut
sub last_vm {
my $self = shift;
my $id_vm = $self->_data('id_vm');
return if !$id_vm;
return Ravada::VM->open($id_vm);
}
=head2 list_requests
Returns a list of pending requests from the domain
......
......@@ -171,6 +171,18 @@ sub test_remove_domain_node {
}
}
sub test_domain_starts_in_same_vm {
my ($vm_name, $node, $domain) = @_;
unlike($domain->_vm->host, qr/localhost/) or return;
is($domain->_vm->host, $node->host) or return;
my $domain2 = rvd_back->search_domain($domain->name);
ok($domain2,"Expecting a domain called ".$domain->name) or return;
is($domain2->_vm->host, $node->host);
}
#############################################################
clean();
......@@ -210,6 +222,8 @@ SKIP: {
my $domain3 = test_domain($vm_name, $node);
test_remove_domain($vm_name, $node, $domain3) if $domain3;
my $domain4 = test_domain($vm_name, $node);
test_domain_starts_in_same_vm($vm_name, $node, $domain4) if $domain4;
}
......
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