3 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
11 eval { require WWW::Mechanize };
13 warn "\nCannot load WWW::Mechanize. "
14 . "\nPlease install it before using smolder_smoke_signal.\n";
27 ./bin/smolder_smoke_signal --server smolder.foo.com \
28 --username myself --password s3cr3t --file test_report.xml \
33 Script used to upload a Smoke test report to a running smolder server.
34 This is extremely useful for scripted/automatic test runs but also
35 helpful when using a CLI makes things faster.
45 This is the hostname (and port if not 80) of the running Smolder server.
49 The name of the Smolder project to use for the upload.
53 The name of the Smolder user to use for the upload.
57 The password for the Smolder user given by C<username>.
61 The name of the file to upload. Please see F<docs/upload_file_format.pod>
62 for more details about the format that Smolder expects this file to
73 If your Smolder server is running on a port other than 80, then you
78 The architecture for the given smoke test run. If none is given
79 it will use the default architecture for the project.
83 The platform for the given smoke test run. If none is given
84 it will use the default platform for the project.
88 The revision control number for this test run. Only applies to
89 projects that use revision control (shouldn't they all) and only
90 applies to tests run against a checkout from revision control.
92 This is just a free form text option so it will work with any
93 revision number that your preferred revision control system uses.
97 A comma separated list of tags that are given for this smoke report run.
99 ./bin/smolder_smoke_signal --server smolder.foo.com \
100 --username myself --password s3cr3t --file test_report.xml \
101 --project MyProject --tags "Foo, My Bar"
105 Any comments that you want to associate with the smoke test run.
109 Print verbose output of our actions to STDOUT.
114 my ($server, $project, $user, $pw, $file, $arch, $platform, $tags, $comments, $verbose, $rev,
119 'server=s' => \$server,
121 'project=s' => \$project,
122 'username=s' => \$user,
123 'password=s' => \$pw,
125 'architecture=s' => \$arch,
126 'platform=s' => \$platform,
128 'comments=s' => \$comments,
129 'revision=s' => \$rev,
130 'verbose!' => \$verbose,
147 # make sure all the required fields are there
148 _missing_required('server') unless $server;
149 _missing_required('project') unless $project;
150 _missing_required('username') unless $user;
151 _missing_required('password') unless $pw;
152 _missing_required('file') unless $file;
154 # make sure our file is there and is of the right type
156 unless ($file =~ /\.tar(\.gz)?$/) {
157 warn "File '$file' is not of the correct type!\n";
161 warn "File '$file' does not exist, or is not readable!\n";
165 # try and reach the smolder server
166 print "Trying to reach Smolder server at $server.\n" if ($verbose);
168 my $mech = WWW::Mechanize->new();
169 my $base_url = "http://$server:$port/app";
170 eval { $mech->get($base_url) };
171 unless ($mech->status eq '200') {
172 warn "Could not reach $server:$port successfully. Received status " . $mech->status . "\n";
177 print "Trying to login with username '$user'.\n" if ($verbose);
178 $mech->get($base_url . '/public_auth/login');
179 my $form = $mech->form_name('login');
180 if ($mech->status ne '200' || !$form) {
181 warn "Could not reach Smolder login form. Are you sure $server:$port is a Smolder server?\n";
189 my $content = $mech->content;
190 if ($mech->status ne '200' || $content !~ /Welcome \Q$user\E/) {
191 warn "Could not login with username '$user' and password '$pw'!\n";
195 # now go to this project's page
196 print "Retrieving project listing for user '$user'.\n" if ($verbose);
197 $mech->get($base_url . '/developer_projects');
198 $content = $mech->content;
199 $content =~ />\Q$project\E<!--ID:(\d+)-->/;
201 if ($mech->status ne '200' || !$project_id) {
202 warn "Could not get your project listing, or you are not a member of the '$project' project!\n";
206 # now go to the add-smoke-report page for this project
207 print "Adding smoke report to project '$project'.\n" if ($verbose);
208 $mech->get($base_url . "/developer_projects/add_report/$project_id");
209 $content = $mech->content;
210 if ($mech->status ne '200' || $content !~ /New Smoke Report/) {
211 warn "Could not reach the Add Smoke Report form!\n";
214 $mech->form_name('add_report');
215 my %fields = (report_file => $file);
216 $fields{platform} = $platform if $platform;
217 $fields{architecture} = $arch if $arch;
218 $fields{tags} = $tags if $tags;
219 $fields{comments} = $comments if $comments;
220 $fields{revision} = $rev if $rev;
221 $mech->set_fields(%fields);
224 $content = $mech->content;
225 if ($mech->status ne '200' || $content !~ /Recent Smoke Reports/) {
226 warn "Could not upload smoke report with the given information!\n";
229 $content =~ /#(\d+) Added/;
232 print "\nReport successfully uploaded as #$report_id.\n";
234 ##########################################################
236 ##########################################################
237 sub _missing_required {
239 warn "Missing required field '$field'!\n";