Commit 4f7818fa authored by Francesc Guasch's avatar Francesc Guasch
Browse files

refactor(install): install rvd in tests

issue #838
parent a55f95f8
......@@ -81,7 +81,7 @@ our %VALID_ARG = (
,remove_hardware => {uid => 1, id_domain => 1, name => 1, index => 1}
,change_max_memory => {uid => 1, id_domain => 1, ram => 1}
,refresh_vms => { }
,enforce_limits => { timeout => 2 }
,enforce_limits => { timeout => 2, _force => 2 }
);
our %CMD_SEND_MESSAGE = map { $_ => 1 }
......@@ -1148,7 +1148,8 @@ sub remove_base_vm {
}
sub type($self) {
my $command = $self->command;
my $command = $self;
$command = $self->command if ref($self);
for my $type ( keys %COMMAND ) {
return $type if grep /^$command$/, @{$COMMAND{$type}->{commands}};
}
......@@ -1165,11 +1166,14 @@ Returns the number of working requests of the same type
sub count_requests($self) {
my $sth = $$CONNECTOR->dbh->prepare(
"SELECT COUNT(*) FROM requests"
"SELECT command FROM requests"
." WHERE status = 'working' "
);
$sth->execute();
my ($n) = $sth->fetchrow;
my $n = 0;
while ( my $command = $sth->fetchrow ) {
$n++ if type($command) eq $self->type;
}
return $n;
}
......@@ -1325,7 +1329,7 @@ sub enforce_limits {
my $args = _check_args('enforce_limits', @_ );
return if _requested('enforce_limits');
return if !$args->{_force} && _requested('enforce_limits');
$args->{timeout} = $TIMEOUT_SHUTDOWN if !exists $args->{timeout};
my $self = {};
......@@ -1357,6 +1361,7 @@ This method is used for commands that take long to run as garbage collection.
=cut
sub done_recently($self, $seconds=60,$command=undef) {
_init_connector();
my $id_req = 0;
if ($self) {
$id_req = $self->id;
......
......@@ -16,6 +16,8 @@ my $RAVADA = Ravada->new(connector => $test->connector
, config => 't/etc/ravada.conf'
);
$RAVADA->_install();
Ravada::Auth::SQL::add_user(name => 'test',password => $$);
ok($$Ravada::Auth::SQL::CON,"Undefined DB connection");
......
......@@ -11,6 +11,7 @@ use_ok('Ravada::Auth::SQL');
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $ravada = Ravada->new(connector => $test->connector, config => 't/etc/ravada.conf');
$ravada->_install();
Ravada::Auth::SQL::add_user(name => 'root', password => 'root', is_admin => 1);
......
......@@ -40,6 +40,7 @@ sub test_search_vm {
my $RAVADA;
eval {
$RAVADA = Ravada->new(%CONFIG);
$RAVADA->_install();
};
my $err = ($@ or '');
......
......@@ -180,6 +180,7 @@ sub rvd_back {
, config => ( $CONFIG or $DEFAULT_CONFIG)
, warn_error => 0
);
$rvd->_install();
user_admin() if $create_user;
$ARG_CREATE_DOM{KVM} = [ id_iso => search_id_iso('Alpine') ];
......
......@@ -18,6 +18,7 @@ SKIP: {
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $RAVADA= Ravada->new( connector => $test->connector);
$RAVADA->_install();
my $vm_lxc;
......
......@@ -17,6 +17,7 @@ SKIP: {
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $RAVADA= Ravada->new( connector => $test->connector);
$RAVADA->_install();
my $vm_lxc;
my $CONT= 0;
......
......@@ -18,6 +18,7 @@ SKIP: {
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $RAVADA= Ravada->new( connector => $test->connector);
$RAVADA->_install();
my $vm_lxc;
my $CONT= 0;
......
......@@ -482,7 +482,7 @@ sub test_domain_limit_noadmin {
is(rvd_back->list_domains(user => $user, active => 1),1);
$domain2->start( $user );
my $req = Ravada::Request->enforce_limits(timeout => 1);
my $req = Ravada::Request->enforce_limits(timeout => 1, _force => 1);
rvd_back->_process_all_requests_dont_fork();
sleep 1;
rvd_back->_process_all_requests_dont_fork();
......@@ -527,14 +527,14 @@ sub test_domain_limit_already_requested {
is(scalar @list_requests,0,"Expecting 0 requests ".Dumper(\@list_requests));
is(rvd_back->list_domains(user => $user, active => 1),2);
Ravada::Request->enforce_limits(timeout => 1);
rvd_back->_process_all_requests_dont_fork();
sleep 1;
my $req = Ravada::Request->enforce_limits(timeout => 1, _force => 1);
rvd_back->_process_all_requests_dont_fork();
is($req->status,'done');
is($req->error, '');
my @list = rvd_back->list_domains(user => $user, active => 1);
is(scalar @list,1) or die Dumper(\@list);
is(scalar @list,1) or die Dumper([ map { $_->name } @list]);
is($list[0]->name, $domain2->name) if $list[0];
$domain2->remove($user);
......
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