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

create new KVM domain from Front

parent b119d431
......@@ -176,6 +176,7 @@ sub create_domain {
carp "WARNING: no VM defined, we will use ".$vm->name
if !$vm_name;
confess "I can't find any vm ".Dumper($self->vm) if !$vm;
return $vm->create_domain(@_);
}
......@@ -441,12 +442,13 @@ This is run in the ravada backend. It processes the commands requested by the fr
sub process_requests {
my $self = shift;
my $debug = shift;
my $sth = $CONNECTOR->dbh->prepare("SELECT id FROM requests WHERE status='requested'");
$sth->execute;
while (my ($id)= $sth->fetchrow) {
my $req = Ravada::Request->open($id);
warn "executing request ".$req." ".Dumper($req) if $DEBUG;
warn "executing request ".$req." ".Dumper($req) if $DEBUG || $debug;
$self->_execute($req);
warn $req->status() if $DEBUG;
}
......
......@@ -125,7 +125,7 @@ sub wait_request {
my $timeout = ( shift or $TIMEOUT );
$self->backend->process_requests if $self->backend;
$self->backend->process_requests() if $self->backend;
for ( 1 .. $TIMEOUT ) {
last if $req->status eq 'done';
......
......@@ -40,24 +40,90 @@ sub create_args {
die "Unknown backend $backend" if !$CREATE_ARGS{$backend};
return %{$CREATE_ARGS{$backend}};
}
sub remove_old_disks {
my $name = $DOMAIN_NAME;
my $vm = $RVD_BACK->search_vm('kvm');
ok($vm,"I can't find a KVM virtual manager") or return;
my $dir_img = $vm->dir_img();
ok($dir_img," I cant find a dir_img in the KVM virtual manager") or return;
for my $count ( 0 .. 10 ) {
my $disk = $dir_img."/$name"."_$count.img";
if ( -e $disk ) {
unlink $disk or die "I can't remove $disk";
}
}
$vm->storage_pool->refresh();
}
sub remove_old_domains {
for ( 0 .. 10 ) {
my $dom_name = $DOMAIN_NAME."_$_";
my $domain = $RVD_BACK->search_domain($dom_name);
$domain->shutdown_now() if $domain;
test_remove_domain($dom_name);
}
}
sub search_domain_db
{
my $name = shift;
my $sth = $test->dbh->prepare("SELECT * FROM domains WHERE name=? ");
$sth->execute($name);
my $row = $sth->fetchrow_hashref;
return $row;
}
sub test_remove_domain {
my $name = shift;
my $domain;
$domain = $RVD_BACK->search_domain($name,1);
if ($domain) {
diag("Removing domain $name");
$domain->remove();
}
$domain = $RVD_BACK->search_domain($name);
die "I can't remove old domain $name"
if $domain;
ok(!search_domain_db($name),"Domain $name still in db");
}
####################################################################
#
remove_old_domains();
remove_old_disks();
for my $vm_name ('kvm','lxc') {
for my $vm ('kvm','lxc') {
my $vm = $RVD_BACK->search_vm($vm_name);
if (!$vm) {
diag("Skipping VM $vm_name in this system");
next;
}
my $name = _new_name();
my $req = $RVD_FRONT->create_domain( name => $name
, vm => $vm
, create_args($vm)
, vm => $vm_name
, create_args($vm_name)
);
ok($req, "Request $name not created");
$RVD_FRONT->wait_request($req);
ok($req->status eq 'done',"Request for create $vm domain ".$req->status);
ok(!$req->error,$req->error);
my $domain = $RVD_FRONT->search_domain($name);
ok($domain,"Domain $name not found");
ok($domain,"Domain $name not found") or exit;
ok($domain && $domain->{name} &&
$domain->{name} eq $name,"Expecting domain name $name, got "
.($domain->{name} or '<UNDEF>'));
......
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