Trade memory leaks for segfaults
[Math-GSL.git] / bin / smolder_smoke_signal
blobb49d4be2569f282b0dbf9b7a5e7350ac15b26196
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
4 use Getopt::Long;
5 use Pod::Usage;
7 BEGIN {
8 eval { require WWW::Mechanize };
9 if ($@) {
10 warn "\nCannot load WWW::Mechanize. "
11 . "\nPlease install it before using smolder_smoke_signal.\n";
12 exit(1);
16 =pod
18 =head1 NAME
20 smolder_smoke_signal
22 =head1 SYNOPSIS
24 ./bin/smolder_smoke_signal --server smolder.foo.com \
25 --username myself --password s3cr3t --file test_report.xml \
26 --project MyProject
28 =head1 DESCRIPTION
30 Script used to upload a Smoke test report to a running smolder server.
31 This is extremely useful for scripted/automatic test runs but also
32 helpful when using a CLI makes things faster.
34 =head1 OPTIONS
36 =head2 REQUIRED
38 =over
40 =item server
42 This is the hostname (and port if not 80) of the running Smolder server.
44 =item project
46 The name of the Smolder project to use for the upload.
48 =item username
50 The name of the Smolder user to use for the upload.
52 =item password
54 The password for the Smolder user given by C<username>.
56 =item file
58 The name of the file to upload. Please see F<docs/upload_file_format.pod>
59 for more details about the format that Smolder expects this file to
60 take.
62 =back
64 =head2 OPTIONAL
66 =over
68 =item port
70 If your Smolder server is running on a port other than 80, then you
71 can specify it here.
73 =item architecture
75 The architecture for the given smoke test run. If none is given
76 it will use the default architecture for the project.
78 =item platform
80 The platform for the given smoke test run. If none is given
81 it will use the default platform for the project.
83 =item revision
85 The revision control number for this test run. Only applies to
86 projects that use revision control (shouldn't they all) and only
87 applies to tests run against a checkout from revision control.
89 This is just a free form text option so it will work with any
90 revision number that your preferred revision control system uses.
92 =item tags
94 A comma separated list of tags that are given for this smoke report run.
96 ./bin/smolder_smoke_signal --server smolder.foo.com \
97 --username myself --password s3cr3t --file test_report.xml \
98 --project MyProject --tags "Foo, My Bar"
100 =item comments
102 Any comments that you want to associate with the smoke test run.
104 =item verbose
106 Print verbose output of our actions to STDOUT.
108 =cut
110 # default options
111 my ($server, $project, $user, $pw, $file, $arch, $platform, $tags, $comments, $verbose, $rev,
112 $port);
113 my ($help, $man);
115 GetOptions(
116 'server=s' => \$server,
117 'port=s' => \$port,
118 'project=s' => \$project,
119 'username=s' => \$user,
120 'password=s' => \$pw,
121 'file=s' => \$file,
122 'architecture=s' => \$arch,
123 'platform=s' => \$platform,
124 'tags=s' => \$tags,
125 'comments=s' => \$comments,
126 'revision=s' => \$rev,
127 'verbose!' => \$verbose,
128 'help' => \$help,
129 'man' => \$man,
130 ) || pod2usage();
132 if ($help) {
133 pod2usage(
134 -exitval => 0,
135 -verbose => 1,
137 } elsif ($man) {
138 pod2usage(
139 -exitval => 0,
140 -verbose => 2,
144 # make sure all the required fields are there
145 _missing_required('server') unless $server;
146 _missing_required('project') unless $project;
147 _missing_required('username') unless $user;
148 _missing_required('password') unless $pw;
149 _missing_required('file') unless $file;
151 # make sure our file is there and is of the right type
152 if (-r $file) {
153 unless ($file =~ /\.tar(\.gz)?$/) {
154 warn "File '$file' is not of the correct type!\n";
155 exit(1);
157 } else {
158 warn "File '$file' does not exist, or is not readable!\n";
159 exit(1);
162 # try and reach the smolder server
163 print "Trying to reach Smolder server at $server.\n" if ($verbose);
164 $port ||= 80;
165 my $mech = WWW::Mechanize->new();
166 my $base_url = "http://$server:$port/app";
167 eval { $mech->get($base_url) };
168 unless ($mech->status eq '200') {
169 warn "Could not reach $server:$port successfully. Received status " . $mech->status . "\n";
170 exit(1);
173 # now login
174 print "Trying to login with username '$user'.\n" if ($verbose);
175 $mech->get($base_url . '/public_auth/login');
176 my $form = $mech->form_name('login');
177 if ($mech->status ne '200' || !$form) {
178 warn "Could not reach Smolder login form. Are you sure $server:$port is a Smolder server?\n";
179 exit(1);
181 $mech->set_fields(
182 username => $user,
183 password => $pw,
185 $mech->submit();
186 my $content = $mech->content;
187 if ($mech->status ne '200' || $content !~ /Welcome \Q$user\E/) {
188 warn "Could not login with username '$user' and password '$pw'!\n";
189 exit(1);
192 # now go to this project's page
193 print "Retrieving project listing for user '$user'.\n" if ($verbose);
194 $mech->get($base_url . '/developer_projects');
195 $content = $mech->content;
196 $content =~ />\Q$project\E<!--ID:(\d+)-->/;
197 my $project_id = $1;
198 if ($mech->status ne '200' || !$project_id) {
199 warn "Could not get your project listing, or you are not a member of the '$project' project!\n";
200 exit(1);
203 # now go to the add-smoke-report page for this project
204 print "Adding smoke report to project '$project'.\n" if ($verbose);
205 $mech->get($base_url . "/developer_projects/add_report/$project_id");
206 $content = $mech->content;
207 if ($mech->status ne '200' || $content !~ /New Smoke Report/) {
208 warn "Could not reach the Add Smoke Report form!\n";
209 exit(1);
211 $mech->form_name('add_report');
212 my %fields = (report_file => $file);
213 $fields{platform} = $platform if $platform;
214 $fields{architecture} = $arch if $arch;
215 $fields{tags} = $tags if $tags;
216 $fields{comments} = $comments if $comments;
217 $fields{revision} = $rev if $rev;
218 $mech->set_fields(%fields);
219 $mech->submit();
221 $content = $mech->content;
222 if ($mech->status ne '200' || $content !~ /Recent Smoke Reports/) {
223 warn "Could not upload smoke report with the given information!\n";
224 exit(1);
226 $content =~ /#(\d+) Added/;
227 my $report_id = $1;
229 print "\nReport successfully uploaded as #$report_id.\n";
231 ##########################################################
232 # helper methods
233 ##########################################################
234 sub _missing_required {
235 my $field = shift;
236 warn "Missing required field '$field'!\n";
237 pod2usage();