Commit 7f21471f authored by frankiejol's avatar frankiejol
Browse files

refactor(test): skip non-root test

parent d1d7184c
...@@ -98,6 +98,9 @@ $DIR_SQL = "/usr/share/doc/ravada/sql/mysql" if ! -e $DIR_SQL; ...@@ -98,6 +98,9 @@ $DIR_SQL = "/usr/share/doc/ravada/sql/mysql" if ! -e $DIR_SQL;
our $USER_DAEMON; our $USER_DAEMON;
our $USER_DAEMON_NAME = 'daemon'; our $USER_DAEMON_NAME = 'daemon';
our $FIRST_TIME_RUN = 1;
$FIRST_TIME_RUN = 0 if $0 =~ /\.t$/;
has 'connector' => ( has 'connector' => (
is => 'rw' is => 'rw'
); );
...@@ -146,6 +149,7 @@ sub _install($self) { ...@@ -146,6 +149,7 @@ sub _install($self) {
$self->_update_data(); $self->_update_data();
$self->_init_user_daemon(); $self->_init_user_daemon();
$self->_sql_insert_defaults(); $self->_sql_insert_defaults();
print "\n" if $FIRST_TIME_RUN;
} }
sub _init_user_daemon { sub _init_user_daemon {
...@@ -574,7 +578,7 @@ sub _update_isos { ...@@ -574,7 +578,7 @@ sub _update_isos {
sub _scheduled_fedora_releases($self,$data) { sub _scheduled_fedora_releases($self,$data) {
return if !exists $VALID_VM{KVM} ||!$VALID_VM{KVM}; return if !exists $VALID_VM{KVM} ||!$VALID_VM{KVM} || $>;
my $vm = $self->search_vm('KVM') or return; # TODO move ISO downloads off KVM my $vm = $self->search_vm('KVM') or return; # TODO move ISO downloads off KVM
my @now = localtime(time); my @now = localtime(time);
...@@ -869,7 +873,8 @@ sub _update_table($self, $table, $field, $data, $verbose=0) { ...@@ -869,7 +873,8 @@ sub _update_table($self, $table, $field, $data, $verbose=0) {
warn("INFO: $table : $row->{$field} already added.\n") if $verbose; warn("INFO: $table : $row->{$field} already added.\n") if $verbose;
next; next;
} }
warn("INFO: updating $table : $row->{$field}\n") if $0 !~ /\.t$/; warn("INFO: updating $table : $row->{$field}\n")
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
my $sql = my $sql =
"INSERT INTO $table " "INSERT INTO $table "
...@@ -983,7 +988,10 @@ sub _add_indexes_generic($self) { ...@@ -983,7 +988,10 @@ sub _add_indexes_generic($self) {
$type .=" INDEX " if $type=~ /^unique/i; $type .=" INDEX " if $type=~ /^unique/i;
my $sql = "CREATE $type $if_not_exists $name on $table ($fields)"; my $sql = "CREATE $type $if_not_exists $name on $table ($fields)";
warn "INFO: Adding index to $table: $name" if $0 !~ /\.t$/; warn "INFO: Adding index to $table: $name"
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
print "+" if $FIRST_TIME_RUN;
my $sth = $CONNECTOR->dbh->prepare($sql); my $sth = $CONNECTOR->dbh->prepare($sql);
$sth->execute(); $sth->execute();
} }
...@@ -1204,7 +1212,8 @@ sub _upgrade_table { ...@@ -1204,7 +1212,8 @@ sub _upgrade_table {
warn "INFO: changing $field\n" warn "INFO: changing $field\n"
." $row->{COLUMN_SIZE} to ".($new_size or '')."\n" ." $row->{COLUMN_SIZE} to ".($new_size or '')."\n"
." $row->{TYPE_NAME} -> $new_type \n" ." $row->{TYPE_NAME} -> $new_type \n"
." in $table\n$definition\n" if $0 !~ /\.t$/; ." in $table\n$definition\n" if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
print "-" if $FIRST_TIME_RUN;
$dbh->do("alter table $table change $field $field $definition"); $dbh->do("alter table $table change $field $field $definition");
return; return;
} }
...@@ -1216,11 +1225,14 @@ sub _upgrade_table { ...@@ -1216,11 +1225,14 @@ sub _upgrade_table {
$definition =~ s/DEFAULT.*ON UPDATE(.*)//i; $definition =~ s/DEFAULT.*ON UPDATE(.*)//i;
$sqlite_trigger = $1; $sqlite_trigger = $1;
} }
warn "INFO: adding $field $definition to $table\n" if $0 !~ /\.t$/; warn "INFO: adding $field $definition to $table\n"
if!$FIRST_TIME_RUN && $0 !~ /\.t$/;
$dbh->do("alter table $table add $field $definition"); $dbh->do("alter table $table add $field $definition");
if ( $sqlite_trigger && !$self->_exists_trigger($dbh, "Update$field") ) { if ( $sqlite_trigger && !$self->_exists_trigger($dbh, "Update$field") ) {
$self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger); $self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger);
} }
print "-" if $FIRST_TIME_RUN;
return 1; return 1;
} }
...@@ -1259,7 +1271,9 @@ sub _remove_field { ...@@ -1259,7 +1271,9 @@ sub _remove_field {
$sth->finish; $sth->finish;
return if !$row; return if !$row;
warn "INFO: removing $field to $table\n" if $0 !~ /\.t$/; warn "INFO: removing $field to $table\n"
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
$dbh->do("alter table $table drop column $field"); $dbh->do("alter table $table drop column $field");
return 1; return 1;
...@@ -1274,7 +1288,10 @@ sub _create_table { ...@@ -1274,7 +1288,10 @@ sub _create_table {
$sth->finish; $sth->finish;
return if keys %$info; return if keys %$info;
warn "INFO: creating table $table\n" if $0 !~ /\.t$/; warn "INFO: creating table $table\n"
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
print "." if $FIRST_TIME_RUN;
my $file_sql = "$DIR_SQL/$table.sql"; my $file_sql = "$DIR_SQL/$table.sql";
open my $in,'<',$file_sql or die "$! $file_sql"; open my $in,'<',$file_sql or die "$! $file_sql";
...@@ -1292,7 +1309,9 @@ sub _insert_data { ...@@ -1292,7 +1309,9 @@ sub _insert_data {
my $file_sql = "$DIR_SQL/../data/insert_$table.sql"; my $file_sql = "$DIR_SQL/../data/insert_$table.sql";
return if ! -e $file_sql; return if ! -e $file_sql;
warn "INFO: inserting data for $table\n"; warn "INFO: inserting data for $table\n"
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
open my $in,'<',$file_sql or die "$! $file_sql"; open my $in,'<',$file_sql or die "$! $file_sql";
my $sql = ''; my $sql = '';
while (my $line = <$in>) { while (my $line = <$in>) {
...@@ -1323,6 +1342,7 @@ sub _create_tables { ...@@ -1323,6 +1342,7 @@ sub _create_tables {
} }
sub _sql_create_tables($self) { sub _sql_create_tables($self) {
my $created = 0;
my $driver = lc($CONNECTOR->dbh->{Driver}{Name}); my $driver = lc($CONNECTOR->dbh->{Driver}{Name});
my %tables = ( my %tables = (
settings => { settings => {
...@@ -1336,9 +1356,14 @@ sub _sql_create_tables($self) { ...@@ -1336,9 +1356,14 @@ sub _sql_create_tables($self) {
my $sth = $CONNECTOR->dbh->table_info('%',undef,$table,'TABLE'); my $sth = $CONNECTOR->dbh->table_info('%',undef,$table,'TABLE');
my $info = $sth->fetchrow_hashref(); my $info = $sth->fetchrow_hashref();
$sth->finish; $sth->finish;
next if keys %$info; if ( keys %$info ) {
$FIRST_TIME_RUN = 0;
next;
}
warn "INFO: creating table $table\n" if $0 !~ /\.t$/; print "Installing " if !$created && $FIRST_TIME_RUN;
warn "INFO: creating table $table\n"
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
my $sql_fields; my $sql_fields;
for my $field (sort keys %{$tables{$table}} ) { for my $field (sort keys %{$tables{$table}} ) {
...@@ -1349,8 +1374,9 @@ sub _sql_create_tables($self) { ...@@ -1349,8 +1374,9 @@ sub _sql_create_tables($self) {
my $sql = "CREATE TABLE $table ( $sql_fields )"; my $sql = "CREATE TABLE $table ( $sql_fields )";
$CONNECTOR->dbh->do($sql); $CONNECTOR->dbh->do($sql);
$created++;
} }
return $created;
} }
sub _sql_insert_defaults($self){ sub _sql_insert_defaults($self){
...@@ -1442,7 +1468,10 @@ sub _sql_insert_defaults($self){ ...@@ -1442,7 +1468,10 @@ sub _sql_insert_defaults($self){
$sth->execute($entry->{$field{$table}}); $sth->execute($entry->{$field{$table}});
my ($found) = $sth->fetchrow; my ($found) = $sth->fetchrow;
next if $found; next if $found;
warn "INFO adding default $table ".Dumper($entry) if $0 !~ /t$/;
warn "INFO: adding default $table ".Dumper($entry)
if !$FIRST_TIME_RUN && $0 !~ /\.t$/;
$self->_sql_insert_values($table, $entry); $self->_sql_insert_values($table, $entry);
} }
} }
......
...@@ -4012,7 +4012,7 @@ sub rsync($self, @args) { ...@@ -4012,7 +4012,7 @@ sub rsync($self, @args) {
my $msg = $self->_msg_log_rsync($file, $node, "rsync", $request); my $msg = $self->_msg_log_rsync($file, $node, "rsync", $request);
$request->status("syncing") if $request; $request->status("syncing") if $request;
$request->error("Syncing $file"); $request->error("Syncing $file") if $request;
$request->error($msg) if $request && $DEBUG_RSYNC; $request->error($msg) if $request && $DEBUG_RSYNC;
warn "$msg\n" if $DEBUG_RSYNC; warn "$msg\n" if $DEBUG_RSYNC;
...@@ -4029,7 +4029,7 @@ sub rsync($self, @args) { ...@@ -4029,7 +4029,7 @@ sub rsync($self, @args) {
.Dumper($files)."\n" .Dumper($files)."\n"
.join(' ',@{$rsync->err}); .join(' ',@{$rsync->err});
} }
$request->error("rsync done ".(time - $time_rsync)." seconds"); $request->error("rsync done ".(time - $time_rsync)." seconds") if $request;
$node->refresh_storage_pools(); $node->refresh_storage_pools();
} }
......
...@@ -46,6 +46,12 @@ sub test_create_domain { ...@@ -46,6 +46,12 @@ sub test_create_domain {
######################################################################### #########################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
my $vm_name = 'KVM'; my $vm_name = 'KVM';
......
...@@ -28,6 +28,11 @@ sub test_get_cpu_usage { ...@@ -28,6 +28,11 @@ sub test_get_cpu_usage {
} }
#################################################################################### ####################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
......
...@@ -1129,7 +1129,7 @@ clean_remote() if !$>; ...@@ -1129,7 +1129,7 @@ clean_remote() if !$>;
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024; $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ('KVM', 'Void') { for my $vm_name ( vm_names() ) {
my $vm; my $vm;
eval { $vm = rvd_back->search_vm($vm_name) }; eval { $vm = rvd_back->search_vm($vm_name) };
......
...@@ -12,8 +12,6 @@ use Test::Ravada; ...@@ -12,8 +12,6 @@ use Test::Ravada;
no warnings "experimental::signatures"; no warnings "experimental::signatures";
use feature qw(signatures); use feature qw(signatures);
use_ok('Ravada');
init(); init();
####################################################################### #######################################################################
...@@ -89,7 +87,7 @@ sub _hibernate_domain($domain) { ...@@ -89,7 +87,7 @@ sub _hibernate_domain($domain) {
clean(); clean();
clean_remote() if !$>; clean_remote() if !$>;
for my $vm_name ('Void' , 'KVM' ) { for my $vm_name ( vm_names() ) {
my $vm; my $vm;
eval { $vm = rvd_back->search_vm($vm_name) }; eval { $vm = rvd_back->search_vm($vm_name) };
......
...@@ -356,6 +356,13 @@ sub test_reopen { ...@@ -356,6 +356,13 @@ sub test_reopen {
####################################################### #######################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
my $vm_name = 'KVM'; my $vm_name = 'KVM';
......
...@@ -122,6 +122,11 @@ sub _set_raw_volume { ...@@ -122,6 +122,11 @@ sub _set_raw_volume {
} }
##################################################################### #####################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
...@@ -131,10 +136,6 @@ for my $vm_name ('KVM') { ...@@ -131,10 +136,6 @@ for my $vm_name ('KVM') {
my $vm = rvd_back->search_vm($vm_name); my $vm = rvd_back->search_vm($vm_name);
my $msg = "SKIPPED: No virtual managers found"; my $msg = "SKIPPED: No virtual managers found";
if ($vm && $vm_name =~ /kvm/i && $>) {
$msg = "SKIPPED: Test must run as root";
$vm = undef;
}
skip($msg,10) if !$vm; skip($msg,10) if !$vm;
......
...@@ -40,6 +40,12 @@ sub test_spice { ...@@ -40,6 +40,12 @@ sub test_spice {
####################################################### #######################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
my $vm_name = 'KVM'; my $vm_name = 'KVM';
......
...@@ -52,6 +52,12 @@ sub test_sysinfo($domain, $domain_name=$domain->name) { ...@@ -52,6 +52,12 @@ sub test_sysinfo($domain, $domain_name=$domain->name) {
###################################################################################3 ###################################################################################3
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
init(); init();
clean(); clean();
......
...@@ -77,7 +77,8 @@ sub test_tls { ...@@ -77,7 +77,8 @@ sub test_tls {
clean(); clean();
my $vm_name = 'KVM'; my $vm_name = 'KVM';
my $vm = rvd_back->search_vm($vm_name); my $vm;
$vm = rvd_back->search_vm($vm_name) if !$>;
SKIP: { SKIP: {
......
...@@ -1155,14 +1155,14 @@ sub test_migrate_req($vm, $node) { ...@@ -1155,14 +1155,14 @@ sub test_migrate_req($vm, $node) {
, retry => 10 , retry => 10
); );
for ( 1 .. 30 ) { for ( 1 .. 30 ) {
wait_request( debug => 1, check_error => 0); wait_request( debug => 0, check_error => 0);
is($req->status,'done'); is($req->status,'done');
last if !$req->error; last if !$req->error;
diag($req->status); diag($req->status);
diag($req->error." try : ".$req->retry); diag($req->error." try : ".$req->retry);
sleep 1; sleep 1;
} }
is($req->error,'') or exit; like($req->error,qr(^$|seconds)) or exit;
my $domain3 = Ravada::Domain->open($domain->id); my $domain3 = Ravada::Domain->open($domain->id);
is($domain3->is_active,1); is($domain3->is_active,1);
...@@ -1265,6 +1265,13 @@ sub test_nat($vm, $node, $set_localhost_natip=0) { ...@@ -1265,6 +1265,13 @@ sub test_nat($vm, $node, $set_localhost_natip=0) {
} }
################################################################################## ##################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024; $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
......
...@@ -119,11 +119,17 @@ sub test_disabled_node($vm, $node) { ...@@ -119,11 +119,17 @@ sub test_disabled_node($vm, $node) {
} }
################################################################################## ##################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024; $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ( 'KVM', 'Void') { for my $vm_name ( vm_names() ) {
my $vm; my $vm;
eval { $vm = rvd_back->search_vm($vm_name) }; eval { $vm = rvd_back->search_vm($vm_name) };
......
...@@ -63,11 +63,17 @@ sub test_disable_node($vm, $node) { ...@@ -63,11 +63,17 @@ sub test_disable_node($vm, $node) {
} }
################################################################################## ##################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean(); clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024; $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ( 'KVM', 'Void') { for my $vm_name ( vm_names() ) {
my $vm; my $vm;
eval { $vm = rvd_back->search_vm($vm_name) }; eval { $vm = rvd_back->search_vm($vm_name) };
......
...@@ -12,9 +12,19 @@ use Test::Ravada; ...@@ -12,9 +12,19 @@ use Test::Ravada;
no warnings "experimental::signatures"; no warnings "experimental::signatures";
use feature qw(signatures); use feature qw(signatures);
init();
################################################################## ##################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
SKIP: {
skip($msg,10);
}
done_testing();
exit;
}
init();
for my $vm_name ( 'KVM') { for my $vm_name ( 'KVM') {
my $vm; my $vm;
......
...@@ -66,6 +66,16 @@ sub test_fail_different_storage_pools($node) { ...@@ -66,6 +66,16 @@ sub test_fail_different_storage_pools($node) {
} }
################################################################################## ##################################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
SKIP: {
skip($msg,10);
}
done_testing();
exit;
}
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024; $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
......
...@@ -76,6 +76,15 @@ sub test_remove($vm, $node1, $node2) { ...@@ -76,6 +76,15 @@ sub test_remove($vm, $node1, $node2) {
} }
################################################################################## ##################################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
SKIP:{
skip($msg,10);
}
done_testing();
exit;
}
clean(); clean();
......
...@@ -201,6 +201,15 @@ sub test_change_hardware($vm, @nodes) { ...@@ -201,6 +201,15 @@ sub test_change_hardware($vm, @nodes) {
} }
################################################################################## ##################################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);