foreman-tasks 9.1.0 → 9.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/foreman_tasks/remote_task.rb +3 -0
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +17 -17
- data/test/controllers/tasks_controller_test.rb +6 -6
- data/test/helpers/foreman_tasks/foreman_tasks_helper_test.rb +7 -7
- data/test/helpers/foreman_tasks/tasks_helper_test.rb +3 -3
- data/test/lib/actions/middleware/keep_current_request_id_test.rb +3 -3
- data/test/lib/concerns/polling_action_extensions_test.rb +4 -4
- data/test/tasks/generate_task_actions_test.rb +1 -1
- data/test/unit/actions/action_with_sub_plans_test.rb +4 -4
- data/test/unit/actions/bulk_action_test.rb +9 -9
- data/test/unit/actions/proxy_action_test.rb +20 -20
- data/test/unit/actions/recurring_action_test.rb +15 -15
- data/test/unit/actions/trigger_proxy_batch_test.rb +4 -4
- data/test/unit/cleaner_test.rb +24 -24
- data/test/unit/locking_test.rb +8 -8
- data/test/unit/proxy_selector_test.rb +9 -9
- data/test/unit/recurring_logic_test.rb +31 -32
- data/test/unit/remote_task_test.rb +4 -4
- data/test/unit/task_groups_test.rb +4 -4
- data/test/unit/task_test.rb +51 -51
- data/test/unit/triggering_test.rb +11 -11
- data/test/unit/troubleshooting_help_generator_test.rb +6 -6
- data/test/unit/ui_notifications_test.rb +20 -21
- metadata +2 -2
data/test/unit/cleaner_test.rb
CHANGED
@@ -22,14 +22,14 @@ class TasksTest < ActiveSupport::TestCase
|
|
22
22
|
FactoryBot.create(:dynflow_task, :product_create_task)]
|
23
23
|
cleaner.expects(:tasks_to_csv)
|
24
24
|
cleaner.delete
|
25
|
-
|
26
|
-
|
25
|
+
assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
|
26
|
+
assert_equal tasks_to_keep.map(&:id).sort, ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id)
|
27
27
|
|
28
|
-
|
29
|
-
|
28
|
+
assert_equal 0, ForemanTasks.dynflow.world.persistence
|
29
|
+
.find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size
|
30
30
|
|
31
|
-
|
32
|
-
|
31
|
+
assert_equal tasks_to_keep.size, ForemanTasks.dynflow.world.persistence
|
32
|
+
.find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#orphaned_dynflow_tasks" do
|
@@ -67,11 +67,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
67
67
|
|
68
68
|
cleaner.expects(:tasks_to_csv)
|
69
69
|
cleaner.delete
|
70
|
-
|
71
|
-
|
70
|
+
assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
|
71
|
+
assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep)
|
72
72
|
|
73
|
-
|
74
|
-
|
73
|
+
assert_nil ForemanTasks::Link.find_by(id: link_to_delete.id)
|
74
|
+
assert_not_nil ForemanTasks::Link.find_by(id: link_to_keep.id)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'supports passing empty filter (just delete all)' do
|
@@ -85,8 +85,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
85
85
|
end]
|
86
86
|
cleaner.expects(:tasks_to_csv)
|
87
87
|
cleaner.delete
|
88
|
-
|
89
|
-
|
88
|
+
assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
|
89
|
+
assert_equal tasks_to_keep, ForemanTasks::Task.where(id: tasks_to_keep)
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'matches tasks with compound filters properly' do
|
@@ -100,8 +100,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
100
100
|
task_to_keep.update!(:result => 'pending', :state => 'planned')
|
101
101
|
cleaner.expects(:tasks_to_csv)
|
102
102
|
cleaner.delete
|
103
|
-
|
104
|
-
|
103
|
+
assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
|
104
|
+
assert_equal [task_to_keep], ForemanTasks::Task.where(id: task_to_keep)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'backs tasks up before deleting' do
|
@@ -117,11 +117,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
117
117
|
cleaner.delete
|
118
118
|
w.close
|
119
119
|
header, *data = r.readlines.map(&:chomp)
|
120
|
-
|
120
|
+
assert_equal ForemanTasks::Task.attribute_names.join(','), header
|
121
121
|
expected_lines = tasks_to_delete.map { |task| task.attributes.values.to_csv.chomp }
|
122
|
-
|
123
|
-
expected_lines.each { |line|
|
124
|
-
|
122
|
+
assert_equal expected_lines.count, data.count
|
123
|
+
expected_lines.each { |line| assert_includes data, line }
|
124
|
+
assert_empty ForemanTasks::Task.where(id: tasks_to_delete)
|
125
125
|
end
|
126
126
|
|
127
127
|
class ActionWithCleanup < Actions::Base
|
@@ -135,7 +135,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
135
135
|
ForemanTasks::Cleaner.stubs(:cleanup_settings => {})
|
136
136
|
actions = ForemanTasks::Cleaner.actions_with_default_cleanup
|
137
137
|
example = actions.find { |rule| rule.klass == ActionWithCleanup }
|
138
|
-
|
138
|
+
assert_equal '15d', example.after
|
139
139
|
end
|
140
140
|
|
141
141
|
it 'searches for the actions that have the cleanup_after defined' do
|
@@ -143,7 +143,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
143
143
|
{ :actions => [{ :name => ActionWithCleanup.name, :after => '5d' }] })
|
144
144
|
actions = ForemanTasks::Cleaner.actions_with_default_cleanup
|
145
145
|
example = actions.find { |rule| rule.klass == ActionWithCleanup }
|
146
|
-
|
146
|
+
assert_equal '5d', example.after
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'generates filters from rules properly' do
|
@@ -157,10 +157,10 @@ class TasksTest < ActiveSupport::TestCase
|
|
157
157
|
:override_actions => true, :states => 'all' }]
|
158
158
|
ForemanTasks::Cleaner.stubs(:cleanup_settings).returns(:rules => rules)
|
159
159
|
r1, r2 = ForemanTasks::Cleaner.actions_by_rules actions_with_default
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
160
|
+
assert_equal '(NOT ((label ^ (action1, action2)))) AND (label = something)', r1[:filter]
|
161
|
+
assert_equal %w[stopped paused], r1[:states]
|
162
|
+
assert_equal '(label = something_else)', r2[:filter]
|
163
|
+
assert_equal [], r2[:states]
|
164
164
|
end
|
165
165
|
end
|
166
166
|
end
|
data/test/unit/locking_test.rb
CHANGED
@@ -32,14 +32,14 @@ module ForemanTasks
|
|
32
32
|
|
33
33
|
it 'can lock a resource for a single task only once' do
|
34
34
|
Lock.lock!(resource, task1)
|
35
|
-
|
35
|
+
assert_equal 1, Lock.for_resource(resource).count
|
36
36
|
Lock.lock!(resource, task1)
|
37
|
-
|
37
|
+
assert_equal 1, Lock.for_resource(resource).count
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'cannot lock a resource for multiple tasks' do
|
41
41
|
lock = Lock.lock!(resource, task1)
|
42
|
-
|
42
|
+
assert_equal [lock], Lock.colliding_locks(resource, task2)
|
43
43
|
assert_raises Lock::LockConflict do
|
44
44
|
Lock.lock!(resource, task2)
|
45
45
|
end
|
@@ -52,13 +52,13 @@ module ForemanTasks
|
|
52
52
|
exception = assert_raises Lock::LockConflict do
|
53
53
|
Lock.lock!(resource, task2)
|
54
54
|
end
|
55
|
-
|
55
|
+
assert_match(/#{lock.task_id}/, exception.message)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'creates a link when creating a lock for a resource' do
|
59
59
|
Lock.lock!(resource, task1)
|
60
60
|
link = Link.for_resource(resource).first
|
61
|
-
|
61
|
+
assert_equal task1.id, link.task_id
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -69,15 +69,15 @@ module ForemanTasks
|
|
69
69
|
|
70
70
|
it 'can link a resource for a single task only once' do
|
71
71
|
Link.link!(resource, task1)
|
72
|
-
|
72
|
+
assert_equal 1, Link.for_resource(resource).count
|
73
73
|
Link.link!(resource, task1)
|
74
|
-
|
74
|
+
assert_equal 1, Link.for_resource(resource).count
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'can link a resource to multiple tasks' do
|
78
78
|
Link.link!(resource, task1)
|
79
79
|
Link.link!(resource, task2)
|
80
|
-
|
80
|
+
assert_equal 2, Link.for_resource(resource).count
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
@@ -18,22 +18,22 @@ describe ForemanTasks::ProxySelector do
|
|
18
18
|
found << proxy_selector.select_by_jobs_count(proxies)
|
19
19
|
end
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
assert_equal count, available.count
|
22
|
+
assert_equal count - 1, available.uniq.count
|
23
|
+
assert_equal 1, proxy_selector.offline.count
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'returns nil for if no proxy is available' do
|
27
|
-
|
27
|
+
assert_nil proxy_selector.select_by_jobs_count([])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe '#determine_proxy' do
|
32
32
|
it 'returns :not_defined when avialable proxies returns empty hash' do
|
33
33
|
proxy_selector.stubs(:available_proxies => [])
|
34
|
-
|
34
|
+
assert_equal :not_defined, proxy_selector.determine_proxy
|
35
35
|
proxy_selector.stubs(:available_proxies => { :global => [] })
|
36
|
-
|
36
|
+
assert_equal :not_defined, proxy_selector.determine_proxy
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'returns :not_available when proxies are set but offline' do
|
@@ -41,7 +41,7 @@ describe ForemanTasks::ProxySelector do
|
|
41
41
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).times(count).raises
|
42
42
|
proxy_selector.stubs(:available_proxies =>
|
43
43
|
{ :global => FactoryBot.create_list(:smart_proxy, count) })
|
44
|
-
|
44
|
+
assert_equal :not_available, proxy_selector.determine_proxy
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'returns first available proxy, prioritizing by strategy' do
|
@@ -51,9 +51,9 @@ describe ForemanTasks::ProxySelector do
|
|
51
51
|
ForemanTasks::ProxySelector.any_instance.stubs(:available_proxies =>
|
52
52
|
{ :fallback => [fallback_proxy],
|
53
53
|
:global => [global_proxy] })
|
54
|
-
|
54
|
+
assert_equal fallback_proxy, ForemanTasks::ProxySelector.new.determine_proxy
|
55
55
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).raises.then.returns(0)
|
56
|
-
|
56
|
+
assert_equal global_proxy, ForemanTasks::ProxySelector.new.determine_proxy
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
@@ -4,17 +4,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
4
4
|
describe 'generating times' do
|
5
5
|
it 'assembles cronline' do
|
6
6
|
hash = {}
|
7
|
-
|
7
|
+
assert_equal '* * * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
8
8
|
hash.update :minutes => '*'
|
9
|
-
|
9
|
+
assert_equal '* * * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
10
10
|
hash.update :hours => '0,12'
|
11
|
-
|
11
|
+
assert_equal '* 0,12 * * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
12
12
|
hash.update :days => '*/2'
|
13
|
-
|
13
|
+
assert_equal '* 0,12 */2 * *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
14
14
|
hash.update :months => '12'
|
15
|
-
|
15
|
+
assert_equal '* 0,12 */2 12 *', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
16
16
|
hash.update :days_of_week => '1,2,3,4,5,6,7'
|
17
|
-
|
17
|
+
assert_equal '* 0,12 */2 12 1,2,3,4,5,6,7', ForemanTasks::RecurringLogic.assemble_cronline(hash)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'generates correct times' do
|
@@ -25,17 +25,17 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
25
25
|
minute = 0
|
26
26
|
reference_time = Time.utc(year, month, day, hour, minute)
|
27
27
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
28
|
-
|
28
|
+
assert_equal Time.utc(year, month, day, hour, minute), parser.next_occurrence_time(reference_time)
|
29
29
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 * * * *')
|
30
|
-
|
30
|
+
assert_equal Time.utc(year, month, day, hour, minute), parser.next_occurrence_time(reference_time)
|
31
31
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 * * *')
|
32
|
-
|
32
|
+
assert_equal Time.utc(year, month, day, 18), parser.next_occurrence_time(reference_time)
|
33
33
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 * *')
|
34
|
-
|
34
|
+
assert_equal Time.utc(year, month + 1, 10, 18, minute), parser.next_occurrence_time(reference_time)
|
35
35
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 11,12 *')
|
36
|
-
|
36
|
+
assert_equal Time.utc(year, 11, 10, 18, 0), parser.next_occurrence_time(reference_time)
|
37
37
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * 1')
|
38
|
-
|
38
|
+
assert_equal Time.utc(year, month + 1, 5), parser.next_occurrence_time(reference_time)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'creates correct cronline hash' do
|
@@ -48,10 +48,10 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
48
48
|
expected_result_daily = { :minutes => minutes, :hours => hours }
|
49
49
|
expected_result_weekly = { :minutes => minutes, :hours => hours, :days_of_week => '1,4,6' }
|
50
50
|
expected_result_monthly = { :minutes => minutes, :hours => hours, :days => days }
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
assert_equal expected_result_hourly, ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)
|
52
|
+
assert_equal expected_result_daily, ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)
|
53
|
+
assert_equal expected_result_weekly, ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)
|
54
|
+
assert_equal expected_result_monthly, ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'validates cronline correctly' do
|
@@ -68,18 +68,18 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
68
68
|
it 'can have limited number of repeats' do
|
69
69
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
70
70
|
parser.state = 'active'
|
71
|
-
|
71
|
+
assert parser.can_continue?
|
72
72
|
parser.max_iteration = 5
|
73
73
|
parser.expects(:iteration).twice.returns(5)
|
74
|
-
|
74
|
+
assert_not parser.can_continue?
|
75
75
|
parser.max_iteration = nil
|
76
76
|
time = Time.utc(2015, 9, 29, 15, 0)
|
77
77
|
parser.end_time = time
|
78
|
-
|
78
|
+
assert_not parser.can_continue?(time)
|
79
79
|
parser.end_time = time + 120
|
80
|
-
|
80
|
+
assert parser.can_continue?(time)
|
81
81
|
parser.max_iteration = 5
|
82
|
-
|
82
|
+
assert_not parser.can_continue?(time)
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'generates delay options' do
|
@@ -87,9 +87,8 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
87
87
|
parser.stubs(:id).returns(1)
|
88
88
|
reference_time = Time.utc(2015, 9, 29, 15)
|
89
89
|
expected_hash = { :start_at => reference_time, :start_before => nil, :recurring_logic_id => parser.id, :frozen => false }
|
90
|
-
|
91
|
-
|
92
|
-
.must_equal expected_hash.merge(:start_before => reference_time + 3600)
|
90
|
+
assert_equal expected_hash, parser.generate_delay_options(reference_time)
|
91
|
+
assert_equal expected_hash.merge(:start_before => reference_time + 3600), parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600)
|
93
92
|
end
|
94
93
|
|
95
94
|
it 'can start' do
|
@@ -119,19 +118,19 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
119
118
|
it 'has a task group associated to all tasks that were created as part of the recurring logic' do
|
120
119
|
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
121
120
|
recurring_logic.save
|
122
|
-
|
121
|
+
assert_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup, recurring_logic.task_group
|
123
122
|
task = FactoryBot.build(:dynflow_task, :user_create_task)
|
124
123
|
task.task_groups << Support::DummyTaskGroup.new
|
125
124
|
task.save!
|
126
125
|
recurring_logic.task_group.tasks << task
|
127
|
-
|
126
|
+
assert_includes recurring_logic.task_groups, *task.task_groups
|
128
127
|
end
|
129
128
|
|
130
129
|
it 'can be created from triggering' do
|
131
130
|
triggering = FactoryBot.build(:triggering, :recurring, :end_time_limited)
|
132
131
|
logic = ForemanTasks::RecurringLogic.new_from_triggering(triggering)
|
133
132
|
# Mysql coerces the times a bit
|
134
|
-
|
133
|
+
assert_in_delta triggering.end_time, logic.end_time, 1.second
|
135
134
|
end
|
136
135
|
|
137
136
|
it 'cannot trigger tasks when cancelled' do
|
@@ -181,24 +180,24 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
181
180
|
let(:logic) { FactoryBot.build(:recurring_logic) }
|
182
181
|
|
183
182
|
it 'is valid by default' do
|
184
|
-
|
183
|
+
assert_predicate logic, :valid?
|
185
184
|
end
|
186
185
|
|
187
186
|
it 'is invalid when end time in past' do
|
188
187
|
logic.end_time = (Time.zone.now - 120)
|
189
|
-
|
188
|
+
assert_not_predicate logic, :valid?
|
190
189
|
end
|
191
190
|
|
192
191
|
it 'is invalid when iteration limit < 1' do
|
193
192
|
logic.max_iteration = 0
|
194
|
-
|
193
|
+
assert_not_predicate logic, :valid?
|
195
194
|
end
|
196
195
|
|
197
196
|
it 'is valid when in active state' do
|
198
197
|
logic.end_time = (Time.zone.now - 120)
|
199
|
-
|
198
|
+
assert_not_predicate logic, :valid?
|
200
199
|
logic.state = 'active'
|
201
|
-
|
200
|
+
assert_predicate logic, :valid?
|
202
201
|
end
|
203
202
|
end
|
204
203
|
end
|
@@ -24,8 +24,8 @@ module ForemanTasks
|
|
24
24
|
RemoteTask.batch_trigger('a_operation', remote_tasks)
|
25
25
|
remote_tasks.each do |remote_task|
|
26
26
|
remote_task.reload
|
27
|
-
|
28
|
-
|
27
|
+
assert_equal 'triggered', remote_task.state
|
28
|
+
assert_equal (remote_task.id + 5).to_s, remote_task.remote_task_id
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -50,8 +50,8 @@ module ForemanTasks
|
|
50
50
|
RemoteTask.batch_trigger('a_operation', remote_tasks)
|
51
51
|
remote_tasks.each do |remote_task|
|
52
52
|
remote_task.reload
|
53
|
-
|
54
|
-
|
53
|
+
assert_equal 'triggered', remote_task.state
|
54
|
+
assert_equal (remote_task.id + 5).to_s, remote_task.remote_task_id
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
@@ -59,18 +59,18 @@ module ForemanTasks
|
|
59
59
|
|
60
60
|
it 'has the task group assigned' do
|
61
61
|
task = spawn_task.call ChildAction
|
62
|
-
|
62
|
+
assert_equal [1], task.task_groups.map(&:id)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'tasks inherit task groups correctly' do
|
66
66
|
children_count = 3
|
67
67
|
task = spawn_task.call ParentAction, children_count
|
68
68
|
# Parent task has task groups of its children
|
69
|
-
|
69
|
+
assert_equal [1, 2, 3, 4], task.task_groups.map(&:id).sort
|
70
70
|
# Children have the parent's and their own, they don't have their siblings' task groups
|
71
|
-
|
71
|
+
assert_equal children_count, task.sub_tasks.count
|
72
72
|
task.sub_tasks.each do |sub_task|
|
73
|
-
|
73
|
+
assert_equal [1, sub_task.input[:id]].sort, sub_task.task_groups.map(&:id).sort
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
data/test/unit/task_test.rb
CHANGED
@@ -32,8 +32,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'cannot search by arbitrary key' do
|
35
|
-
|
36
|
-
|
35
|
+
assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('user.my_key ~ 5') }
|
36
|
+
assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('user. = 5') }
|
37
37
|
end
|
38
38
|
|
39
39
|
test 'can search the tasks by negated user' do
|
@@ -59,8 +59,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
59
59
|
end
|
60
60
|
|
61
61
|
test 'cannot glob on user\'s id' do
|
62
|
-
|
63
|
-
|
62
|
+
assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for("user.id ~ something") }
|
63
|
+
assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for("user.id ~ 5") }
|
64
64
|
end
|
65
65
|
|
66
66
|
test 'can search the tasks by user with wildcards' do
|
@@ -105,28 +105,28 @@ class TasksTest < ActiveSupport::TestCase
|
|
105
105
|
|
106
106
|
it 'can search by seconds ' do
|
107
107
|
skip unless on_postgresql?
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
108
|
+
assert_empty scope.search_for('duration < 2')
|
109
|
+
assert_equal [@task_one, @task_two], scope.search_for('duration = 2')
|
110
|
+
assert_empty scope.search_for('duration < "2 seconds"')
|
111
|
+
assert_empty scope.search_for('duration > "2 seconds"')
|
112
|
+
assert_equal [@task_one, @task_two], scope.search_for('duration = "2 seconds"')
|
113
|
+
assert_equal [@task_one, @task_two], scope.search_for('duration <= "2 seconds"')
|
114
|
+
assert_equal [@task_one, @task_two], scope.search_for('duration >= "2 seconds"')
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'can search by other time intervals' do
|
118
118
|
skip unless on_postgresql?
|
119
119
|
%w[minutes hours days months years].each do |interval|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
120
|
+
assert_equal [@task_one, @task_two], scope.search_for("duration < \"2 #{interval}\"")
|
121
|
+
assert_empty scope.search_for("duration > \"2 #{interval}\"")
|
122
|
+
assert_empty scope.search_for("duration = \"2 #{interval}\"")
|
123
|
+
assert_equal [@task_one, @task_two], scope.search_for("duration <= \"2 #{interval}\"")
|
124
|
+
assert_empty scope.search_for("duration >= \"2 #{interval}\"")
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
128
|
it 'raises an exception if duration is unknown' do
|
129
|
-
|
129
|
+
assert_raises(ScopedSearch::QueryNotSupported) { ForemanTasks::Task.search_for('duration = "25 potatoes"') }
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -144,7 +144,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
144
144
|
describe 'users' do
|
145
145
|
test 'users can be deleted even if they have tasks assigned' do
|
146
146
|
user = FactoryBot.create(:user)
|
147
|
-
FactoryBot.create(:some_task, :
|
147
|
+
FactoryBot.create(:some_task, user: user)
|
148
148
|
user.destroy!
|
149
149
|
end
|
150
150
|
end
|
@@ -152,14 +152,14 @@ class TasksTest < ActiveSupport::TestCase
|
|
152
152
|
describe 'state_updated_at' do
|
153
153
|
it 'updates the state_updated_at when the state changes' do
|
154
154
|
task = FactoryBot.create(:some_task)
|
155
|
-
|
155
|
+
assert_operator task.state_updated_at, :>, Time.now.utc - 1.minute, "Newly created task has to have state_updated_at set"
|
156
156
|
task.update(state_updated_at: nil)
|
157
157
|
task.result = 'error'
|
158
158
|
task.save
|
159
|
-
|
159
|
+
assert_nil task.state_updated_at, "Other than state change should not affect 'state_updated_at'"
|
160
160
|
task.state = 'running'
|
161
161
|
task.save
|
162
|
-
|
162
|
+
assert_not_nil task.state_updated_at, "State change should set 'state_updated_at'"
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
@@ -171,7 +171,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
171
171
|
permission = FactoryBot.build(:permission)
|
172
172
|
permission.resource_type = 'ForemanTasks::Task'
|
173
173
|
permission.save!
|
174
|
-
FactoryBot.create(:filter, :
|
174
|
+
FactoryBot.create(:filter, role: role, permissions: [permission])
|
175
175
|
|
176
176
|
User.current = user
|
177
177
|
task = FactoryBot.create(:dynflow_task)
|
@@ -184,21 +184,21 @@ class TasksTest < ActiveSupport::TestCase
|
|
184
184
|
describe 'consistency check' do
|
185
185
|
it 'ensures the tasks marked as running are really running in Dynflow' do
|
186
186
|
task = ForemanTasks.sync_task(Support::DummyDynflowAction)
|
187
|
-
task.update(:
|
188
|
-
task.update(:
|
187
|
+
task.update(state: 'running') # Updating state updates the timestamp
|
188
|
+
task.update(state_updated_at: Time.zone.now - 5.minutes)
|
189
189
|
|
190
190
|
ForemanTasks::Task::DynflowTask.consistency_check
|
191
191
|
task.reload
|
192
|
-
|
192
|
+
assert_equal 'stopped', task.state
|
193
193
|
end
|
194
194
|
end
|
195
195
|
|
196
196
|
describe 'active job task' do
|
197
197
|
it 'when scheduled to the future, the label and action is set properly' do
|
198
|
-
job = Support::DummyActiveJob.set(:
|
199
|
-
task = ForemanTasks::Task.find_by!(:
|
200
|
-
|
201
|
-
|
198
|
+
job = Support::DummyActiveJob.set(wait: 12.hours).perform_later
|
199
|
+
task = ForemanTasks::Task.find_by!(external_id: job.provider_job_id)
|
200
|
+
assert_equal "Dummy action", task.action
|
201
|
+
assert_equal "Support::DummyActiveJob", task.label
|
202
202
|
end
|
203
203
|
end
|
204
204
|
|
@@ -214,9 +214,9 @@ class TasksTest < ActiveSupport::TestCase
|
|
214
214
|
end
|
215
215
|
|
216
216
|
it 'handles the error while loading the task and does not propagate errors unless necessary' do
|
217
|
-
task.cancellable?
|
218
|
-
task.resumable?
|
219
|
-
task.main_action
|
217
|
+
assert_nothing_raised { task.cancellable? }
|
218
|
+
assert_nothing_raised { task.resumable? }
|
219
|
+
assert_nothing_raised { task.main_action }
|
220
220
|
assert_equal 'Support::DummyDynflowAction', task.get_humanized(:humanized_name)
|
221
221
|
assert_equal 0, task.progress
|
222
222
|
assert_raises(KeyError) { task.cancel }
|
@@ -226,19 +226,19 @@ class TasksTest < ActiveSupport::TestCase
|
|
226
226
|
describe 'subtask count querying' do
|
227
227
|
let(:result_base) do
|
228
228
|
{
|
229
|
-
:
|
230
|
-
:
|
231
|
-
:
|
232
|
-
:
|
233
|
-
:
|
234
|
-
:
|
229
|
+
error: 0,
|
230
|
+
warning: 0,
|
231
|
+
total: 0,
|
232
|
+
success: 0,
|
233
|
+
cancelled: 0,
|
234
|
+
pending: 0,
|
235
235
|
}
|
236
236
|
end
|
237
237
|
let(:task) { FactoryBot.create(:dynflow_task) }
|
238
238
|
|
239
239
|
describe 'without sub tasks' do
|
240
240
|
it 'calculates the progress report correctly' do
|
241
|
-
|
241
|
+
assert_equal result_base, task.sub_tasks_counts
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
@@ -248,22 +248,22 @@ class TasksTest < ActiveSupport::TestCase
|
|
248
248
|
before { task.sub_tasks = [success, failed] }
|
249
249
|
|
250
250
|
it 'calculate the progress report correctly' do
|
251
|
-
expected_result = result_base.merge(:
|
252
|
-
|
251
|
+
expected_result = result_base.merge(success: 1, error: 1, total: 2)
|
252
|
+
assert_equal expected_result, task.sub_tasks_counts
|
253
253
|
end
|
254
254
|
|
255
255
|
it 'calculates the progress report correctly when using batch planning' do
|
256
|
-
result_base = self.result_base.merge(:
|
257
|
-
fake_action = OpenStruct.new(:
|
256
|
+
result_base = self.result_base.merge(success: 1, error: 1, total: 25)
|
257
|
+
fake_action = OpenStruct.new(total_count: 25)
|
258
258
|
task.stubs(:main_action).returns(fake_action)
|
259
259
|
|
260
260
|
task.state = 'stopped'
|
261
|
-
expected_result = result_base.merge(:
|
262
|
-
|
261
|
+
expected_result = result_base.merge(cancelled: 23)
|
262
|
+
assert_equal expected_result, task.sub_tasks_counts
|
263
263
|
|
264
264
|
task.state = 'pending'
|
265
|
-
expected_result = result_base.merge(:
|
266
|
-
|
265
|
+
expected_result = result_base.merge(pending: 23)
|
266
|
+
assert_equal expected_result, task.sub_tasks_counts
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
@@ -284,11 +284,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
284
284
|
let(:task) { FactoryBot.create(:some_task) }
|
285
285
|
|
286
286
|
it 'can indicate it is delayed' do
|
287
|
-
|
288
|
-
|
287
|
+
assert_not_predicate task, :delayed?
|
288
|
+
assert_equal 'Immediate', task.execution_type
|
289
289
|
task.start_at = Time.now.utc + 100
|
290
|
-
|
291
|
-
|
290
|
+
assert_predicate task, :delayed?
|
291
|
+
assert_equal 'Delayed', task.execution_type
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|