Commit 8ffca991 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

test: allow test to connect to the MySQL DB

issue #1137
parent 13b40a7b
......@@ -102,8 +102,16 @@ sub user_admin {
my $admin_name = base_domain_name();
my $admin_pass = "$$ $$";
eval {
$login = Ravada::Auth::SQL->new(name => $admin_name );
$login = Ravada::Auth::SQL->new(name => $admin_name, password => $admin_pass );
};
warn $@ if $@;
if ($@ && $@ =~ /Login failed/ ) {
$login = Ravada::Auth::SQL->new(name => $admin_name);
$login->remove();
$login = undef;
} elsif ($@) {
die $@;
}
$USER_ADMIN = $login if $login && $login->id;
$USER_ADMIN = create_user($admin_name, $admin_pass,1)
if !$USER_ADMIN;
......@@ -226,19 +234,22 @@ sub new_volume_name($domain=undef) {
return $name."_".$CONT_VOL++;
}
sub rvd_back($config=undef, $init=1) {
sub rvd_back($config=undef, $init=1, $sqlite=1) {
return $RVD_BACK if $RVD_BACK && !$config;
$RVD_BACK = 1;
init($config or $DEFAULT_CONFIG) if $init;
my @connector;
@connector = ( connector => connector() ) if $sqlite;
my $rvd = Ravada->new(
connector => connector()
@connector
, config => ( $config or $DEFAULT_CONFIG)
, warn_error => 1
);
$rvd->_install();
$CONNECTOR = $rvd->connector if !$sqlite;
user_admin();
$RVD_BACK = $rvd;
......@@ -259,7 +270,7 @@ sub rvd_front($config=undef) {
return $RVD_FRONT;
}
sub init($config=undef) {
sub init($config=undef, $sqlite = 1) {
if ($config && ! ref($config) && $config =~ /[A-Z][a-z]+$/) {
$config = { vm => [ $config ] };
......@@ -279,12 +290,17 @@ sub init($config=undef) {
DumpFile($FILE_CONFIG_TMP, $config) if $config && ref($config);
}
$Ravada::CONNECTOR = connector();
Ravada::Auth::SQL::_init_connector($CONNECTOR);
rvd_back($config, 0,$sqlite) if !$RVD_BACK;
if (!$sqlite) {
$CONNECTOR = $RVD_BACK->connector;
} else {
$Ravada::CONNECTOR = connector();
Ravada::Auth::SQL::_init_connector($CONNECTOR);
}
$Ravada::Domain::MIN_FREE_MEMORY = 512*1024;
rvd_back($config, 0) if !$RVD_BACK;
rvd_front($config) if !$RVD_FRONT;
$Ravada::VM::KVM::VERIFY_ISO = 0;
}
......@@ -639,6 +655,7 @@ sub wait_request {
my $skip = ( delete $args{skip} or [] );
$skip = [ $skip ] if !ref($skip);
my %skip = map { $_ => 1 } @$skip;
%skip = ( enforce_limits => 1 ) if !keys %skip;
my $check_error = delete $args{check_error};
$check_error = 1 if !defined $check_error;
......@@ -657,6 +674,7 @@ sub wait_request {
my $req = Ravada::Request->open($req_id);
next if $skip{$req->command};
if ( $req->status ne 'done' ) {
confess if $req->command eq 'enforce_limits';
diag("Waiting for request ".$req->id." ".$req->command) if $debug;
$done_all = 0;
} elsif (!$done{$req->id}) {
......@@ -668,6 +686,8 @@ sub wait_request {
$post = '' if !defined $post;
if ( $done_all ) {
for my $req (@$request) {
next if $skip{$req->command};
confess if $req->command eq 'enforce_limits';
if ($req->status ne 'done') {
$done_all = 0;
diag("Waiting for request ".$req->id." ".$req->command);
......
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