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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5280ef80f012ccdd9210e1dadd08a201a20cecba8158d78e6c4820cb367c007e
|
4
|
+
data.tar.gz: bba5cbfeadb51c5bd8f998a3f3439e53d52775d86703535c6359b808149ef24f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2226e22a486c65df96a9dd672b1a360a727482b5038a47d6405ff10fc23849b12077978d898c92467e8c911a79558be1be1004685d7abe99d311d9100677ca56
|
7
|
+
data.tar.gz: 9c3d1498b4aa19d45242ebfc333ccad9d4d2b4b09f1b8d466c9f5dfda9ad09b4ff3d45decd083617a5719ca738ada5f2992915f74a96b8c79a14347997d5afc4
|
@@ -42,6 +42,9 @@ module ForemanTasks
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def update_from_batch_trigger(data, parent = {})
|
45
|
+
# The ID might get overwritten later, but it is a sane default in case of async
|
46
|
+
# triggering where we only get an id of a remote parent
|
47
|
+
self.remote_task_id = execution_plan_id
|
45
48
|
if data['result'] == 'success'
|
46
49
|
self.remote_task_id = data['task_id']
|
47
50
|
self.state = 'triggered'
|
@@ -17,14 +17,14 @@ module ForemanTasks
|
|
17
17
|
get :index
|
18
18
|
assert_response :success
|
19
19
|
data = JSON.parse(response.body)
|
20
|
-
|
20
|
+
assert_equal 5, data['results'].count
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'supports searching' do
|
24
24
|
get :index, params: { :search => 'label = Actions::User::Create' }
|
25
25
|
assert_response :success
|
26
26
|
data = JSON.parse(response.body)
|
27
|
-
|
27
|
+
assert_equal 5, data['results'].count
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'renders task ids when searching by resource id' do
|
@@ -33,15 +33,15 @@ module ForemanTasks
|
|
33
33
|
get :index, params: { :search => "label = Actions::Katello::Product::Create and resource_id = 1" }
|
34
34
|
assert_response :success
|
35
35
|
data = JSON.parse(response.body)
|
36
|
-
|
36
|
+
assert_equal task.id, data['results'].first["id"]
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'supports ordering by duration' do
|
40
40
|
get :index, params: { :sort_by => 'duration' }
|
41
41
|
assert_response :success
|
42
42
|
data = JSON.parse(response.body)
|
43
|
-
|
44
|
-
|
43
|
+
assert_equal 'duration', data.dig('sort', 'by')
|
44
|
+
assert_equal 5, data['results'].count
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'with current taxonomies' do
|
@@ -53,9 +53,9 @@ module ForemanTasks
|
|
53
53
|
get :index, params: { organization_id: org1.id }
|
54
54
|
assert_response :success
|
55
55
|
results = JSON.parse(response.body)['results']
|
56
|
-
|
57
|
-
|
58
|
-
|
56
|
+
assert_equal 6, results.count
|
57
|
+
assert_includes results.map { |r| r['id'] }, org1_task.id
|
58
|
+
assert_not_includes results.map { |r| r['id'] }, org2_task.id
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
@@ -66,7 +66,7 @@ module ForemanTasks
|
|
66
66
|
post :bulk_search, params: { :searches => [{ :type => "task", :task_id => task.id, :search_id => "1" }] }
|
67
67
|
assert_response :success
|
68
68
|
data = JSON.parse(response.body)
|
69
|
-
|
69
|
+
assert_equal task.id, data[0]['results'][0]['id']
|
70
70
|
end
|
71
71
|
|
72
72
|
it 'can search for a specific resource' do
|
@@ -77,7 +77,7 @@ module ForemanTasks
|
|
77
77
|
|
78
78
|
assert_response :success
|
79
79
|
data = JSON.parse(response.body)
|
80
|
-
|
80
|
+
assert_equal task.id, data[0]['results'][0]['id']
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -108,7 +108,7 @@ module ForemanTasks
|
|
108
108
|
get :show, params: { id: task.id }, session: set_session_user
|
109
109
|
assert_response :success
|
110
110
|
data = JSON.parse(response.body)
|
111
|
-
|
111
|
+
assert_equal task.duration.in_seconds.to_s, data['duration']
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -118,7 +118,7 @@ module ForemanTasks
|
|
118
118
|
get :index, session: set_session_user
|
119
119
|
assert_response :success
|
120
120
|
data = JSON.parse(response.body)
|
121
|
-
|
121
|
+
assert_equal task.duration.in_seconds.to_s, data['results'][0]['duration']
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -189,17 +189,17 @@ module ForemanTasks
|
|
189
189
|
wait_for { ForemanTasks::Task.find_by(external_id: triggered.id).state == 'running' }
|
190
190
|
|
191
191
|
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
192
|
-
|
193
|
-
|
192
|
+
assert_equal 'running', task.state
|
193
|
+
assert_equal 'pending', task.result
|
194
194
|
|
195
195
|
callback = Support::DummyProxyAction.proxy.log[:trigger_task].first[1].first[1][:action_input][:callback]
|
196
196
|
post :callback, params: { 'callback' => callback, 'data' => { 'result' => 'success' } }
|
197
197
|
triggered.finished.wait(5)
|
198
198
|
|
199
199
|
task.reload
|
200
|
-
|
201
|
-
|
202
|
-
|
200
|
+
assert_equal 'stopped', task.state
|
201
|
+
assert_equal 'success', task.result
|
202
|
+
assert_equal({ 'result' => 'success' }, task.main_action.output['proxy_output'])
|
203
203
|
end
|
204
204
|
end
|
205
205
|
end
|
@@ -141,30 +141,30 @@ module ForemanTasks
|
|
141
141
|
@controller.stubs(:params).returns(:search => "id = #{task.id}")
|
142
142
|
in_taxonomy_scope(organizations.first) do |_o, _l|
|
143
143
|
results = @controller.send(:filter, ForemanTasks::Task)
|
144
|
-
|
144
|
+
assert_equal [task.id], results.map(&:id).sort
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
148
|
it 'does not scope by taxonomy if unset' do
|
149
149
|
organizations
|
150
150
|
tasks
|
151
|
-
|
151
|
+
assert_equal '', @controller.send(:current_taxonomy_search)
|
152
152
|
results = @controller.send(:filter, ForemanTasks::Task)
|
153
|
-
|
153
|
+
assert_equal tasks.map(&:id).sort, results.map(&:id).sort
|
154
154
|
end
|
155
155
|
|
156
156
|
it 'scopes by organization if set' do
|
157
157
|
scoped, _, unscoped = tasks
|
158
158
|
in_taxonomy_scope(organizations.first) do |o, _l|
|
159
|
-
|
159
|
+
assert_equal "(organization_id = #{o.id})", @controller.send(:current_taxonomy_search)
|
160
160
|
results = @controller.send(:filter, ForemanTasks::Task)
|
161
|
-
|
161
|
+
assert_equal [scoped, unscoped].map(&:id).sort, results.map(&:id).sort
|
162
162
|
end
|
163
163
|
end
|
164
164
|
|
165
165
|
it 'scopes by org and location if set' do
|
166
166
|
in_taxonomy_scope(organizations.first, FactoryBot.create(:location)) do |o, l|
|
167
|
-
|
167
|
+
assert_equal "(organization_id = #{o.id} AND location_id = #{l.id})", @controller.send(:current_taxonomy_search)
|
168
168
|
end
|
169
169
|
end
|
170
170
|
end
|
@@ -10,9 +10,9 @@ module ForemanTasks
|
|
10
10
|
it 'prepares items for index correctly' do
|
11
11
|
stubs(:action_name).returns('index')
|
12
12
|
items = breadcrumb_items
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
assert_equal 1, items.count
|
14
|
+
assert_equal 'Tasks', items.first[:caption]
|
15
|
+
assert_nil items.first[:url]
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'prepares items for show correctly' do
|
@@ -20,8 +20,8 @@ module ForemanTasks
|
|
20
20
|
@task.action = 'A task'
|
21
21
|
stubs(:action_name).returns('show')
|
22
22
|
items = breadcrumb_items
|
23
|
-
|
24
|
-
|
23
|
+
assert_equal(['Tasks', 'A task'], items.map { |i| i[:caption] })
|
24
|
+
assert_nil items.last[:url]
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'prepares items for sub tasks correctly' do
|
@@ -31,8 +31,8 @@ module ForemanTasks
|
|
31
31
|
@task.action = 'A task'
|
32
32
|
stubs(:action_name).returns('sub_tasks')
|
33
33
|
items = breadcrumb_items
|
34
|
-
|
35
|
-
|
34
|
+
assert_equal(['Tasks', 'A task', 'Sub tasks'], items.map { |i| i[:caption] })
|
35
|
+
assert_nil items.last[:url]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -12,11 +12,11 @@ module ForemanTasks
|
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'formats the task input properly' do
|
15
|
-
|
15
|
+
assert_equal "Create user 'Anonymous Admin'", format_task_input(@task)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'displays the dash if task is nil' do
|
19
|
-
|
19
|
+
assert_equal '-', format_task_input(nil)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -37,7 +37,7 @@ module ForemanTasks
|
|
37
37
|
|
38
38
|
it 'formats the task input properly' do
|
39
39
|
response = "product 'product-2'; organization 'test-0'"
|
40
|
-
|
40
|
+
assert_equal("Create #{response}", format_task_input(@task))
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -29,21 +29,21 @@ module ForemanTasks
|
|
29
29
|
it 'stores the id on planning' do
|
30
30
|
::Logging.mdc['request'] = expected_id
|
31
31
|
action = create_and_plan_action(DummyAction)
|
32
|
-
|
32
|
+
assert_equal expected_id, action.input[:current_request_id]
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'restores the id for run' do
|
36
36
|
::Logging.mdc['request'] = expected_id
|
37
37
|
action = create_and_plan_action(DummyAction, true)
|
38
38
|
action = run_action action
|
39
|
-
|
39
|
+
assert_equal expected_id, action.output[:run_result]
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'restores the id for finalize' do
|
43
43
|
::Logging.mdc['request'] = expected_id
|
44
44
|
action = create_and_plan_action(DummyAction, true)
|
45
45
|
action = finalize_action(run_action(action))
|
46
|
-
|
46
|
+
assert_equal expected_id, action.output[:finalize_result]
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
@@ -11,22 +11,22 @@ module ForemanTasks
|
|
11
11
|
let(:default_intervals) { [0.5, 1, 2, 4, 8, 16] }
|
12
12
|
|
13
13
|
it 'is extends the polling action module' do
|
14
|
-
|
14
|
+
assert_equal ForemanTasks::Concerns::PollingActionExtensions, ::Dynflow::Action::Polling.ancestors.first
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'does not modify polling intervals by default' do
|
18
|
-
|
18
|
+
assert_equal default_intervals, Action.allocate.poll_intervals
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'cannot make intervals shorter than 0.5 seconds' do
|
22
22
|
Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns 0
|
23
|
-
|
23
|
+
assert_equal default_intervals.map { 0.5 }, Action.allocate.poll_intervals
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'can be used to make the intervals longer' do
|
27
27
|
value = 5
|
28
28
|
Setting.expects(:[]).with(:foreman_tasks_polling_multiplier).returns value
|
29
|
-
|
29
|
+
assert_equal default_intervals.map { |i| i * value }, Action.allocate.poll_intervals
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -26,7 +26,7 @@ class GenerateTaskActionsTest < ActiveSupport::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
assert_match(%r{Generating action for #{tasks.count} tasks}, stdout)
|
29
|
-
|
29
|
+
assert_equal tasks.count, ForemanTasks::Task.where(:action => label).count
|
30
30
|
assert_match(%r{Processed #{tasks.count}/#{tasks.count} tasks}, stdout)
|
31
31
|
end
|
32
32
|
|
@@ -48,15 +48,15 @@ module ForemanTasks
|
|
48
48
|
end
|
49
49
|
|
50
50
|
specify 'the sub-plan stores the information about its parent' do
|
51
|
-
|
52
|
-
|
51
|
+
assert_equal 1, task.sub_tasks.size
|
52
|
+
assert_equal ChildAction.name, task.sub_tasks.first.label
|
53
53
|
end
|
54
54
|
|
55
55
|
specify "the locks of the sub-plan don't colide with the locks of its parent" do
|
56
56
|
child_task = task.sub_tasks.first
|
57
|
-
assert_not
|
57
|
+
assert_not child_task.locks.any?, "the lock is ensured by the parent"
|
58
58
|
found = ForemanTasks::Link.for_resource(user).where(:task_id => child_task.id).any?
|
59
|
-
assert
|
59
|
+
assert found, "the action is linked properly"
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -37,20 +37,20 @@ module ForemanTasks
|
|
37
37
|
Target.expects(:unscoped).returns(Target)
|
38
38
|
Target.expects(:where).with(:id => targets.map(&:id)).returns(targets)
|
39
39
|
|
40
|
-
|
40
|
+
assert_equal targets.count, task.sub_tasks.count
|
41
41
|
success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
|
42
|
-
|
43
|
-
|
42
|
+
assert_empty failed
|
43
|
+
assert_equal 5, success.count
|
44
44
|
end
|
45
45
|
|
46
46
|
specify 'it plans a task for each target even if target cannot be found' do
|
47
47
|
Target.expects(:unscoped).returns(Target)
|
48
48
|
Target.expects(:where).with(:id => targets.map(&:id)).returns(targets.take(4))
|
49
49
|
|
50
|
-
|
50
|
+
assert_equal targets.count, task.sub_tasks.count
|
51
51
|
success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
|
52
|
-
|
53
|
-
|
52
|
+
assert_equal 4, success.count
|
53
|
+
assert_equal 1, failed.count
|
54
54
|
end
|
55
55
|
|
56
56
|
specify "it handles keyword arguments as indifferent hashes when they're being flattened" do
|
@@ -61,8 +61,8 @@ module ForemanTasks
|
|
61
61
|
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
62
62
|
wait_for { task.reload.state == 'stopped' }
|
63
63
|
task = task.sub_tasks.first
|
64
|
-
|
65
|
-
|
64
|
+
assert_equal 7, task.input[:kw_string]
|
65
|
+
assert_equal 7, task.input[:kw_symbol]
|
66
66
|
end
|
67
67
|
|
68
68
|
specify 'it allows setting concurrency limit' do
|
@@ -71,7 +71,7 @@ module ForemanTasks
|
|
71
71
|
|
72
72
|
triggered = ForemanTasks.trigger(ParentAction, ChildAction, targets, concurrency_limit: 25)
|
73
73
|
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
74
|
-
|
74
|
+
assert_equal 25, task.execution_plan.entry_action.concurrency_limit
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
@@ -46,17 +46,17 @@ module ForemanTasks
|
|
46
46
|
'proxy_action_name' => 'Proxy::DummyAction',
|
47
47
|
'callback' => { 'task_id' => Support::DummyProxyAction.proxy.uuid, 'step_id' => @run_step_id } } }
|
48
48
|
expected_call = ['support', { @action.execution_plan_id => action_input }]
|
49
|
-
|
49
|
+
assert_equal expected_call, proxy_call
|
50
50
|
end
|
51
51
|
|
52
52
|
describe 'with batch triggering' do
|
53
53
|
let(:batch_triggering) { true }
|
54
54
|
it 'create remote tasks for batch triggering' do
|
55
55
|
task = RemoteTask.first
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
56
|
+
assert_equal 'new', task.state
|
57
|
+
assert_equal @action.execution_plan_id, task.execution_plan_id
|
58
|
+
assert_equal 'support', task.operation
|
59
|
+
assert_nil task.remote_task_id
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -65,22 +65,22 @@ module ForemanTasks
|
|
65
65
|
it "doesn't trigger the corresponding action again on the proxy" do
|
66
66
|
action = run_action(@action)
|
67
67
|
|
68
|
-
|
68
|
+
assert_equal :suspended, action.state
|
69
69
|
|
70
|
-
|
70
|
+
assert_equal 1, Support::DummyProxyAction.proxy.log[:trigger_task].size
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'supports skipping' do
|
75
75
|
action = run_action(@action, ::Dynflow::Action::Skip)
|
76
|
-
|
76
|
+
assert_equal :success, action.state
|
77
77
|
end
|
78
78
|
|
79
79
|
describe 'cancel' do
|
80
80
|
it 'sends the cancel event to the proxy when the cancel event is sent for the first time' do
|
81
81
|
action = run_action(@action, ::Dynflow::Action::Cancellable::Cancel)
|
82
|
-
|
83
|
-
|
82
|
+
assert_equal [action.execution_plan_id], Support::DummyProxyAction.proxy.log[:cancel_task].first
|
83
|
+
assert_equal :suspended, action.state
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'cancels the action immediatelly when cancel event is sent for the second time' do
|
@@ -91,14 +91,14 @@ module ForemanTasks
|
|
91
91
|
e
|
92
92
|
end
|
93
93
|
|
94
|
-
|
95
|
-
|
94
|
+
assert_equal 1, Support::DummyProxyAction.proxy.log[:cancel_task].size
|
95
|
+
assert_match 'Cancel enforced', error.message
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
99
|
it 'saves the data comming from the proxy to the output and finishes' do
|
100
100
|
action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
|
101
|
-
|
101
|
+
assert_equal({ 'result' => 'success' }, action.output[:proxy_output])
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'handles connection errors' do
|
@@ -112,12 +112,12 @@ module ForemanTasks
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
action = run_stubbed_action.call action
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
assert_equal :suspended, action.state
|
116
|
+
assert_equal 1, action.world.clock.pending_pings.length
|
117
|
+
assert_equal 1, action.output[:metadata][:failed_proxy_tasks].length
|
118
118
|
2.times { action.output[:metadata][:failed_proxy_tasks] << {} }
|
119
|
-
|
120
|
-
|
119
|
+
assert_raises(Errno::ECONNREFUSED) { run_stubbed_action.call action }
|
120
|
+
assert_equal :error, action.state
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'hides secrets' do
|
@@ -127,12 +127,12 @@ module ForemanTasks
|
|
127
127
|
'foo' => 'bar',
|
128
128
|
'secrets' => secrets)
|
129
129
|
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
130
|
-
|
130
|
+
assert_equal 'Secrets hidden', task.input[:secrets]
|
131
131
|
triggered.future.wait # Wait for the task to get triggered before leaving the test
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'wipes secrets' do
|
135
|
-
|
135
|
+
assert_equal secrets, @action.input[:secrets]
|
136
136
|
action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
|
137
137
|
|
138
138
|
# #wipe_secrets! gets called as a hook, hooks are not triggered when using action testing helpers
|
@@ -50,45 +50,45 @@ module ForemanTasks
|
|
50
50
|
end
|
51
51
|
|
52
52
|
specify 'it triggers the repeat when task is cancelled' do
|
53
|
-
|
54
|
-
|
53
|
+
assert_predicate recurring_task, :delayed?
|
54
|
+
assert_equal 1, recurring_logic.tasks.count
|
55
55
|
cancelled_events = recurring_task.execution_plan.cancel
|
56
56
|
cancelled_events.each(&:wait!)
|
57
57
|
recurring_logic.reload
|
58
|
-
|
58
|
+
assert_equal 2, recurring_logic.tasks.count
|
59
59
|
new_task = recurring_logic.tasks.find { |task| task.id != recurring_task.id }
|
60
|
-
|
61
|
-
|
60
|
+
assert_equal args, new_task.execution_plan.delay_record.args
|
61
|
+
assert_equal recurring_task.start_at + 1.year, new_task.start_at
|
62
62
|
end
|
63
63
|
|
64
64
|
specify 'it triggers the repeat when the task goes into planned state' do
|
65
65
|
delay_options = recurring_logic.generate_delay_options
|
66
66
|
task = ForemanTasks.delay HookedAction, delay_options, *args
|
67
|
-
|
67
|
+
assert_equal 1, recurring_logic.tasks.count
|
68
68
|
|
69
69
|
# Perform planning of the delayed plan
|
70
70
|
task.execution_plan.delay_record.plan
|
71
71
|
|
72
72
|
# Check a repetition was planned
|
73
|
-
|
73
|
+
assert_equal 2, recurring_logic.tasks.count
|
74
74
|
end
|
75
75
|
|
76
76
|
specify 'it does not trigger repeat when failing in run' do
|
77
77
|
delay_options = recurring_logic.generate_delay_options
|
78
78
|
task = ForemanTasks.delay HookedAction, delay_options, true, args.last
|
79
|
-
|
79
|
+
assert_equal 1, recurring_logic.tasks.count
|
80
80
|
|
81
81
|
# Perform the planning (trigger repeat)
|
82
82
|
task.execution_plan.delay_record.plan
|
83
|
-
|
83
|
+
assert_equal 2, recurring_logic.tasks.count
|
84
84
|
|
85
85
|
# Let it fail
|
86
86
|
task.execution_plan.delay_record.execute.finished.wait
|
87
87
|
task.reload
|
88
|
-
|
88
|
+
assert_equal 'error', task.result
|
89
89
|
|
90
90
|
# Check no new repetitions were planned
|
91
|
-
|
91
|
+
assert_equal 2, recurring_logic.tasks.count
|
92
92
|
end
|
93
93
|
|
94
94
|
specify 'it resets the request id on repetition' do
|
@@ -99,13 +99,13 @@ module ForemanTasks
|
|
99
99
|
|
100
100
|
delay_options = recurring_logic.generate_delay_options
|
101
101
|
task = ForemanTasks.delay HookedAction, delay_options, true, args.last
|
102
|
-
|
102
|
+
assert_equal expected_id, task.input[:current_request_id]
|
103
103
|
|
104
104
|
SecureRandom.stubs(:uuid).returns(new_id)
|
105
105
|
# Perform the planning (trigger repeat)
|
106
106
|
task.execution_plan.delay_record.plan
|
107
107
|
repetition = recurring_logic.tasks.find { |t| t.id != task.id }
|
108
|
-
|
108
|
+
assert_equal new_id, repetition.input[:current_request_id]
|
109
109
|
ensure
|
110
110
|
::Logging.mdc['request'] = old_id
|
111
111
|
end
|
@@ -114,11 +114,11 @@ module ForemanTasks
|
|
114
114
|
delay_options = past_recurring_logic.generate_delay_options
|
115
115
|
delay_options[:start_at] = Time.zone.now - 1.week
|
116
116
|
task = ForemanTasks.delay HookedAction, delay_options, *args
|
117
|
-
|
117
|
+
assert_equal 1, past_recurring_logic.tasks.count
|
118
118
|
|
119
119
|
task.execution_plan.delay_record.plan
|
120
120
|
# Post planning, a new task should be scheduled
|
121
|
-
|
121
|
+
assert_equal 2, past_recurring_logic.tasks.count
|
122
122
|
# The scheduled task should have the start date according to cron in future.
|
123
123
|
assert_equal (Time.zone.now + 1.minute).change(:sec => 0), past_recurring_logic.tasks.where(:state => "scheduled").first.start_at
|
124
124
|
end
|
@@ -13,8 +13,8 @@ module ForemanTasks
|
|
13
13
|
describe 'triggering' do
|
14
14
|
it 'doesnt run anything on trigger' do
|
15
15
|
Actions::TriggerProxyBatch.any_instance.expects(:trigger_remote_tasks_batch).never
|
16
|
-
|
17
|
-
|
16
|
+
assert_equal :suspended, triggered.state
|
17
|
+
assert_equal 0, triggered.output[:planned_count]
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'triggers remote tasks on TriggerNextBatch' do
|
@@ -37,7 +37,7 @@ module ForemanTasks
|
|
37
37
|
Actions::TriggerProxyBatch.any_instance.expects(:trigger_remote_tasks_batch).once
|
38
38
|
triggered.output[:planned_count] = 0
|
39
39
|
action = run_action(triggered, Actions::TriggerProxyBatch::TriggerLastBatch)
|
40
|
-
|
40
|
+
assert_equal :success, action.state
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
@@ -57,7 +57,7 @@ module ForemanTasks
|
|
57
57
|
ForemanTasks::RemoteTask.expects(:batch_trigger).with(proxy_operation_name, grouped_remote_batch)
|
58
58
|
|
59
59
|
triggered.trigger_remote_tasks_batch
|
60
|
-
|
60
|
+
assert_equal batch_size, triggered.output[:planned_count]
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|