GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Unverified Commit 3c10e0c5 authored by boklm's avatar boklm

Add mechanism to send and receive reports with ssh

parent 90d1a980
......@@ -116,6 +116,9 @@ Available options
working on a new test and don't want to run all the test suite
to try your new test.
--upload-to=<login@hostname>
Upload the tests reports to select host, with ssh.
Configuration Files
-------------------
......@@ -151,3 +154,18 @@ following actions are available:
list_tests::
List available tests and their descriptions.
send_report::
Upload a report to a remote host. The report name is selected
with the --name option, and the remote host with the --upload-to.
This action is also done as part of run_tests if the --upload-to
option is defined.
receive_report::
Receive a report on stdin. Usually this action is run from an
ssh authorized_keys file.
update_authkeys::
Update the ssh authorized_keys file with users defined in the
'uploaders' option. You need to run this on a user account that
will be receiving tests reports.
......@@ -38,7 +38,7 @@ sub get_options {
my @options = qw(mozmill! selenium! starttor! tor-control-port=i
tor-socks-port=i reports-dir=s gpgcheck! keyring=s
virtualenv=s xvfb! name=s download-dir=s config=s
action=s enable-tests=s);
action=s enable-tests=s upload-to=s);
my (%cli, %config);
Getopt::Long::GetOptionsFromArray(\@_, \%cli, @options) || exit 1;
$cli{args} = \@_ if @_;
......
package TBBTestSuite::Reports::Receive;
use warnings;
use strict;
use YAML qw(LoadFile);
use File::Path qw(make_path);
use File::Temp;
use File::Copy;
use File::Slurp;
use FindBin;
use TBBTestSuite::Common qw(exit_error);
use TBBTestSuite::Options qw($options);
sub receive_report {
my $tmpdir = File::Temp->newdir() || exit_error 'Error creating tmp dir';
chdir $tmpdir || exit_error 'Error entering tmp directory';
system('tar', '-xf', '-') && exit_error 'Error receiving files';
exit_error 'Cannot find report.yml' unless -f 'report.yml';
my $report = LoadFile('report.yml');
chdir '/';
my $name = $report->{options}{name};
if (!$name || $name =~ m/\// || $name =~ m/^\./) {
exit_error 'Invalid report name';
}
exit_error 'Report already exist' if -d "$options->{'reports-dir'}/r/$name";
$tmpdir->unlink_on_destroy(0);
system('mv', $tmpdir, "$options->{'reports-dir'}/r/$name");
}
sub update_authkeys {
my $sshdir = "$ENV{HOME}/.ssh";
if (!-d $sshdir) {
make_path($sshdir);
chmod 0700, $sshdir;
}
my $new_authkeys = '';
my $config = $options->{config} ? " --config=$options->{config}" : '';
foreach my $uploader (sort keys %{$options->{uploaders}}) {
my $key = $options->{uploaders}{$uploader}{key};
$new_authkeys .= "command=\"$FindBin::Bin/tbb-testsuite --action "
. "receive_report$config\",no-X11-forwarding,"
. "no-agent-forwarding,no-port-forwarding $key $uploader\n";
}
my $authkeys_file = "$sshdir/authorized_keys";
my $old_authkeys = -f $authkeys_file ? read_file($authkeys_file) : '';
write_file($authkeys_file, $new_authkeys) if $old_authkeys ne $new_authkeys;
chmod 0600, $authkeys_file;
}
1;
package TBBTestSuite::Reports::Send;
use warnings;
use strict;
use TBBTestSuite::Common qw(exit_error);
use TBBTestSuite::Options qw($options);
sub send_report {
exit_error 'No report name specified' unless $options->{name};
exit_error 'No destination specified' unless $options->{'upload-to'};
my $report_dir = "$options->{'reports-dir'}/r/$options->{name}";
chdir $report_dir || exit_error 'Error accessing report dir';
system("tar cf - . | ssh -T $options->{'upload-to'}");
}
1;
......@@ -8,6 +8,8 @@ use YAML;
use TBBTestSuite::Common qw(exit_error run_alone rm_pidfile);
use TBBTestSuite::Options qw($options);
use TBBTestSuite::Reports;
use TBBTestSuite::Reports::Receive;
use TBBTestSuite::Reports::Send;
use TBBTestSuite::Tests;
sub run_tests {
......@@ -27,6 +29,7 @@ sub run_tests {
YAML::DumpFile("$options->{'report-dir'}/report.yml", $report);
TBBTestSuite::Reports::make_report($report);
TBBTestSuite::Reports::make_reports_index;
TBBTestSuite::Reports::Send::send_report if $options->{'upload-to'};
}
sub make_report {
......@@ -38,11 +41,19 @@ sub make_report {
TBBTestSuite::Reports::make_report($report);
}
sub receive_report {
TBBTestSuite::Reports::Receive::receive_report;
TBBTestSuite::Reports::make_reports_index;
}
my %actions = (
run_tests => \&run_tests,
list_tests => \&TBBTestSuite::Tests::list_tests,
reports_index => \&TBBTestSuite::Reports::make_reports_index,
make_report => \&make_report,
send_report => \&TBBTestSuite::Reports::Send::send_report,
receive_report => \&receive_report,
update_authkeys => \&TBBTestSuite::Reports::Receive::update_authkeys,
);
exit_error "Unknow action $options->{action}" unless $actions{$options->{action}};
......
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