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;
our $USER_DAEMON;
our $USER_DAEMON_NAME = 'daemon';
our $FIRST_TIME_RUN = 1;
$FIRST_TIME_RUN = 0 if $0 =~ /\.t$/;
has 'connector' => (
is => 'rw'
);
......@@ -146,6 +149,7 @@ sub _install($self) {
$self->_update_data();
$self->_init_user_daemon();
$self->_sql_insert_defaults();
print "\n" if $FIRST_TIME_RUN;
}
sub _init_user_daemon {
......@@ -574,7 +578,7 @@ sub _update_isos {
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 @now = localtime(time);
......@@ -869,7 +873,8 @@ sub _update_table($self, $table, $field, $data, $verbose=0) {
warn("INFO: $table : $row->{$field} already added.\n") if $verbose;
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 =
"INSERT INTO $table "
......@@ -983,7 +988,10 @@ sub _add_indexes_generic($self) {
$type .=" INDEX " if $type=~ /^unique/i;
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);
$sth->execute();
}
......@@ -1204,7 +1212,8 @@ sub _upgrade_table {
warn "INFO: changing $field\n"
." $row->{COLUMN_SIZE} to ".($new_size or '')."\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");
return;
}
......@@ -1216,11 +1225,14 @@ sub _upgrade_table {
$definition =~ s/DEFAULT.*ON UPDATE(.*)//i;
$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");
if ( $sqlite_trigger && !$self->_exists_trigger($dbh, "Update$field") ) {
$self->_sqlite_trigger($dbh,$table, $field, $sqlite_trigger);
}
print "-" if $FIRST_TIME_RUN;
return 1;
}
......@@ -1259,7 +1271,9 @@ sub _remove_field {
$sth->finish;
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");
return 1;
......@@ -1274,7 +1288,10 @@ sub _create_table {
$sth->finish;
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";
open my $in,'<',$file_sql or die "$! $file_sql";
......@@ -1292,7 +1309,9 @@ sub _insert_data {
my $file_sql = "$DIR_SQL/../data/insert_$table.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";
my $sql = '';
while (my $line = <$in>) {
......@@ -1323,6 +1342,7 @@ sub _create_tables {
}
sub _sql_create_tables($self) {
my $created = 0;
my $driver = lc($CONNECTOR->dbh->{Driver}{Name});
my %tables = (
settings => {
......@@ -1336,9 +1356,14 @@ sub _sql_create_tables($self) {
my $sth = $CONNECTOR->dbh->table_info('%',undef,$table,'TABLE');
my $info = $sth->fetchrow_hashref();
$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;
for my $field (sort keys %{$tables{$table}} ) {
......@@ -1349,8 +1374,9 @@ sub _sql_create_tables($self) {
my $sql = "CREATE TABLE $table ( $sql_fields )";
$CONNECTOR->dbh->do($sql);
$created++;
}
return $created;
}
sub _sql_insert_defaults($self){
......@@ -1442,7 +1468,10 @@ sub _sql_insert_defaults($self){
$sth->execute($entry->{$field{$table}});
my ($found) = $sth->fetchrow;
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);
}
}
......
......@@ -4012,7 +4012,7 @@ sub rsync($self, @args) {
my $msg = $self->_msg_log_rsync($file, $node, "rsync", $request);
$request->status("syncing") if $request;
$request->error("Syncing $file");
$request->error("Syncing $file") if $request;
$request->error($msg) if $request && $DEBUG_RSYNC;
warn "$msg\n" if $DEBUG_RSYNC;
......@@ -4029,7 +4029,7 @@ sub rsync($self, @args) {
.Dumper($files)."\n"
.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();
}
......
......@@ -46,6 +46,12 @@ sub test_create_domain {
#########################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
my $vm_name = 'KVM';
......
......@@ -28,6 +28,11 @@ sub test_get_cpu_usage {
}
####################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
......
......@@ -1129,7 +1129,7 @@ clean_remote() if !$>;
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ('KVM', 'Void') {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -12,8 +12,6 @@ use Test::Ravada;
no warnings "experimental::signatures";
use feature qw(signatures);
use_ok('Ravada');
init();
#######################################################################
......@@ -89,7 +87,7 @@ sub _hibernate_domain($domain) {
clean();
clean_remote() if !$>;
for my $vm_name ('Void' , 'KVM' ) {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -356,6 +356,13 @@ sub test_reopen {
#######################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
my $vm_name = 'KVM';
......
......@@ -122,6 +122,11 @@ sub _set_raw_volume {
}
#####################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
......@@ -131,10 +136,6 @@ for my $vm_name ('KVM') {
my $vm = rvd_back->search_vm($vm_name);
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;
......
......@@ -40,6 +40,12 @@ sub test_spice {
#######################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
my $vm_name = 'KVM';
......
......@@ -52,6 +52,12 @@ sub test_sysinfo($domain, $domain_name=$domain->name) {
###################################################################################3
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
init();
clean();
......
......@@ -77,7 +77,8 @@ sub test_tls {
clean();
my $vm_name = 'KVM';
my $vm = rvd_back->search_vm($vm_name);
my $vm;
$vm = rvd_back->search_vm($vm_name) if !$>;
SKIP: {
......
......@@ -1155,14 +1155,14 @@ sub test_migrate_req($vm, $node) {
, retry => 10
);
for ( 1 .. 30 ) {
wait_request( debug => 1, check_error => 0);
wait_request( debug => 0, check_error => 0);
is($req->status,'done');
last if !$req->error;
diag($req->status);
diag($req->error." try : ".$req->retry);
sleep 1;
}
is($req->error,'') or exit;
like($req->error,qr(^$|seconds)) or exit;
my $domain3 = Ravada::Domain->open($domain->id);
is($domain3->is_active,1);
......@@ -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();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
......
......@@ -119,11 +119,17 @@ sub test_disabled_node($vm, $node) {
}
##################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ( 'KVM', 'Void') {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -63,11 +63,17 @@ sub test_disable_node($vm, $node) {
}
##################################################################################
if ($>) {
diag("SKIPPED: Test must run as root");
done_testing();
exit;
}
clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ( 'KVM', 'Void') {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -12,9 +12,19 @@ use Test::Ravada;
no warnings "experimental::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') {
my $vm;
......
......@@ -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;
......
......@@ -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();
......
......@@ -201,6 +201,15 @@ sub test_change_hardware($vm, @nodes) {
}
##################################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
SKIP:{
skip($msg,10);
}
done_testing();
exit;
}
clean();
......@@ -208,7 +217,7 @@ $Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
my @nodes;
for my $vm_name ( 'Void', 'KVM') {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -72,12 +72,21 @@ sub test_shared($vm, $node) {
}
#################################################################################
if ($>) {
my $msg = "SKIPPED: Test must run as root";
diag($msg);
SKIP:{
skip($msg,10);
}
done_testing();
exit;
}
clean();
$Ravada::Domain::MIN_FREE_MEMORY = 256 * 1024;
for my $vm_name ( 'Void', 'KVM') {
for my $vm_name ( vm_names() ) {
my $vm;
eval { $vm = rvd_back->search_vm($vm_name) };
......
......@@ -76,7 +76,10 @@ sub test_download {
test_insert_locale();
test_insert_request();
test_download('linkat');
SKIP: {
skip("SKIPPED: Test must run as root",8) if $<;
test_download('linkat');
};
end();
done_testing();
......
Markdown is supported
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