Skip to content

Commit 7dfa8e1

Browse files
committedMar 24, 2015
Merge pull request os-autoinst#307 from aaannz/a6440_ajaxCloning
action 6440 - canceling reactions
2 parents 81e51f1 + 94fcbd5 commit 7dfa8e1

File tree

8 files changed

+93
-43
lines changed

8 files changed

+93
-43
lines changed
 

‎lib/OpenQA/Scheduler.pm

+4-4
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,11 @@ sub job_duplicate {
879879
# set this clone was triggered by manually if it's not auto-clone
880880
$args{dup_type_auto} = 0 unless defined $args{dup_type_auto};
881881

882-
log_debug("duplicating $args{jobid}");
883-
884882
my $job = schema->resultset("Jobs")->find({id => $args{jobid}});
885-
return undef unless $job;
886-
return undef if $job->clone; # already cloned
883+
return unless $job;
884+
return unless $job->can_be_duplicated; # already cloned
885+
886+
log_debug("duplicating $args{jobid}");
887887

888888
if($args{dup_type_auto}) {
889889
if ( int($job->retry_avbl) > 0) {

‎lib/OpenQA/Schema/Result/Jobs.pm

+7-4
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,20 @@ sub to_hash {
266266
267267
=item Arguments: none
268268
269-
=item Return value: 1 if a new clon can be created. 0 otherwise.
269+
=item Return value: 1 if a new clone can be created. undef otherwise.
270270
271271
=back
272272
273-
Checks if a given job can be duplicated.
273+
Checks if a given job can be duplicated - not cloned yet and in correct state.
274274
275275
=cut
276276
sub can_be_duplicated{
277-
my $self = shift;
277+
my ($self) = @_;
278278

279-
$self->clone ? 0 : 1;
279+
my $state = $self->state;
280+
return unless (grep {/$state/} (EXECUTION_STATES, FINAL_STATES) );
281+
return if $self->clone;
282+
return 1;
280283
}
281284

282285
=head2 duplicate

‎public/javascripts/tests.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,21 @@ function renderTestsList(jobs) {
197197
$('#relevantbox').css('color', 'inherit');
198198
} );
199199
} );
200-
$(document).on("click", '.restart', function() {
201-
var restart_link = $(this);
202-
var link = $(this).parent('span').find('.name');
203-
$.post(restart_link.attr("href")).done( function( data ) { $(link).append(' (restarted)'); });
204-
$(this).html('');
205-
});
206-
$(document).on('mouseover', '.parent_child', highlightJobs);
207-
$(document).on('mouseout', '.parent_child', unhighlightJobs);
208200
};
201+
202+
$(document).on("click", '.restart', function() {
203+
var restart_link = $(this);
204+
var link = $(this).parent('span').find('.name');
205+
$.post(restart_link.attr("href")).done( function( data ) { $(link).append(' (restarted)'); });
206+
$(this).html('');
207+
});
208+
209+
$(document).on('click', '.cancel', function() {
210+
var cancel_link = $(this);
211+
var test = $(this).parent('td');
212+
$.post(cancel_link.attr("href")).done( function( data ) { $(test).append(' (cancelled)'); });
213+
$(this).html('');
214+
});
215+
216+
$(document).on('mouseover', '.parent_child', highlightJobs);
217+
$(document).on('mouseout', '.parent_child', unhighlightJobs);

‎t/05-scheduler-restart-and-duplicate.t

+29-7
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,14 @@ my $current_jobs = list_jobs();
3838
ok(@$current_jobs, "have jobs");
3939

4040
my $job1 = OpenQA::Scheduler::job_get(99927);
41+
is($job1->{state}, OpenQA::Schema::Result::Jobs::SCHEDULED, 'trying to duplicate scheduled job');
4142
my $id = OpenQA::Scheduler::job_duplicate(jobid => 99927);
42-
ok(defined $id, "duplicate works");
43+
ok(!defined $id, "duplication rejected");
44+
45+
$job1 = OpenQA::Scheduler::job_get(99926);
46+
is($job1->{state}, OpenQA::Schema::Result::Jobs::DONE, 'trying to duplicate done job');
47+
$id = OpenQA::Scheduler::job_duplicate(jobid => 99926);
48+
ok(defined $id, "duplication works");
4349

