foreman-tasks 0.13.1 → 0.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +9 -0
- data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +1 -0
- data/app/controllers/foreman_tasks/api/tasks_controller.rb +7 -3
- data/app/controllers/foreman_tasks/tasks_controller.rb +10 -1
- data/app/lib/actions/base.rb +1 -1
- data/app/lib/actions/middleware/keep_current_taxonomies.rb +4 -0
- data/app/lib/actions/middleware/keep_current_user.rb +5 -0
- data/app/models/foreman_tasks/recurring_logic.rb +6 -6
- data/app/models/foreman_tasks/task.rb +23 -13
- data/app/models/foreman_tasks/task/dynflow_task.rb +11 -6
- data/app/views/foreman_tasks/api/tasks/show.json.rabl +1 -1
- data/app/views/foreman_tasks/tasks/index.html.erb +2 -15
- data/app/views/foreman_tasks/tasks/show.html.erb +98 -75
- data/foreman-tasks.gemspec +1 -1
- data/lib/foreman_tasks.rb +1 -5
- data/lib/foreman_tasks/cleaner.rb +10 -0
- data/lib/foreman_tasks/version.rb +1 -1
- data/locale/action_names.rb +3 -2
- data/locale/en/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/en/foreman_tasks.po +10 -4
- data/locale/foreman_tasks.pot +59 -51
- data/test/controllers/tasks_controller_test.rb +48 -0
- data/test/foreman_tasks_test_helper.rb +2 -0
- data/test/support/dummy_active_job.rb +7 -0
- data/test/support/dummy_recurring_dynflow_action.rb +5 -0
- data/test/unit/cleaner_test.rb +8 -2
- data/test/unit/recurring_logic_test.rb +9 -0
- data/test/unit/task_test.rb +9 -0
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25fc44af39850ad061431b4262495b931072731c
|
4
|
+
data.tar.gz: 925eb0edab02549e5a27980b83c2356732eb871d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cfa0af234b3c6adc0b80ea15411ce3d7bc9d4e0326d620b0495ae914a2adf628762d49a7f9460573c290b1fad3d4535db3c2024c068c40fbdbfcb8cd186c249
|
7
|
+
data.tar.gz: 11a2abde6bf2eed2ead3d6fef4e6cc1dc9baaa9b828c30afa4938387f9451a1ee25226382d0cb32c6e8c952d833b5197d94a99009142f198c36e93835055eace
|
data/README.md
CHANGED
@@ -13,6 +13,15 @@ happening/happened in your Foreman instance. A framework for asynchronous tasks
|
|
13
13
|
* [foreman-users](https://groups.google.com/forum/?fromgroups#!forum/foreman-users)
|
14
14
|
* [foreman-dev](https://groups.google.com/forum/?fromgroups#!forum/foreman-dev)
|
15
15
|
|
16
|
+
## Compatibility
|
17
|
+
|
18
|
+
| Foreman Version | Plugin Version |
|
19
|
+
| --------------- | -------------- |
|
20
|
+
| >= 1.15 | ~> 0.9.0 |
|
21
|
+
| >= 1.16 | ~> 0.10.0 |
|
22
|
+
| >= 1.17 | ~> 0.11.0 |
|
23
|
+
| >= 1.18 | ~> 0.13.0 |
|
24
|
+
|
16
25
|
Installation
|
17
26
|
------------
|
18
27
|
|
@@ -12,6 +12,7 @@ module ForemanTasks
|
|
12
12
|
before_action :find_resource, :only => %w[show cancel]
|
13
13
|
|
14
14
|
api :GET, '/recurring_logics', N_('List recurring logics')
|
15
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
15
16
|
def index
|
16
17
|
@recurring_logics = resource_scope_for_index
|
17
18
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
module ForemanTasks
|
2
|
+
# rubocop:disable Metrics/ClassLength
|
2
3
|
module Api
|
3
4
|
class TasksController < ::Api::V2::BaseController
|
4
5
|
include ::Foreman::Controller::SmartProxyAuth
|
@@ -118,7 +119,9 @@ module ForemanTasks
|
|
118
119
|
end
|
119
120
|
def index
|
120
121
|
scope = resource_scope.search_for(params[:search]).select('DISTINCT foreman_tasks_tasks.*')
|
121
|
-
|
122
|
+
|
123
|
+
total = resource_scope.count
|
124
|
+
subtotal = scope.count
|
122
125
|
|
123
126
|
ordering_params = {
|
124
127
|
sort_by: params[:sort_by] || 'started_at',
|
@@ -128,14 +131,14 @@ module ForemanTasks
|
|
128
131
|
|
129
132
|
pagination_params = {
|
130
133
|
page: params[:page] || 1,
|
131
|
-
per_page: params[:per_page] || 20
|
134
|
+
per_page: params[:per_page] || Setting[:entries_per_page] || 20
|
132
135
|
}
|
133
136
|
scope = pagination_scope(scope, pagination_params)
|
134
137
|
results = scope.map { |task| task_hash(task) }
|
135
138
|
|
136
139
|
render :json => {
|
137
140
|
total: total,
|
138
|
-
subtotal:
|
141
|
+
subtotal: subtotal,
|
139
142
|
page: pagination_params[:page],
|
140
143
|
per_page: pagination_params[:per_page],
|
141
144
|
sort: {
|
@@ -264,4 +267,5 @@ module ForemanTasks
|
|
264
267
|
end
|
265
268
|
end
|
266
269
|
end
|
270
|
+
# rubocop:enable Metrics/ClassLength
|
267
271
|
end
|
@@ -125,8 +125,17 @@ module ForemanTasks
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def filter(scope)
|
128
|
-
|
128
|
+
search = current_taxonomy_search
|
129
|
+
search = [search, params[:search]].select(&:present?).join(' AND ')
|
130
|
+
scope.search_for(search, :order => params[:order])
|
129
131
|
.paginate(:page => params[:page], :per_page => params[:per_page]).distinct
|
130
132
|
end
|
133
|
+
|
134
|
+
def current_taxonomy_search
|
135
|
+
conditions = []
|
136
|
+
conditions << "organization_id = #{Organization.current.id}" if Organization.current
|
137
|
+
conditions << "location_id = #{Location.current.id}" if Location.current
|
138
|
+
conditions.empty? ? '' : "(#{conditions.join(' AND ')})"
|
139
|
+
end
|
131
140
|
end
|
132
141
|
end
|
data/app/lib/actions/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Actions
|
2
2
|
class Base < Dynflow::Action
|
3
|
-
middleware.use ::Actions::Middleware::RailsExecutorWrap
|
3
|
+
middleware.use ::Actions::Middleware::RailsExecutorWrap
|
4
4
|
|
5
5
|
def task
|
6
6
|
@task ||= ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first!
|
@@ -8,11 +8,7 @@ module ForemanTasks
|
|
8
8
|
belongs_to :triggering
|
9
9
|
|
10
10
|
has_many :tasks, :through => :task_group
|
11
|
-
|
12
|
-
has_many :task_groups, :through => :tasks, :uniq => true
|
13
|
-
else
|
14
|
-
has_many :task_groups, -> { distinct }, :through => :tasks
|
15
|
-
end
|
11
|
+
has_many :task_groups, -> { distinct }, :through => :tasks
|
16
12
|
|
17
13
|
scoped_search :on => :id, :complete_value => false, :validator => ScopedSearch::Validators::INTEGER
|
18
14
|
scoped_search :on => :max_iteration, :complete_value => false, :rename => :iteration_limit
|
@@ -28,9 +24,13 @@ module ForemanTasks
|
|
28
24
|
end
|
29
25
|
|
30
26
|
def start(action_class, *args)
|
27
|
+
start_after(action_class, Time.zone.now, *args)
|
28
|
+
end
|
29
|
+
|
30
|
+
def start_after(action_class, time, *args)
|
31
31
|
self.state = 'active'
|
32
32
|
save!
|
33
|
-
|
33
|
+
trigger_repeat_after(time, action_class, *args)
|
34
34
|
end
|
35
35
|
|
36
36
|
def trigger_repeat_after(time, action_class, *args)
|
@@ -26,18 +26,12 @@ module ForemanTasks
|
|
26
26
|
|
27
27
|
has_many :task_group_members, :dependent => :destroy
|
28
28
|
has_many :task_groups, :through => :task_group_members
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
:through => :task_group_members, :source => :task_group
|
36
|
-
# in fact, the task has only one owner but Rails don't let you to
|
37
|
-
# specify has_one relation though has_many relation
|
38
|
-
has_many :owners, -> { where(['foreman_tasks_locks.name = ?', Lock::OWNER_LOCK_NAME]) },
|
39
|
-
:through => :locks, :source => :resource, :source_type => 'User'
|
40
|
-
end
|
29
|
+
has_many :recurring_logic_task_groups, -> { where :type => 'ForemanTasks::TaskGroups::RecurringLogicTaskGroup' },
|
30
|
+
:through => :task_group_members, :source => :task_group
|
31
|
+
# in fact, the task has only one owner but Rails don't let you to
|
32
|
+
# specify has_one relation though has_many relation
|
33
|
+
has_many :owners, -> { where(['foreman_tasks_locks.name = ?', Lock::OWNER_LOCK_NAME]) },
|
34
|
+
:through => :locks, :source => :resource, :source_type => 'User'
|
41
35
|
|
42
36
|
scoped_search :on => :id, :complete_value => false
|
43
37
|
scoped_search :on => :action, :complete_value => false
|
@@ -48,6 +42,8 @@ module ForemanTasks
|
|
48
42
|
scoped_search :on => :start_at, :complete_value => false
|
49
43
|
scoped_search :on => :ended_at, :complete_value => false
|
50
44
|
scoped_search :on => :parent_task_id, :complete_value => true
|
45
|
+
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'location_id', :ext_method => :search_by_taxonomy, :only_explicit => true
|
46
|
+
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'organization_id', :ext_method => :search_by_taxonomy, :only_explicit => true
|
51
47
|
scoped_search :relation => :locks, :on => :resource_type, :complete_value => true, :rename => 'resource_type', :ext_method => :search_by_generic_resource
|
52
48
|
scoped_search :relation => :locks, :on => :resource_id, :complete_value => false, :rename => 'resource_id', :ext_method => :search_by_generic_resource
|
53
49
|
scoped_search :relation => :owners,
|
@@ -141,6 +137,20 @@ module ForemanTasks
|
|
141
137
|
{ :conditions => condition, :joins => :locks }
|
142
138
|
end
|
143
139
|
|
140
|
+
def self.search_by_taxonomy(key, operator, value)
|
141
|
+
uniq_suffix = SecureRandom.hex(3)
|
142
|
+
resource_type = key == 'location_id' ? 'Location' : 'Organization'
|
143
|
+
|
144
|
+
joins = <<-SQL
|
145
|
+
LEFT JOIN foreman_tasks_locks AS foreman_tasks_locks_taxonomy#{uniq_suffix}
|
146
|
+
ON (foreman_tasks_locks_taxonomy#{uniq_suffix}.task_id = foreman_tasks_tasks.id AND
|
147
|
+
foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_type = '#{resource_type}')
|
148
|
+
SQL
|
149
|
+
# Select only those tasks which either have the correct taxonomy or are not related to any
|
150
|
+
sql = "foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id #{operator} ? OR foreman_tasks_locks_taxonomy#{uniq_suffix}.resource_id IS NULL"
|
151
|
+
{ :conditions => sanitize_sql_for_conditions([sql, value]), :joins => joins }
|
152
|
+
end
|
153
|
+
|
144
154
|
def self.search_by_owner(key, operator, value)
|
145
155
|
return { :conditions => '0 = 1' } if value == 'current_user' && User.current.nil?
|
146
156
|
|
@@ -228,7 +238,7 @@ module ForemanTasks
|
|
228
238
|
part.to_s
|
229
239
|
end
|
230
240
|
end.join('; ')
|
231
|
-
parts.join(' ')
|
241
|
+
parts.join(' ').strip
|
232
242
|
end
|
233
243
|
|
234
244
|
protected
|
@@ -15,7 +15,7 @@ module ForemanTasks
|
|
15
15
|
self.start_at = string_to_time(utc_zone, data[:start_at]) if data[:start_at]
|
16
16
|
self.start_before = string_to_time(utc_zone, data[:start_before]) if data[:start_before]
|
17
17
|
self.parent_task_id ||= begin
|
18
|
-
if main_action.
|
18
|
+
if main_action.try(:caller_execution_plan_id)
|
19
19
|
DynflowTask.where(:external_id => main_action.caller_execution_plan_id).first!.id
|
20
20
|
end
|
21
21
|
end
|
@@ -70,7 +70,6 @@ module ForemanTasks
|
|
70
70
|
end
|
71
71
|
|
72
72
|
def label
|
73
|
-
return execution_plan_action.input['job_class'] if active_job?
|
74
73
|
return main_action.class.name if main_action.present?
|
75
74
|
self[:label]
|
76
75
|
end
|
@@ -106,8 +105,12 @@ module ForemanTasks
|
|
106
105
|
def main_action
|
107
106
|
return @main_action if defined?(@main_action)
|
108
107
|
if active_job?
|
109
|
-
|
110
|
-
|
108
|
+
args = if execution_plan.delay_record
|
109
|
+
execution_plan.delay_record.args.first
|
110
|
+
else
|
111
|
+
execution_plan_action.input
|
112
|
+
end
|
113
|
+
@main_action = active_job_action(args['job_class'], args['job_arguments'])
|
111
114
|
else
|
112
115
|
@main_action = execution_plan && execution_plan.root_plan_step.try(:action, execution_plan)
|
113
116
|
end
|
@@ -118,7 +121,9 @@ module ForemanTasks
|
|
118
121
|
# humanized_* methods for foreman-tasks integration.
|
119
122
|
def active_job_action(klass, args)
|
120
123
|
return if klass.blank?
|
121
|
-
klass.
|
124
|
+
if (active_job_class = klass.safe_constantize)
|
125
|
+
active_job_class.new(*args)
|
126
|
+
end
|
122
127
|
end
|
123
128
|
|
124
129
|
def active_job?
|
@@ -142,7 +147,7 @@ module ForemanTasks
|
|
142
147
|
method = find_humanize_method_kind(method)
|
143
148
|
Match! method, :humanized_name, :humanized_input, :humanized_output, :humanized_errors
|
144
149
|
if method != :humanized_name && execution_scheduled?
|
145
|
-
return
|
150
|
+
return
|
146
151
|
elsif method == :humanized_name && main_action.nil?
|
147
152
|
return N_(label)
|
148
153
|
end
|
@@ -2,20 +2,7 @@
|
|
2
2
|
<% title_actions csv_link, help_button %>
|
3
3
|
<% stylesheet 'foreman_tasks/tasks' %>
|
4
4
|
|
5
|
-
<
|
6
|
-
|
7
|
-
var currentTwoPaneTask;
|
8
|
-
|
9
|
-
$(document).on('click', ".table-two-pane td.two-pane-link", function(e) {
|
10
|
-
currentTwoPaneTask = $(this).find("a");
|
11
|
-
if(currentTwoPaneTask.length){
|
12
|
-
e.preventDefault();
|
13
|
-
two_pane_open(currentTwoPaneTask);
|
14
|
-
}
|
15
|
-
});
|
16
|
-
|
17
|
-
</script>
|
18
|
-
<table class="<%= table_css_classes('table-fixed table-two-pane') %>">
|
5
|
+
<table class="<%= table_css_classes('table-fixed') %>">
|
19
6
|
<tr>
|
20
7
|
<th class="col-md-4"><%= _("Action") %></th>
|
21
8
|
<th class="col-md-1"><%= _("State") %></th>
|
@@ -26,7 +13,7 @@ $(document).on('click', ".table-two-pane td.two-pane-link", function(e) {
|
|
26
13
|
</tr>
|
27
14
|
<% for task in @tasks %>
|
28
15
|
<tr>
|
29
|
-
<td class="task-id
|
16
|
+
<td class="task-id ellipsis">
|
30
17
|
<%= link_to_if_authorized(format_task_input(task),
|
31
18
|
hash_for_foreman_tasks_task_path(:id => task)) %>
|
32
19
|
</td>
|
@@ -1,94 +1,117 @@
|
|
1
1
|
<% stylesheet 'foreman_tasks/tasks' %>
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
3
|
+
<%= breadcrumbs(
|
4
|
+
items: [
|
5
|
+
{
|
6
|
+
caption: _('Tasks'),
|
7
|
+
url: url_for(foreman_tasks_tasks_path)
|
8
|
+
},
|
9
|
+
{
|
10
|
+
caption: truncate(format_task_input(@task), :length => 50)
|
11
|
+
}
|
12
|
+
],
|
13
|
+
name_field: 'action',
|
14
|
+
resource_url: foreman_tasks_api_tasks_path,
|
15
|
+
switcher_item_url: foreman_tasks_task_path(:id => ':id')
|
16
|
+
) %>
|
17
|
+
|
18
|
+
|
19
|
+
<div class="task-details">
|
20
|
+
<script>
|
21
|
+
if (typeof taskProgressReloader === 'undefined') {
|
22
|
+
var taskProgressReloader = {
|
23
|
+
timeoutId: null,
|
24
|
+
formId: null,
|
25
|
+
reload: function () {
|
26
|
+
tfm.tools.showSpinner();
|
27
|
+
taskProgressReloader.timeoutId = null;
|
28
|
+
taskProgressReloader.formId = null;
|
29
|
+
|
30
|
+
$.ajax({
|
31
|
+
type:'GET',
|
32
|
+
url: document.location.href,
|
33
|
+
headers: {"X-Foreman-Layout": "two-pane"},
|
34
|
+
success: function(response){
|
35
|
+
$('#content .task-details').replaceWith($(response));
|
36
|
+
},
|
37
|
+
error: function(response){
|
38
|
+
document.location.reload();
|
39
|
+
},
|
40
|
+
complete: function(){
|
41
|
+
tfm.tools.hideSpinner();
|
42
|
+
}
|
43
|
+
});
|
44
|
+
},
|
45
|
+
|
46
|
+
start: function () {
|
47
|
+
var button = $('.reload-button');
|
48
|
+
if (!taskProgressReloader.timeoutId) {
|
49
|
+
taskProgressReloader.timeoutId = setTimeout(this.reload, 5000);
|
50
|
+
taskProgressReloader.formId = $(button).closest('form')[0].id;
|
51
|
+
}
|
52
|
+
button.html('<span class="glyphicon glyphicon-refresh spin"></span> <%= _('Stop auto-reloading') %>');
|
53
|
+
button.show();
|
54
|
+
},
|
55
|
+
|
56
|
+
stop: function () {
|
57
|
+
if (taskProgressReloader.timeoutId) {
|
58
|
+
clearTimeout(taskProgressReloader.timeoutId);
|
59
|
+
}
|
60
|
+
taskProgressReloader.timeoutId = null;
|
61
|
+
taskProgressReloader.formId = null;
|
62
|
+
var button = $('.reload-button');
|
63
|
+
button.html('<span class="glyphicon glyphicon-refresh"></span> <%= _('Start auto-reloading') %>');
|
64
|
+
button.show();
|
65
|
+
},
|
66
|
+
|
67
|
+
toggle: function () {
|
68
|
+
if (taskProgressReloader.timeoutId) {
|
69
|
+
this.stop();
|
14
70
|
} else {
|
15
|
-
|
71
|
+
this.start();
|
16
72
|
}
|
17
|
-
} else {
|
18
|
-
document.location.reload();
|
19
73
|
}
|
20
|
-
}
|
74
|
+
};
|
75
|
+
}
|
21
76
|
|
22
|
-
|
23
|
-
|
24
|
-
if
|
25
|
-
|
26
|
-
taskProgressReloader.formId = $(button).closest('form')[0].id;
|
77
|
+
$(document).ready(function () {
|
78
|
+
$('.modal-submit').click(function(e){
|
79
|
+
if($(this).hasClass('disabled')){
|
80
|
+
e.preventDefault();
|
27
81
|
}
|
28
|
-
|
29
|
-
|
30
|
-
|
82
|
+
});
|
83
|
+
$('.disable-unlock').click(function() {
|
84
|
+
var button = $(this).parents('.modal').find('.modal-submit');
|
31
85
|
|
32
|
-
|
33
|
-
|
34
|
-
clearTimeout(taskProgressReloader.timeoutId);
|
86
|
+
if($(this).is(':checked')){
|
87
|
+
button.removeClass('disabled')
|
35
88
|
}
|
36
|
-
|
37
|
-
|
38
|
-
var button = $('.reload-button');
|
39
|
-
button.html('<span class="glyphicon glyphicon-refresh"></span> <%= _('Start auto-reloading') %>');
|
40
|
-
button.show();
|
41
|
-
},
|
42
|
-
|
43
|
-
toggle: function () {
|
44
|
-
if (taskProgressReloader.timeoutId) {
|
45
|
-
this.stop();
|
46
|
-
} else {
|
47
|
-
this.start();
|
89
|
+
else{
|
90
|
+
button.addClass('disabled')
|
48
91
|
}
|
49
|
-
}
|
50
|
-
};
|
51
|
-
}
|
52
|
-
|
53
|
-
$(document).ready(function () {
|
54
|
-
$('.modal-submit').click(function(e){
|
55
|
-
if($(this).hasClass('disabled')){
|
56
|
-
e.preventDefault();
|
57
|
-
}
|
58
|
-
});
|
59
|
-
$('.disable-unlock').click(function() {
|
60
|
-
var button = $(this).parents('.modal').find('.modal-submit');
|
61
|
-
|
62
|
-
if($(this).is(':checked')){
|
63
|
-
button.removeClass('disabled')
|
64
|
-
}
|
65
|
-
else{
|
66
|
-
button.addClass('disabled')
|
67
|
-
}
|
68
|
-
});
|
92
|
+
});
|
69
93
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
94
|
+
$('.reload-button').click(function (event) {
|
95
|
+
taskProgressReloader.toggle();
|
96
|
+
event.preventDefault();
|
97
|
+
});
|
74
98
|
|
75
|
-
|
76
|
-
|
77
|
-
|
99
|
+
$('.reload-button-stop').click(function (event) {
|
100
|
+
taskProgressReloader.stop();
|
101
|
+
});
|
78
102
|
|
79
|
-
|
103
|
+
$('ul.nav-tabs a' ).click(function (event) {
|
104
|
+
taskProgressReloader.stop();
|
105
|
+
});
|
106
|
+
|
107
|
+
<% if @task.state != 'stopped' %>
|
108
|
+
taskProgressReloader.start();
|
109
|
+
<% else %>
|
80
110
|
taskProgressReloader.stop();
|
111
|
+
<% end %>
|
81
112
|
});
|
113
|
+
</script>
|
82
114
|
|
83
|
-
<% if @task.state != 'stopped' %>
|
84
|
-
taskProgressReloader.start();
|
85
|
-
<% else %>
|
86
|
-
taskProgressReloader.stop();
|
87
|
-
<% end %>
|
88
|
-
});
|
89
|
-
</script>
|
90
|
-
|
91
|
-
<div class="task-details">
|
92
115
|
|
93
116
|
<%= form_for @task, :url => "#" do %>
|
94
117
|
|
data/foreman-tasks.gemspec
CHANGED
@@ -29,7 +29,7 @@ same resource. It also optionally provides Dynflow infrastructure for using it f
|
|
29
29
|
s.extra_rdoc_files = Dir['README*', 'LICENSE']
|
30
30
|
|
31
31
|
s.add_dependency "foreman-tasks-core"
|
32
|
-
s.add_dependency "dynflow", '~> 1.0'
|
32
|
+
s.add_dependency "dynflow", '~> 1.0', '>= 1.0.5'
|
33
33
|
s.add_dependency "sinatra" # for Dynflow web console
|
34
34
|
s.add_dependency "parse-cron", '~> 0.1.4'
|
35
35
|
s.add_dependency "get_process_mem" # for memory polling
|
data/lib/foreman_tasks.rb
CHANGED
@@ -34,11 +34,7 @@ module ForemanTasks
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def self.rails_safe_trigger_task
|
37
|
-
|
38
|
-
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
39
|
-
yield
|
40
|
-
end
|
41
|
-
else
|
37
|
+
ActiveSupport::Dependencies.interlock.permit_concurrent_loads do
|
42
38
|
yield
|
43
39
|
end
|
44
40
|
end
|
@@ -103,6 +103,7 @@ module ForemanTasks
|
|
103
103
|
delete_remote_tasks(chunk)
|
104
104
|
end
|
105
105
|
end
|
106
|
+
delete_orphaned_locks
|
106
107
|
delete_orphaned_dynflow_tasks
|
107
108
|
end
|
108
109
|
|
@@ -147,6 +148,15 @@ module ForemanTasks
|
|
147
148
|
ForemanTasks.dynflow.world.persistence.delete_execution_plans({ 'uuid' => uuids }, batch_size, @backup_dir)
|
148
149
|
end
|
149
150
|
|
151
|
+
def delete_orphaned_locks
|
152
|
+
orphaned_locks = ForemanTasks::Lock.left_outer_joins(:task).where(:'foreman_tasks_tasks.id' => nil)
|
153
|
+
with_noop(orphaned_locks, 'orphaned task locks') do |source, name|
|
154
|
+
with_batches(source, name) do |chunk|
|
155
|
+
ForemanTasks::Lock.where(id: chunk.pluck(:id)).delete_all
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
150
160
|
def delete_orphaned_dynflow_tasks
|
151
161
|
with_noop(orphaned_dynflow_tasks, 'orphaned execution plans') do |source, name|
|
152
162
|
with_batches(source, name) do |chunk|
|
data/locale/action_names.rb
CHANGED
Binary file
|
data/locale/en/foreman_tasks.po
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
#
|
6
6
|
msgid ""
|
7
7
|
msgstr ""
|
8
|
-
"Project-Id-Version: foreman_tasks 0.
|
8
|
+
"Project-Id-Version: foreman_tasks 0.2.5\n"
|
9
9
|
"Report-Msgid-Bugs-To: \n"
|
10
10
|
"PO-Revision-Date: 2016-02-03 09:55-0500\n"
|
11
11
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
@@ -150,6 +150,9 @@ msgstr ""
|
|
150
150
|
msgid "External Id"
|
151
151
|
msgstr ""
|
152
152
|
|
153
|
+
msgid "Failed to check on tasks on proxy at %{url}: %{exception}"
|
154
|
+
msgstr ""
|
155
|
+
|
153
156
|
msgid "Failed to initialize"
|
154
157
|
msgstr ""
|
155
158
|
|
@@ -271,6 +274,9 @@ msgstr ""
|
|
271
274
|
msgid "Parent task"
|
272
275
|
msgstr ""
|
273
276
|
|
277
|
+
msgid "Proxy task gone missing from the smart proxy"
|
278
|
+
msgstr ""
|
279
|
+
|
274
280
|
msgid "Raw"
|
275
281
|
msgstr ""
|
276
282
|
|
@@ -289,6 +295,9 @@ msgstr ""
|
|
289
295
|
msgid "Recurring logics"
|
290
296
|
msgstr ""
|
291
297
|
|
298
|
+
msgid "Remote action:"
|
299
|
+
msgstr ""
|
300
|
+
|
292
301
|
msgid "Repeat N times"
|
293
302
|
msgstr ""
|
294
303
|
|
@@ -436,9 +445,6 @@ msgstr ""
|
|
436
445
|
msgid "Thu"
|
437
446
|
msgstr ""
|
438
447
|
|
439
|
-
msgid "Time in second during which a task has to be started on the proxy"
|
440
|
-
msgstr ""
|
441
|
-
|
442
448
|
msgid "Time in seconds between retries"
|
443
449
|
msgstr ""
|
444
450
|
|
data/locale/foreman_tasks.pot
CHANGED
@@ -8,8 +8,8 @@ msgid ""
|
|
8
8
|
msgstr ""
|
9
9
|
"Project-Id-Version: foreman_tasks 1.0.0\n"
|
10
10
|
"Report-Msgid-Bugs-To: \n"
|
11
|
-
"POT-Creation-Date: 2018-
|
12
|
-
"PO-Revision-Date: 2018-
|
11
|
+
"POT-Creation-Date: 2018-06-14 21:03+0200\n"
|
12
|
+
"PO-Revision-Date: 2018-06-14 21:03+0200\n"
|
13
13
|
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
14
14
|
"Language-Team: LANGUAGE <LL@li.org>\n"
|
15
15
|
"Language: \n"
|
@@ -22,87 +22,87 @@ msgstr ""
|
|
22
22
|
msgid "List recurring logics"
|
23
23
|
msgstr ""
|
24
24
|
|
25
|
-
#: ../app/controllers/foreman_tasks/api/recurring_logics_controller.rb:
|
25
|
+
#: ../app/controllers/foreman_tasks/api/recurring_logics_controller.rb:20
|
26
26
|
msgid "Show recurring logic details"
|
27
27
|
msgstr ""
|
28
28
|
|
29
|
-
#: ../app/controllers/foreman_tasks/api/recurring_logics_controller.rb:
|
29
|
+
#: ../app/controllers/foreman_tasks/api/recurring_logics_controller.rb:24
|
30
30
|
msgid "Cancel recurring logic"
|
31
31
|
msgstr ""
|
32
32
|
|
33
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
33
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:74
|
34
34
|
msgid "Resume all paused error tasks"
|
35
35
|
msgstr ""
|
36
36
|
|
37
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
37
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:75
|
38
38
|
msgid "Resume tasks matching search string"
|
39
39
|
msgstr ""
|
40
40
|
|
41
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
41
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:76
|
42
42
|
msgid "Resume specific tasks by ID"
|
43
43
|
msgstr ""
|
44
44
|
|
45
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
45
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:111
|
46
46
|
msgid "List tasks"
|
47
47
|
msgstr ""
|
48
48
|
|
49
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
49
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:112
|
50
50
|
msgid "Search string"
|
51
51
|
msgstr ""
|
52
52
|
|
53
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
53
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:113
|
54
54
|
msgid "Page number, starting at 1"
|
55
55
|
msgstr ""
|
56
56
|
|
57
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
57
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:114
|
58
58
|
msgid "Number of results per page to return"
|
59
59
|
msgstr ""
|
60
60
|
|
61
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
61
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:115
|
62
62
|
msgid "Sort field and order, e.g. 'name DESC'"
|
63
63
|
msgstr ""
|
64
64
|
|
65
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
65
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:116
|
66
66
|
msgid "Hash version of 'order' param"
|
67
67
|
msgstr ""
|
68
68
|
|
69
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
69
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:117
|
70
70
|
msgid "Field to sort the results on"
|
71
71
|
msgstr ""
|
72
72
|
|
73
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
73
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:118
|
74
74
|
msgid "How to order the sorted results (e.g. ASC for ascending)"
|
75
75
|
msgstr ""
|
76
76
|
|
77
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
77
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:152
|
78
78
|
msgid "Send data to the task from external executor (such as smart_proxy_dynflow)"
|
79
79
|
msgstr ""
|
80
80
|
|
81
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
81
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:154
|
82
82
|
msgid "UUID of the task"
|
83
83
|
msgstr ""
|
84
84
|
|
85
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
85
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:155
|
86
86
|
msgid "The ID of the step inside the execution plan to send the event to"
|
87
87
|
msgstr ""
|
88
88
|
|
89
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
89
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:157
|
90
90
|
msgid "Data to be sent to the action"
|
91
91
|
msgstr ""
|
92
92
|
|
93
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
93
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:185
|
94
94
|
msgid "User search_params requires user_id to be specified"
|
95
95
|
msgstr ""
|
96
96
|
|
97
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
97
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:194
|
98
98
|
msgid "Resource search_params requires resource_type and resource_id to be specified"
|
99
99
|
msgstr ""
|
100
100
|
|
101
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
101
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:201
|
102
102
|
msgid "Task search_params requires task_id to be specified"
|
103
103
|
msgstr ""
|
104
104
|
|
105
|
-
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:
|
105
|
+
#: ../app/controllers/foreman_tasks/api/tasks_controller.rb:205
|
106
106
|
msgid "Type %s for search_params is not supported"
|
107
107
|
msgstr ""
|
108
108
|
|
@@ -148,8 +148,7 @@ msgstr ""
|
|
148
148
|
|
149
149
|
#: ../app/helpers/foreman_tasks/foreman_tasks_helper.rb:36
|
150
150
|
#: ../app/helpers/foreman_tasks/foreman_tasks_helper.rb:45
|
151
|
-
#: ../app/models/foreman_tasks/recurring_logic.rb:
|
152
|
-
#: ../app/models/foreman_tasks/task/dynflow_task.rb:110
|
151
|
+
#: ../app/models/foreman_tasks/recurring_logic.rb:110
|
153
152
|
#: ../app/views/foreman_tasks/tasks/dashboard/_latest_tasks_in_error_warning.html.erb:14
|
154
153
|
#: ../app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb:14
|
155
154
|
msgid "N/A"
|
@@ -312,7 +311,7 @@ msgstr ""
|
|
312
311
|
msgid "The targets are of different types"
|
313
312
|
msgstr ""
|
314
313
|
|
315
|
-
#: ../app/lib/actions/foreman/host/import_facts.rb:44 action_names.rb:
|
314
|
+
#: ../app/lib/actions/foreman/host/import_facts.rb:44 action_names.rb:5
|
316
315
|
msgid "Import facts"
|
317
316
|
msgstr ""
|
318
317
|
|
@@ -352,7 +351,7 @@ msgstr ""
|
|
352
351
|
msgid "organization"
|
353
352
|
msgstr ""
|
354
353
|
|
355
|
-
#: ../app/lib/actions/helpers/with_continuous_output.rb:
|
354
|
+
#: ../app/lib/actions/helpers/with_continuous_output.rb:24
|
356
355
|
msgid "Failed to initialize"
|
357
356
|
msgstr ""
|
358
357
|
|
@@ -364,31 +363,39 @@ msgstr ""
|
|
364
363
|
msgid "All proxies with the required feature are unavailable at the moment"
|
365
364
|
msgstr ""
|
366
365
|
|
367
|
-
#: ../app/lib/actions/
|
366
|
+
#: ../app/lib/actions/middleware/watch_delegated_proxy_sub_tasks.rb:68
|
367
|
+
msgid "Failed to check on tasks on proxy at %{url}: %{exception}"
|
368
|
+
msgstr ""
|
369
|
+
|
370
|
+
#: ../app/lib/actions/proxy_action.rb:79
|
368
371
|
msgid "The smart proxy task %s failed."
|
369
372
|
msgstr ""
|
370
373
|
|
371
|
-
#: ../app/lib/actions/proxy_action.rb:
|
374
|
+
#: ../app/lib/actions/proxy_action.rb:90
|
372
375
|
msgid "Cancel enforced: the task might be still running on the proxy"
|
373
376
|
msgstr ""
|
374
377
|
|
375
|
-
#: ../app/lib/actions/proxy_action.rb:
|
378
|
+
#: ../app/lib/actions/proxy_action.rb:100
|
376
379
|
msgid "Task aborted: the task might be still running on the proxy"
|
377
380
|
msgstr ""
|
378
381
|
|
379
|
-
#: ../app/lib/actions/proxy_action.rb:
|
382
|
+
#: ../app/lib/actions/proxy_action.rb:121
|
383
|
+
msgid "Proxy task gone missing from the smart proxy"
|
384
|
+
msgstr ""
|
385
|
+
|
386
|
+
#: ../app/lib/actions/proxy_action.rb:151
|
380
387
|
msgid "Initialization error: %s"
|
381
388
|
msgstr ""
|
382
389
|
|
383
|
-
#: ../app/models/foreman_tasks/recurring_logic.rb:
|
390
|
+
#: ../app/models/foreman_tasks/recurring_logic.rb:104
|
384
391
|
msgid "Active"
|
385
392
|
msgstr ""
|
386
393
|
|
387
|
-
#: ../app/models/foreman_tasks/recurring_logic.rb:
|
394
|
+
#: ../app/models/foreman_tasks/recurring_logic.rb:106
|
388
395
|
msgid "Cancelled"
|
389
396
|
msgstr ""
|
390
397
|
|
391
|
-
#: ../app/models/foreman_tasks/recurring_logic.rb:
|
398
|
+
#: ../app/models/foreman_tasks/recurring_logic.rb:108
|
392
399
|
msgid "Finished"
|
393
400
|
msgstr ""
|
394
401
|
|
@@ -456,10 +463,6 @@ msgstr ""
|
|
456
463
|
msgid "Time in seconds between retries"
|
457
464
|
msgstr ""
|
458
465
|
|
459
|
-
#: ../app/models/setting/foreman_tasks.rb:13
|
460
|
-
msgid "Time in second during which a task has to be started on the proxy"
|
461
|
-
msgstr ""
|
462
|
-
|
463
466
|
#: ../app/views/common/_trigger_form.html.erb:2
|
464
467
|
msgid "Schedule"
|
465
468
|
msgstr ""
|
@@ -489,7 +492,7 @@ msgstr ""
|
|
489
492
|
#: ../app/views/foreman_tasks/task_groups/recurring_logic_task_groups/_recurring_logic_task_group.html.erb:12
|
490
493
|
#: ../app/views/foreman_tasks/tasks/_errors.html.erb:16
|
491
494
|
#: ../app/views/foreman_tasks/tasks/_running_steps.html.erb:19
|
492
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
495
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:7
|
493
496
|
msgid "Action"
|
494
497
|
msgstr ""
|
495
498
|
|
@@ -523,7 +526,7 @@ msgstr ""
|
|
523
526
|
#: ../app/views/foreman_tasks/tasks/_running_steps.html.erb:24
|
524
527
|
#: ../app/views/foreman_tasks/tasks/dashboard/_latest_tasks_in_error_warning.html.erb:5
|
525
528
|
#: ../app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb:4
|
526
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
529
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:8
|
527
530
|
msgid "State"
|
528
531
|
msgstr ""
|
529
532
|
|
@@ -604,7 +607,7 @@ msgstr ""
|
|
604
607
|
#: ../app/views/foreman_tasks/tasks/_details.html.erb:96
|
605
608
|
#: ../app/views/foreman_tasks/tasks/dashboard/_latest_tasks_in_error_warning.html.erb:6
|
606
609
|
#: ../app/views/foreman_tasks/tasks/dashboard/_tasks_status.html.erb:5
|
607
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
610
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:9
|
608
611
|
msgid "Result"
|
609
612
|
msgstr ""
|
610
613
|
|
@@ -617,12 +620,12 @@ msgid "Execution type"
|
|
617
620
|
msgstr ""
|
618
621
|
|
619
622
|
#: ../app/views/foreman_tasks/tasks/_details.html.erb:127
|
620
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
623
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:10
|
621
624
|
msgid "Started at"
|
622
625
|
msgstr ""
|
623
626
|
|
624
627
|
#: ../app/views/foreman_tasks/tasks/_details.html.erb:131
|
625
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
628
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:11
|
626
629
|
msgid "Ended at"
|
627
630
|
msgstr ""
|
628
631
|
|
@@ -633,7 +636,7 @@ msgid "Output"
|
|
633
636
|
msgstr ""
|
634
637
|
|
635
638
|
#: ../app/views/foreman_tasks/tasks/_details.html.erb:188
|
636
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
639
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:121
|
637
640
|
msgid "Errors"
|
638
641
|
msgstr ""
|
639
642
|
|
@@ -720,35 +723,36 @@ msgid "Last start time"
|
|
720
723
|
msgstr ""
|
721
724
|
|
722
725
|
#: ../app/views/foreman_tasks/tasks/index.html.erb:1
|
726
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:6
|
723
727
|
#: ../lib/foreman_tasks/engine.rb:48
|
724
728
|
msgid "Tasks"
|
725
729
|
msgstr ""
|
726
730
|
|
727
|
-
#: ../app/views/foreman_tasks/tasks/index.html.erb:
|
731
|
+
#: ../app/views/foreman_tasks/tasks/index.html.erb:12
|
728
732
|
msgid "User"
|
729
733
|
msgstr ""
|
730
734
|
|
731
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
735
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:52
|
732
736
|
msgid "Stop auto-reloading"
|
733
737
|
msgstr ""
|
734
738
|
|
735
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
739
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:63
|
736
740
|
msgid "Start auto-reloading"
|
737
741
|
msgstr ""
|
738
742
|
|
739
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
743
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:119
|
740
744
|
msgid "Task"
|
741
745
|
msgstr ""
|
742
746
|
|
743
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
747
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:120
|
744
748
|
msgid "Running Steps"
|
745
749
|
msgstr ""
|
746
750
|
|
747
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
751
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:122
|
748
752
|
msgid "Locks"
|
749
753
|
msgstr ""
|
750
754
|
|
751
|
-
#: ../app/views/foreman_tasks/tasks/show.html.erb:
|
755
|
+
#: ../app/views/foreman_tasks/tasks/show.html.erb:123
|
752
756
|
msgid "Raw"
|
753
757
|
msgstr ""
|
754
758
|
|
@@ -767,5 +771,9 @@ msgid "Recurring Logics"
|
|
767
771
|
msgstr ""
|
768
772
|
|
769
773
|
#: action_names.rb:2
|
774
|
+
msgid "Remote action:"
|
775
|
+
msgstr ""
|
776
|
+
|
777
|
+
#: action_names.rb:3
|
770
778
|
msgid "Action with sub plans"
|
771
779
|
msgstr ""
|
@@ -12,6 +12,54 @@ module ForemanTasks
|
|
12
12
|
:dynflow_task
|
13
13
|
end
|
14
14
|
# rubocop:enable Naming/AccessorMethodName
|
15
|
+
|
16
|
+
def linked_task(resource)
|
17
|
+
FactoryBot.create(:some_task).tap { |t| ForemanTasks::Lock.link!(resource, t.id) }
|
18
|
+
end
|
19
|
+
|
20
|
+
def in_taxonomy_scope(organization, location = nil)
|
21
|
+
Organization.current = organization
|
22
|
+
Location.current = location unless location.nil?
|
23
|
+
yield organization, location
|
24
|
+
Organization.current = Location.current = nil
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'taxonomy scoping' do
|
28
|
+
let(:organizations) { (0..1).map { FactoryBot.create(:organization) } }
|
29
|
+
let(:tasks) { organizations.map { |o| linked_task(o) } + [FactoryBot.create(:some_task)] }
|
30
|
+
|
31
|
+
it 'takes other searches into account' do
|
32
|
+
task = tasks.first
|
33
|
+
@controller.stubs(:params).returns(:search => "id = #{task.id}")
|
34
|
+
in_taxonomy_scope(organizations.first) do |_o, _l|
|
35
|
+
results = @controller.send(:filter, ForemanTasks::Task)
|
36
|
+
results.map(&:id).sort.must_equal [task.id]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'does not scope by taxonomy if unset' do
|
41
|
+
organizations
|
42
|
+
tasks
|
43
|
+
@controller.send(:current_taxonomy_search).must_equal ''
|
44
|
+
results = @controller.send(:filter, ForemanTasks::Task)
|
45
|
+
results.map(&:id).sort.must_equal tasks.map(&:id).sort
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'scopes by organization if set' do
|
49
|
+
scoped, _, unscoped = tasks
|
50
|
+
in_taxonomy_scope(organizations.first) do |o, _l|
|
51
|
+
@controller.send(:current_taxonomy_search).must_equal "(organization_id = #{o.id})"
|
52
|
+
results = @controller.send(:filter, ForemanTasks::Task)
|
53
|
+
results.map(&:id).sort.must_equal [scoped, unscoped].map(&:id).sort
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'scopes by org and location if set' do
|
58
|
+
in_taxonomy_scope(organizations.first, FactoryBot.create(:location)) do |o, l|
|
59
|
+
@controller.send(:current_taxonomy_search).must_equal "(organization_id = #{o.id} AND location_id = #{l.id})"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
15
63
|
end
|
16
64
|
end
|
17
65
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
|
+
require_relative './support/dummy_active_job'
|
2
3
|
require_relative './support/dummy_dynflow_action'
|
4
|
+
require_relative './support/dummy_recurring_dynflow_action'
|
3
5
|
require_relative './support/dummy_proxy_action'
|
4
6
|
require_relative './support/dummy_task_group'
|
5
7
|
|
data/test/unit/cleaner_test.rb
CHANGED
@@ -39,12 +39,18 @@ class TasksTest < ActiveSupport::TestCase
|
|
39
39
|
task.started_at = task.ended_at = Time.zone.now
|
40
40
|
task.save
|
41
41
|
end]
|
42
|
+
lock_to_delete = tasks_to_delete.first.locks.create(:name => 'read', :resource => User.current)
|
43
|
+
|
44
|
+
tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)]
|
45
|
+
lock_to_keep = tasks_to_keep.first.locks.create(:name => 'read', :resource => User.current)
|
42
46
|
|
43
|
-
tasks_to_keep = [FactoryBot.create(:dynflow_task, :product_create_task)]
|
44
47
|
cleaner.expects(:tasks_to_csv)
|
45
48
|
cleaner.delete
|
46
49
|
ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
|
47
50
|
ForemanTasks::Task.where(id: tasks_to_keep).must_equal tasks_to_keep
|
51
|
+
|
52
|
+
ForemanTasks::Lock.find_by(id: lock_to_delete.id).must_be_nil
|
53
|
+
ForemanTasks::Lock.find_by(id: lock_to_keep.id).wont_be_nil
|
48
54
|
end
|
49
55
|
|
50
56
|
it 'supports passing empty filter (just delete all)' do
|
@@ -76,7 +82,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
76
82
|
w.close
|
77
83
|
header, *data = r.readlines.map(&:chomp)
|
78
84
|
header.must_equal ForemanTasks::Task.attribute_names.join(',')
|
79
|
-
expected_lines = tasks_to_delete.map { |task| task.attributes.values.
|
85
|
+
expected_lines = tasks_to_delete.map { |task| task.attributes.values.to_csv.chomp }
|
80
86
|
data.count.must_equal expected_lines.count
|
81
87
|
expected_lines.each { |line| data.must_include line }
|
82
88
|
ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
|
@@ -88,6 +88,15 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
88
88
|
recurring_logic.start(::Support::DummyDynflowAction)
|
89
89
|
end
|
90
90
|
|
91
|
+
it 'can start at' do
|
92
|
+
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
93
|
+
|
94
|
+
future_time = Time.zone.now + 1.week
|
95
|
+
recurring_logic.start_after(::Support::DummyRecurringDynflowAction, future_time)
|
96
|
+
|
97
|
+
assert_equal future_time.change(:min => future_time.min + 1, :sec => 0), recurring_logic.tasks.first.start_at
|
98
|
+
end
|
99
|
+
|
91
100
|
it 'has a task group associated to all tasks that were created as part of the recurring logic' do
|
92
101
|
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
93
102
|
recurring_logic.save
|
data/test/unit/task_test.rb
CHANGED
@@ -56,6 +56,15 @@ class TasksTest < ActiveSupport::TestCase
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
+
describe 'active job task' do
|
60
|
+
it 'when scheduled to the future, the label and action is set properly' do
|
61
|
+
job = Support::DummyActiveJob.set(:wait => 12.hours).perform_later
|
62
|
+
task = ForemanTasks::Task.find_by!(:external_id => job.provider_job_id)
|
63
|
+
task.action.must_equal "Dummy action"
|
64
|
+
task.label.must_equal "Support::DummyActiveJob"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
59
68
|
describe 'task without valid execution plan' do
|
60
69
|
let(:task) do
|
61
70
|
task = FactoryBot.create(:dynflow_task).tap do |task|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.13.
|
4
|
+
version: 0.13.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: foreman-tasks-core
|
@@ -31,6 +31,9 @@ dependencies:
|
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.0'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 1.0.5
|
34
37
|
type: :runtime
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -38,6 +41,9 @@ dependencies:
|
|
38
41
|
- - "~>"
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '1.0'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.5
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: sinatra
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -250,8 +256,10 @@ files:
|
|
250
256
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
251
257
|
- test/lib/actions/middleware/keep_current_taxonomies_test.rb
|
252
258
|
- test/lib/actions/middleware/keep_current_user_test.rb
|
259
|
+
- test/support/dummy_active_job.rb
|
253
260
|
- test/support/dummy_dynflow_action.rb
|
254
261
|
- test/support/dummy_proxy_action.rb
|
262
|
+
- test/support/dummy_recurring_dynflow_action.rb
|
255
263
|
- test/support/dummy_task_group.rb
|
256
264
|
- test/tasks/generate_task_actions_test.rb
|
257
265
|
- test/unit/actions/action_with_sub_plans_test.rb
|
@@ -286,7 +294,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
286
294
|
version: '0'
|
287
295
|
requirements: []
|
288
296
|
rubyforge_project:
|
289
|
-
rubygems_version: 2.
|
297
|
+
rubygems_version: 2.6.12
|
290
298
|
signing_key:
|
291
299
|
specification_version: 4
|
292
300
|
summary: Foreman plugin for showing tasks information for resoruces and users
|
@@ -302,8 +310,10 @@ test_files:
|
|
302
310
|
- test/helpers/foreman_tasks/tasks_helper_test.rb
|
303
311
|
- test/lib/actions/middleware/keep_current_taxonomies_test.rb
|
304
312
|
- test/lib/actions/middleware/keep_current_user_test.rb
|
313
|
+
- test/support/dummy_active_job.rb
|
305
314
|
- test/support/dummy_dynflow_action.rb
|
306
315
|
- test/support/dummy_proxy_action.rb
|
316
|
+
- test/support/dummy_recurring_dynflow_action.rb
|
307
317
|
- test/support/dummy_task_group.rb
|
308
318
|
- test/tasks/generate_task_actions_test.rb
|
309
319
|
- test/unit/actions/action_with_sub_plans_test.rb
|