Commit f0d7efca authored by Francesc Guasch's avatar Francesc Guasch Committed by Fernando Verdugo
Browse files

Refactor #264 sqldata (#892)

* wip(test): do not use Test::SQL::Data

issue #264

* wip(tests): fixed missing connector

issue #264

* refactor(iptables): only run iptables from root

issue #264

* wip(test): init db

issue #264

* wip(test): store void machines in per-user dir

This way root and non-root tests won't have access problems.

issue #264

* wip(test): Test::SQL::Data no longer a requirement

issue #264

* wip(test): Test::SQL::Data no longer required
parent 43b6a395
......@@ -29,8 +29,7 @@ WriteMakefile(
,'Net::DNS' => 0
},
BUILD_REQUIRES => {
'Test::SQL::Data' => 0
,'Test::Perl::Critic' => 0
'Test::Perl::Critic' => 0
},
test => {TESTS => 't/*.t t/*/*.t'},
......
......@@ -1501,7 +1501,6 @@ sub add_volume_swap {
sub _remove_iptables {
my $self = shift;
return if $>;
my %args = @_;
......@@ -1525,7 +1524,7 @@ sub _remove_iptables {
for my $row (@iptables) {
my ($id, $iptables) = @$row;
$ipt_obj->delete_ip_rule(@$iptables);
$ipt_obj->delete_ip_rule(@$iptables) if !$>;
$sth->execute(Ravada::Utils::now(), $id);
}
}
......@@ -1637,7 +1636,8 @@ sub _add_iptable {
,$local_ip, 'filter', $IPTABLES_CHAIN, 'ACCEPT',
,{'protocol' => 'tcp', 's_port' => 0, 'd_port' => $local_port});
my ($rv, $out_ar, $errs_ar) = $ipt_obj->append_ip_rule(@iptables_arg);
my ($rv, $out_ar, $errs_ar);
($rv, $out_ar, $errs_ar) = $ipt_obj->append_ip_rule(@iptables_arg) if !$>;
$self->_log_iptable(iptables => \@iptables_arg, @_);
......@@ -1743,7 +1743,7 @@ sub _obj_iptables($create_chain=1) {
}
confess $error if $error;
return $ipt_obj if !$create_chain;
return $ipt_obj if !$create_chain || $>;
my $rv = 0;
my $out_ar = [];
my $errs_ar = [];
......
......@@ -27,7 +27,7 @@ has '_ip' => (
,default => sub { return '1.1.1.'.int rand(255)}
);
our $DIR_TMP = "/var/tmp/rvd_void";
our $DIR_TMP = Ravada::Front::Domain::Void::_config_dir();
our $CONVERT = `which convert`;
chomp $CONVERT;
......
......@@ -5,7 +5,7 @@ use YAML qw(LoadFile);
extends 'Ravada::Front::Domain';
my $DIR_TMP = "/var/tmp/rvd_void";
my $DIR_TMP = "/var/tmp/rvd_void/".getpwuid($>);
our %GET_CONTROLLER_SUB = (
'mock' => \&_get_controller_mock
......@@ -38,6 +38,8 @@ sub _config_file {
return "$DIR_TMP/".$self->name.".yml";
}
sub _config_dir { return $DIR_TMP }
sub list_controllers {
return %GET_CONTROLLER_SUB;
}
......
......@@ -2,17 +2,15 @@ use warnings;
use strict;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
ok(! $Ravada::CONNECTOR, "DB connector should be undef at load time");
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $ravada = Ravada->new( connector => $test->connector
, config => 't/etc/ravada.conf'
, warn_error => 0
);
my $ravada = rvd_back();
ok($Ravada::CONNECTOR, "Now we should have a DB connector ");
......@@ -21,13 +19,13 @@ eval { ok($Ravada::CONNECTOR->dbh,"No dbh defined ") };
eval {
my $config_err = "t/etc/ravada_miss.conf";
my $rvd_err = Ravada->new( connector => $test->connector, config => $config_err);
my $rvd_err = Ravada->new( connector => connector(), config => $config_err);
};
like($@,qr/Missing config file/);
eval {
my $config_err = "t/etc/ravada_err.conf";
my $rvd_err = Ravada->new( connector => $test->connector, config => $config_err);
my $rvd_err = Ravada->new( connector => connector(), config => $config_err);
};
like($@,qr/Format error/);
......
......@@ -2,17 +2,15 @@ use warnings;
use strict;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
use_ok('Ravada::VM');
init($test->connector, 't/etc/ravada_vm.conf');
init();
ok(rvd_back);
isa_ok(rvd_back,'Ravada');
done_testing();
......@@ -3,16 +3,13 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
use_ok('Ravada::VM');
init($test->connector, 't/etc/ravada_vm_void.conf');
init('t/etc/ravada_vm_void.conf');
ok(rvd_back);
......
......@@ -6,7 +6,6 @@ use Data::Dumper;
use POSIX qw(WNOHANG);
use Test::Moose::More;
use Test::More;# tests => 82;
use Test::SQL::Data;
use_ok('Ravada');
use_ok('Ravada::Request');
......@@ -14,14 +13,12 @@ use_ok('Ravada::Request');
use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $ravada;
my ($DOMAIN_NAME) = $0 =~ m{.*/(.*)\.};
my $DOMAIN_NAME_SON=$DOMAIN_NAME."_son";
init($test->connector, 't/etc/ravada.conf');
init();
my $RVD_BACK = rvd_back();# $test->connector , 't/etc/ravada.conf');
my $USER = create_user("foo","bar", 1);
......
......@@ -4,7 +4,6 @@ use strict;
use Carp qw(confess);
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use_ok('Ravada');
use_ok('Ravada::Request');
......@@ -12,9 +11,6 @@ use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
init($test->connector, 't/etc/ravada.conf');
my $RAVADA = rvd_back();
my $USER = create_user('foo','bar', 1);
......
......@@ -3,15 +3,14 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
use_ok('Ravada::Auth::SQL');
my $RAVADA = Ravada->new(connector => $test->connector
my $RAVADA = Ravada->new(connector => connector()
, warn_error => 0
, config => 't/etc/ravada.conf'
);
......
......@@ -4,12 +4,13 @@ use strict;
use Data::Dumper;
use IPC::Run3;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $ravada = Ravada->new( connector => $test->connector, config => 't/etc/ravada.conf');
my $ravada = Ravada->new( connector => connector(), config => 't/etc/ravada.conf');
my @images = $ravada->list_images();
......
......@@ -5,7 +5,6 @@ use Data::Dumper;
use IPC::Run3;
use POSIX ":sys_wait_h";
use Test::More;
use Test::SQL::Data;
use XML::LibXML;
use lib 't/lib';
......@@ -14,8 +13,7 @@ use Sys::Statistics::Linux;
use_ok('Ravada');
my $test = Test::SQL::Data->new( config => 't/etc/sql.conf');
my $RVD_BACK = rvd_back( $test->connector , 't/etc/ravada.conf');
my $RVD_BACK = rvd_back( );
my $USER = create_user('foo','bar', 1);
......
......@@ -3,14 +3,14 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
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');
my $ravada = Ravada->new(connector => connector(), config => 't/etc/ravada.conf');
$ravada->_install();
Ravada::Auth::SQL::add_user(name => 'root', password => 'root', is_admin => 1);
......
......@@ -3,18 +3,18 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use YAML qw(LoadFile DumpFile);
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada');
use_ok('Ravada::Auth::LDAP');
my $ADMIN_GROUP = "test.admin.group";
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my ($LDAP_USER , $LDAP_PASS) = ("cn=Directory Manager","saysomething");
init();
my @USERS;
......@@ -41,7 +41,7 @@ sub test_user{
$user_db->remove();
# check for the user in the SQL db, he shouldn't be there
#
my $sth = $test->connector->dbh->prepare("SELECT * FROM users WHERE name=?");
my $sth = connector->dbh->prepare("SELECT * FROM users WHERE name=?");
$sth->execute($name);
my $row = $sth->fetchrow_hashref;
$sth->finish;
......@@ -69,7 +69,7 @@ sub test_user{
"ref should be Ravada::Auth::LDAP , got ".ref($mcnulty_login));
# check for the user in the SQL db
#
$sth = $test->connector->dbh->prepare("SELECT * FROM users WHERE name=?");
$sth = connector->dbh->prepare("SELECT * FROM users WHERE name=?");
$sth->execute($name);
$row = $sth->fetchrow_hashref;
$sth->finish;
......@@ -86,7 +86,7 @@ sub test_user{
eval { $mcnulty2 = Ravada::Auth::LDAP->new(name => $name,password => $password) };
ok($mcnulty2,($@ or "ldap login failed for $name")) or return;
$sth = $test->connector->dbh->prepare("SELECT count(*) FROM users WHERE name=?");
$sth = connector->dbh->prepare("SELECT count(*) FROM users WHERE name=?");
$sth->execute($name);
my ($count) = $sth->fetchrow;
$sth->finish;
......@@ -203,7 +203,7 @@ sub test_user_bind {
my $file_config_bind = "/var/tmp/ravada_test_ldap_bind_$$.conf";
DumpFile($file_config_bind, $config);
my $ravada = Ravada->new(config => $file_config_bind
, connector => $test->connector);
, connector => connector);
Ravada::Auth::LDAP::init();
......@@ -218,7 +218,7 @@ sub test_user_bind {
unlink $file_config_bind;
$ravada = Ravada->new(config => $file_config
, connector => $test->connector);
, connector => connector);
Ravada::Auth::LDAP::_init_ldap_admin();
......@@ -246,7 +246,7 @@ SKIP: {
_init_config($file_config, $with_admin);
my $ravada = Ravada->new(config => $file_config
, connector => $test->connector);
, connector => connector);
my $ldap;
eval { $ldap = Ravada::Auth::LDAP::_init_ldap_admin() };
......
......@@ -5,7 +5,6 @@ use Carp qw(confess);
use Data::Dumper;
use POSIX qw(WNOHANG);
use Test::More;
use Test::SQL::Data;
use_ok('Ravada');
use_ok('Ravada::Network');
......@@ -13,10 +12,8 @@ use_ok('Ravada::Network');
use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $rvd_back = rvd_back( $test->connector , 't/etc/ravada.conf');
my $RVD_FRONT = rvd_front( $test->connector , 't/etc/ravada.conf');
my $rvd_back = rvd_back('t/etc/ravada.conf');
my $RVD_FRONT = rvd_front();
my $vm = $rvd_back->search_vm('Void');
my $USER = create_user('foo','bar', 1);
......@@ -30,7 +27,7 @@ sub test_allow_all {
my $net = Ravada::Network->new(address => $ip);
ok(!$net->allowed($domain->id),"Expecting not allowed from unknown network");
my $sth = $test->dbh->prepare("INSERT INTO networks (name,address,all_domains) "
my $sth = connector->dbh->prepare("INSERT INTO networks (name,address,all_domains) "
." VALUES (?,?,?) ");
$sth->execute('foo', '192.168.1.0/24', 1);
......@@ -64,7 +61,7 @@ sub test_allow_domain {
}
my $sth = $test->dbh->prepare("INSERT INTO networks "
my $sth = connector->dbh->prepare("INSERT INTO networks "
." (id, name,address,all_domains, no_domains) "
." VALUES (?,?,?,?,?) ");
......@@ -72,7 +69,7 @@ sub test_allow_domain {
$sth->execute($id_network,'foo', '10.1.1.0/24', 0,0);
$sth->finish;
$sth = $test->dbh->prepare("INSERT INTO domains_network "
$sth = connector->dbh->prepare("INSERT INTO domains_network "
." (id_domain, id_network, allowed)"
." VALUES (?,?,?) ");
......@@ -89,7 +86,7 @@ sub test_allow_domain {
ok(!$n_found, "Expecting 0 anon bases, got '$n_found'");
}
$sth = $test->dbh->prepare("UPDATE domains_network "
$sth = connector->dbh->prepare("UPDATE domains_network "
." SET allowed=0 "
." WHERE id_domain=? AND id_network=?");
......@@ -105,7 +102,7 @@ sub test_allow_domain {
ok(!$n_found, "Expecting 0 anon bases, got '$n_found'");
}
$sth = $test->dbh->prepare("UPDATE domains_network "
$sth = connector->dbh->prepare("UPDATE domains_network "
." SET allowed=0, anonymous=1 "
." WHERE id_domain=? AND id_network=?");
$sth->execute($domain->id, $id_network);
......@@ -121,7 +118,7 @@ sub test_allow_domain {
ok(!$n_found, "Expecting 0 anon bases, got '$n_found'");
}
$sth = $test->dbh->prepare("UPDATE domains_network "
$sth = connector->dbh->prepare("UPDATE domains_network "
." SET allowed=1, anonymous=1 "
." WHERE id_domain=? AND id_network=?");
$sth->execute($domain->id, $id_network);
......@@ -154,7 +151,7 @@ sub test_deny_all {
ok(!$n_found, "Expecting 0 anon bases, got '$n_found'");
}
my $sth = $test->dbh->prepare("INSERT INTO networks (name,address,no_domains) "
my $sth = connector->dbh->prepare("INSERT INTO networks (name,address,no_domains) "
." VALUES (?,?,?) ");
$sth->execute('bar', '10.0.0.0/16', 1);
......@@ -172,7 +169,7 @@ sub test_deny_all {
}
sub deny_everything_any {
my $sth = $test->dbh->prepare(
my $sth = connector->dbh->prepare(
"UPDATE networks set all_domains=0 where address='0.0.0.0/0'"
);
$sth->execute;
......
......@@ -3,7 +3,6 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
......@@ -11,9 +10,7 @@ use Test::Ravada;
use_ok('Ravada');
use_ok('Ravada::Front');
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
init($test->connector , 't/etc/ravada.conf');
init();
my $USER = create_user('foo','bar', 1);
my $RVD_BACK = rvd_back( );
......@@ -59,7 +56,7 @@ sub test_add_domain_db {
ok($bases,"No bases list returned");
ok(scalar @$bases == 0, "There should be no bases");
$test->dbh->do("UPDATE DOMAINS set is_base=1,is_public=1 WHERE name='$domain_name'");
connector->dbh->do("UPDATE DOMAINS set is_base=1,is_public=1 WHERE name='$domain_name'");
$bases = $RVD_FRONT->list_bases();
ok($bases,"No bases list returned");
......
......@@ -3,23 +3,20 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada::Front');
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $CONFIG_FILE = 't/etc/ravada.conf';
my @rvd_args = (
config => $CONFIG_FILE
,connector => $test->connector
,connector => connector
);
my $RVD_BACK = rvd_back( $test->connector, $CONFIG_FILE);
my $RVD_BACK = rvd_back( );
my $RVD_FRONT = Ravada::Front->new( @rvd_args
, backend => $RVD_BACK
);
......@@ -45,7 +42,7 @@ sub create_args {
sub search_domain_db
{
my $name = shift;
my $sth = $test->dbh->prepare("SELECT * FROM domains WHERE name=? ");
my $sth = connector->dbh->prepare("SELECT * FROM domains WHERE name=? ");
$sth->execute($name);
my $row = $sth->fetchrow_hashref;
return $row;
......@@ -82,7 +79,7 @@ sub test_domain_name {
my $vm_name = shift;
my $domain = create_domain($vm_name);
my $sth = $test->connector->dbh->prepare("DELETE FROM domains WHERE id=?");
my $sth = connector->dbh->prepare("DELETE FROM domains WHERE id=?");
$sth->execute($domain->id);
my $id = $domain->id;
......
......@@ -3,7 +3,6 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use XML::LibXML;
......@@ -12,14 +11,12 @@ use Test::Ravada;
use_ok('Ravada::Front');
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $CONFIG_FILE = 't/etc/ravada.conf';
my $RVD_BACK = rvd_back($test->connector , $CONFIG_FILE);
my $RVD_BACK = rvd_back($CONFIG_FILE);
my $RVD_FRONT = Ravada::Front->new(
config => $CONFIG_FILE
, connector => $test->connector
, connector => connector()
, backend => $RVD_BACK
);
......
......@@ -3,21 +3,18 @@ use strict;
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
use_ok('Ravada::Front');
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
my $CONFIG_FILE = 't/etc/ravada.conf';
my $RVD_BACK = rvd_back($test->connector , $CONFIG_FILE);
my $RVD_BACK = rvd_back($CONFIG_FILE);
my $RVD_FRONT = Ravada::Front->new(
config => $CONFIG_FILE
, connector => $test->connector
, connector => connector()
, backend => $RVD_BACK
);
......
......@@ -4,21 +4,18 @@ use strict;
use Carp qw(confess);
use Data::Dumper;
use Test::More;
use Test::SQL::Data;
use lib 't/lib';
use Test::Ravada;
my $test = Test::SQL::Data->new(config => 't/etc/sql.conf');
use_ok('Ravada');
my $FILE_CONFIG = 't/etc/ravada.conf';
my $RVD_BACK = rvd_back($test->connector, $FILE_CONFIG);
my $RVD_FRONT= rvd_front($test->connector, $FILE_CONFIG);
my $RVD_BACK = rvd_back();
my $RVD_FRONT= rvd_front();
my @ARG_RVD = ( config => $FILE_CONFIG, connector => $test->connector);
my @ARG_RVD = ( config => $FILE_CONFIG, connector => connector() );
my @VMS = vm_names();
my $USER = create_user("foo","bar", 1);
......
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