4450
my $jobs = list_jobs();
4551
is(@$jobs, @$current_jobs+1, "one more job after duplicating one job");
@@ -51,17 +57,25 @@ delete $job1->{id};
5157
delete $job1->{settings}->{NAME};
5258
delete $job2->{id};
5359
delete $job2->{settings}->{NAME};
60+
delete $job1->{state};
61+
delete $job2->{state};
62+
delete $job1->{result};
63+
delete $job2->{result};
64+
delete $job1->{t_finished};
65+
delete $job2->{t_finished};
66+
delete $job1->{t_started};
67+
delete $job2->{t_started};
5468
is_deeply($job1, $job2, "duplicated job equal");
5569

56-
my @ret = OpenQA::Scheduler::job_restart(99927);
70+
my @ret = OpenQA::Scheduler::job_restart(99926);
5771
is(@ret, 0, "no job ids returned");
5872

5973
$jobs = list_jobs();
6074
is_deeply($jobs, $current_jobs, "jobs unchanged after restarting scheduled job");
6175

6276
OpenQA::Scheduler::job_cancel(99927);
6377
$job1 = OpenQA::Scheduler::job_get(99927);
64-
is($job1->{state}, 'cancelled', "scheduled job cancelled after cancelled");
78+
is($job1->{state}, 'cancelled', "scheduled job cancelled after cancel");
6579

6680
$job1 = OpenQA::Scheduler::job_get(99937);
6781
@ret = OpenQA::Scheduler::job_restart(99937);
@@ -94,22 +108,30 @@ $job2 = OpenQA::Scheduler::job_get(99963);
94108

95109
is_deeply($job1, $job2, "running job unchanged after cancel");
96110

97-
my $job3 = OpenQA::Scheduler::job_get(99928);
98-
is($job3->{retry_avbl}, 3, "the retry counter decreased");
99-
my $round1_id = OpenQA::Scheduler::job_duplicate((jobid => 99928, dup_type_auto => 1));
111+
my $job3 = OpenQA::Scheduler::job_get(99938);
112+
is($job3->{retry_avbl}, 3, "the retry counter setup ");
113+
my $round1_id = OpenQA::Scheduler::job_duplicate((jobid => 99938, dup_type_auto => 1));
100114
ok(defined $round1_id, "auto-duplicate works");
101115
$job3 = OpenQA::Scheduler::job_get($round1_id);
102116
is($job3->{retry_avbl}, 2, "the retry counter decreased");
117+
# need to change state from scheduled
118+
OpenQA::Scheduler::job_set_done(jobid => $round1_id, result => OpenQA::Schema::Result::Jobs::INCOMPLETE);
103119
my $round2_id = OpenQA::Scheduler::job_duplicate((jobid => $round1_id, dup_type_auto => 1));
104120
ok(defined $round2_id, "auto-duplicate works");
105121
$job3 = OpenQA::Scheduler::job_get($round2_id);
106122
is($job3->{retry_avbl}, 1, "the retry counter decreased");
123+
# need to change state from scheduled
124+
OpenQA::Scheduler::job_set_done(jobid => $round2_id, result => OpenQA::Schema::Result::Jobs::INCOMPLETE);
107125
my $round3_id = OpenQA::Scheduler::job_duplicate((jobid => $round2_id, dup_type_auto => 1));
108126
ok(defined $round3_id, "auto-duplicate works");
109127
$job3 = OpenQA::Scheduler::job_get($round3_id);
110128
is($job3->{retry_avbl}, 0, "the retry counter decreased");
129+
# need to change state from scheduled
130+
OpenQA::Scheduler::job_set_done(jobid => $round3_id, result => OpenQA::Schema::Result::Jobs::INCOMPLETE);
111131
my $round4_id = OpenQA::Scheduler::job_duplicate((jobid => $round3_id, dup_type_auto => 1));
112-
ok(!defined $round4_id, "auto-duplicate works");
132+
ok(!defined $round4_id, "no logner auto-duplicating");
133+
# need to change state from scheduled
134+
OpenQA::Scheduler::job_set_done(jobid => $round3_id, result => OpenQA::Schema::Result::Jobs::INCOMPLETE);
113135
my $round5_id = OpenQA::Scheduler::job_duplicate(jobid => $round3_id);
114136
ok(defined $round5_id, "manual-duplicate works");
115137
$job3 = OpenQA::Scheduler::job_get($round5_id);

‎t/09-job_clone.t

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ is_deeply($m_hashed, $c_hashed, "equivalent job settings (skipping NAME)");
6666
ok(!$minimalx->can_be_duplicated, "doesn't look cloneable after reloading");
6767
is($minimalx->duplicate, undef, "cannot clone after reloading");
6868

