From 62fdcbeaa5db9c2413a61f5f9a82d36835cb70bb Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Mon, 27 Oct 2014 14:05:44 +0100 Subject: controller: better connect with other utilities * controller/bin/dtf-controller.in (subcommand): Generate stdout and stderr files separately. (child_task): Generate '*.err' and '*.out' logs for subcommands. Call dtf-run-remote with --distro/--distro-version options. Call the dtf-result-stats finally and save its output to results.html. (main): Simple debugging info and comment adjusting. * controller/libexec/dtf-commit-results.in: Tak three arguments now. * controller/libexec/dtf-result-stats.in: Better read the 'tester/run' output. * controller/share/dtf-controller/ansible/playbooks/fedora.yml: Run the 'run --force' instead of 'run' on remote host. * controller/share/dtf-controller/results-stats-templates/html.tmpl React on exit_status 2. --- controller/bin/dtf-controller.in | 49 +++++++++++++++------- controller/libexec/dtf-commit-results.in | 9 +++- controller/libexec/dtf-result-stats.in | 21 ++++++---- .../dtf-controller/ansible/playbooks/fedora.yml | 2 +- .../results-stats-templates/html.tmpl | 4 +- 5 files changed, 59 insertions(+), 26 deletions(-) diff --git a/controller/bin/dtf-controller.in b/controller/bin/dtf-controller.in index e8fc5c8..cf78070 100644 --- a/controller/bin/dtf-controller.in +++ b/controller/bin/dtf-controller.in @@ -33,8 +33,17 @@ sub load_runfile sub subcommand { my $cmd = $_[0]; - my $out_file = $_[1] . ".stdout"; - my $err_file = $_[1] . ".stderr"; + my $out_file = "/dev/null"; + my $err_file = "/dev/null"; + + if (defined $_[1]) { + $out_file = $_[1]; + } + if (defined $_[2]) { + $err_file = $_[2]; + } + + print STDERR "running: " . join(' ', @$cmd) . "\n"; my $pid = fork(); if ($pid eq 0) { @@ -58,11 +67,12 @@ sub child_task my $rc = subcommand [ '@bindir@/dtf-run-remote', - '--taskdir', - $run->{taskdir}, - '--workdir', - $dir, - ], "$dir/dtf-run-remote"; + '--taskdir', $run->{taskdir}, + '--workdir', $dir, + '--distro', $run->{distro}, + '--distro-version', $run->{distro_version}, + ], "$dir/dtf-run-remote.out", + "$dir/dtf-run-remote.err"; # Note that the 'dtf-run-remote' must return EXIT_SUCCESS even if some of # its tests failed. @@ -71,19 +81,28 @@ sub child_task exit (1); } - my $resultdir = "$config->{db}/$run->{distro}/" - . "$run->{distro_version}/$run->{arch}/" - . "results_$config->{starttime}-$run->{stamp}"; + my $db = $config->{db}; + my $respath = "$run->{distro}/" + . "$run->{distro_version}/$run->{arch}/"; + my $taskdir = $respath + . "results_$config->{starttime}-$run->{stamp}"; $rc = subcommand [ '@libexecdir@/dtf-commit-results', "$dir", - "$config->{db}/$run->{distro}/$run->{distro_version}/$run->{arch}/", - ], "$resultdir"; + "$taskdir", + "$db" + ]; if ($rc ne 0) { print STDERR "$task: failed dtf-commit-results"; exit (1); } + + subcommand [ + '@libexecdir@/dtf-result-stats', + "$db/$respath", + ], "$db/$respath/results.xml", "$db/$respath/dtf-result-stats.stderr" + and exit(1); } sub main @@ -98,13 +117,15 @@ sub main # dies on error - which is OK my $dir = File::Temp->newdir("/tmp/dtf-controller-XXXXXX", CLEANUP => 0); + print "results into $dir\n"; + ($run->{stamp} = $dir) =~ s/.*-//; my $pid = fork(); if ($pid == 0) { child_task($run, $dir, $config); - ## child ## + ## child's successful run ## exit (0); } else { @@ -123,7 +144,7 @@ sub main $child = waitpid (-1, 0); } while ($child > 0); - print "Finished.."; + print "Finished..\n"; } GetOptions( diff --git a/controller/libexec/dtf-commit-results.in b/controller/libexec/dtf-commit-results.in index 6b33022..b1d5bf2 100644 --- a/controller/libexec/dtf-commit-results.in +++ b/controller/libexec/dtf-commit-results.in @@ -1,12 +1,15 @@ #!/bin/bash +## $ dtf-commit-results RESULTS SUBDIR [ DB ] + . "@sysconfdir@/dtf.sh" || exit 1 # argparse resultdir="$1" +subresultdir="$2" db="$DTF_DATABASE_DEFAULT" -test -n "$2" && db="$2" +test -n "$3" && db="$3" if test -z "$db" \ || test -z "$resultdir" \ @@ -16,4 +19,6 @@ then exit 1 fi -( cd "$resultdir" && tar -xf dtf.tar.gz && cp -r . "$db" ) +mkdir -p "$db/$subresultdir" || exit 1 + +( cd "$resultdir" && tar -xf dtf.tar.gz && cp -r . "$db/$subresultdir" ) diff --git a/controller/libexec/dtf-result-stats.in b/controller/libexec/dtf-result-stats.in index d4db46f..92fd45f 100644 --- a/controller/libexec/dtf-result-stats.in +++ b/controller/libexec/dtf-result-stats.in @@ -44,17 +44,26 @@ my $task_ids = {}; # go through *each* result directory my $olddir = getcwd; -for (`find "$workdir" -maxdepth 1 -type d`) { +for (`find "$workdir" -mindepth 1 -maxdepth 1 -type d | sort`) { chomp; chdir $_; my $run_results = {}; $run_results->{dirname} = basename($_); $run_results->{tasks} = {}; - $run_results->{exit_status} = 0; + + my $glob_result; + my $fdg; + if (not open $fdg, '<', "dtf/result.yml") { + $run_results->{exit_status} = 2; + } + else { + $run_results->{glob} = YAML::Syck::LoadFile($fdg); + $run_results->{exit_status} = $run_results->{glob}->{exit_status}; + } # go through each task - for (`find -maxdepth 1 -type f -name '*.result'`) { + for (`find dtf/tasks -type f -name '*.result'`) { chomp; (my $task_id = $_) =~ s/\.result$//; @@ -65,11 +74,7 @@ for (`find "$workdir" -maxdepth 1 -type d`) { open my $fd, '<', $yaml_file or die "can't open yaml file '$yaml_file'"; - my $config = YAML::Syck::LoadFile($fd); - if ($config->{exit_status} != 0) { - $run_results->{exit_status} = 1; - } - $run_results->{tasks}->{$task_id} = $config; + $run_results->{tasks}->{$task_id} = YAML::Syck::LoadFile($fd); } push @{$data}, $run_results; diff --git a/controller/share/dtf-controller/ansible/playbooks/fedora.yml b/controller/share/dtf-controller/ansible/playbooks/fedora.yml index 7c62f61..1d49671 100644 --- a/controller/share/dtf-controller/ansible/playbooks/fedora.yml +++ b/controller/share/dtf-controller/ansible/playbooks/fedora.yml @@ -44,7 +44,7 @@ - shell: cd /root && tar -xf {{ opt_testsuite_name }}.tar.gz - - shell: cd /root/{{ opt_testsuite_name }}&& ./run &>/var/tmp/dtf-run.overview + - shell: cd /root/{{ opt_testsuite_name }}&& ./run --force &>/var/tmp/dtf-run.overview register: test_result ignore_errors: yes diff --git a/controller/share/dtf-controller/results-stats-templates/html.tmpl b/controller/share/dtf-controller/results-stats-templates/html.tmpl index 8a09ad7..af06322 100644 --- a/controller/share/dtf-controller/results-stats-templates/html.tmpl +++ b/controller/share/dtf-controller/results-stats-templates/html.tmpl @@ -18,7 +18,9 @@ : for $results -> $result { - : if ($result.exit_status) { + : if ($result.exit_status == 0) { + + : } elsif ($result.exit_status == 2) { : } else { -- cgit