69-
# But cloning the clone should be possible
69+
# But cloning the clone should be possible after job state change
70+
$clone->state(OpenQA::Schema::Result::Jobs::CANCELLED);
7071
my $second = $clone->duplicate({prio => 35, retry_avbl => 2});
7172
is($second->test, "minimalx", "same test again");
7273
is($second->priority, 35, "with adjusted priority");

‎templates/test/result.html.ep

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,28 @@
33

44
% content_for 'ready_function' => begin
55
$('.timeago').timeago();
6+
$( '#restart-result' ).click( function(event) {
7+
event.preventDefault();
8+
var doc_url = document.URL.substring(0, document.URL.lastIndexOf("/") + 1);
9+
var restart_link = $(this);
10+
$.post(restart_link.attr("href")).done( function( data, res, xhr ) {
11+
var jobid = xhr.responseJSON.result;
12+
if (jobid) {
13+
var url = doc_url + jobid;
14+
window.location = url;
15+
}
16+
});
17+
$(this).html('');
18+
});
619
% end
720

821
<div class="grid_2 alpha">
922
<div class="box box-shadow" id="actions_box">
1023
<div class="box-header aligncenter">Actions</div>
1124
<div class="aligncenter">
12-
%# TODO: to use can_be_duplicated we have to wait for https://progress.opensuse.org/issues/1393
13-
%# in the meantime, just check clone_id
14-
% unless ($job->clone_id) {
25+
% if ($job->can_be_duplicated) {
1526
%= link_post url_for('apiv1_restart', name => $testid) => ('data-remote' => 'true', id => 'restart-result') => begin
16-
%= image "/images/toggle.png", alt => "schedule", title => "re-schedule"
27+
%= image "/images/toggle.png", alt => "schedule", title => "restart"
1728
%= end
1829
% }
1930
</div>

‎templates/test/running_table.html.ep

+11-9
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,17 @@
4949
%= link_to "Build$build" => url_for('tests_overview')->query(%$query);
5050
of <%= "$settings->{DISTRI}-$settings->{VERSION}-$settings->{FLAVOR}.$settings->{ARCH}" %>
5151
</td>
52-
<td class="test">
53-
%= link_to url_for('test', 'testid' => $job->id) => begin
54-
<i class="status state_running fa fa-circle" title="Running"></i>
55-
%= link_post url_for('apiv1_cancel', 'name' => $job->id) => ('data-remote' => 'true') => (class => 'cancel') => begin
56-
<i class="action fa fa-times-circle-o"></i>
57-
% end
58-
%= $testname
59-
% end
60-
</td>
52+
<td class="test">
53+
%= link_to url_for('test', 'testid' => $job->id) => begin
54+
<i class="status state_running fa fa-circle" title="Running"></i>
55+
% end
56+
%= link_post url_for('apiv1_cancel', 'name' => $job->id) => ('data-remote' => 'true') => (class => 'cancel') => begin
57+
<i class="action fa fa-times-circle-o"></i>
58+
% end
59+
%= link_to url_for('test', 'testid' => $job->id) => begin
60+
%= $testname
61+
% end
62+
</td>
6163
% my $href = url_for('tests_overview')->query(build => $build, distri => $distri, version => $version);
6264
<td class="testtime" title="<%= $job->t_started %>"><%= $job->t_started->datetime() %>Z</td>
6365
<td style="padding: 3px 4px;" class="progress">

‎templates/test/scheduled_table.html.ep

+8-6
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
%= link_to "Build$build" => url_for('tests_overview')->query(%$query);
4040
of <%= "$settings->{DISTRI}-$settings->{VERSION}-$settings->{FLAVOR}.$settings->{ARCH}" %>
4141
</td>
42-
<td class="test">
42+
<td class="test">
4343
%= link_to url_for('test', 'testid' => $job->id) => begin
44-
<i class="status state_scheduled fa fa-circle" title="Scheduled"></i>
45-
%= link_post url_for('apiv1_cancel', 'name' => $job->id) => ('data-remote' => 'true') => (class => 'cancel') => begin
46-
<i class="action fa fa-times-circle-o"></i>
47-
% end
48-
%= $test
44+
<i class="status state_scheduled fa fa-circle" title="Scheduled"></i>
45+
% end
46+
%= link_post url_for('apiv1_cancel', 'name' => $job->id) => ('data-remote' => 'true') => (class => 'cancel') => begin
47+
<i class="action fa fa-times-circle-o"></i>
48+
% end
49+
%= link_to url_for('test', 'testid' => $job->id) => begin
50+
%= $test
4951
% end
5052
</td>
5153
% my $href = url_for('tests_overview')->query(build => $build, distri => $distri, version => $version);

0 commit comments

Comments
 (0)
Please sign in to comment.