foreman-tasks 2.0.3 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/js_tests.yml +27 -0
  3. data/.github/workflows/ruby_tests.yml +74 -0
  4. data/.rubocop.yml +12 -4
  5. data/.rubocop_todo.yml +32 -25
  6. data/Gemfile +5 -0
  7. data/app/controllers/foreman_tasks/api/tasks_controller.rb +31 -58
  8. data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +1 -1
  9. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +7 -0
  10. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +3 -3
  11. data/app/models/foreman_tasks/recurring_logic.rb +4 -4
  12. data/app/models/foreman_tasks/task.rb +11 -0
  13. data/app/models/foreman_tasks/task/dynflow_task.rb +27 -33
  14. data/app/models/foreman_tasks/task/status_explicator.rb +1 -1
  15. data/app/models/foreman_tasks/triggering.rb +1 -1
  16. data/app/models/setting/foreman_tasks.rb +1 -1
  17. data/app/views/foreman_tasks/api/tasks/index.json.rabl +2 -0
  18. data/app/views/foreman_tasks/recurring_logics/index.html.erb +3 -1
  19. data/config/routes.rb +2 -1
  20. data/db/migrate/20200517215015_rename_bookmarks_controller.rb +2 -2
  21. data/db/seeds.d/30-notification_blueprints.rb +7 -7
  22. data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
  23. data/lib/foreman_tasks/cleaner.rb +4 -6
  24. data/lib/foreman_tasks/dynflow/configuration.rb +1 -1
  25. data/lib/foreman_tasks/dynflow/persistence.rb +4 -6
  26. data/lib/foreman_tasks/engine.rb +2 -2
  27. data/lib/foreman_tasks/version.rb +1 -1
  28. data/package.json +0 -1
  29. data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
  30. data/test/controllers/api/tasks_controller_test.rb +7 -7
  31. data/test/controllers/tasks_controller_test.rb +6 -6
  32. data/test/core/unit/runner_test.rb +20 -20
  33. data/test/core/unit/task_launcher_test.rb +8 -8
  34. data/test/helpers/foreman_tasks/foreman_tasks_helper_test.rb +7 -7
  35. data/test/helpers/foreman_tasks/tasks_helper_test.rb +3 -3
  36. data/test/lib/actions/middleware/keep_current_request_id_test.rb +3 -3
  37. data/test/support/history_tasks_builder.rb +1 -1
  38. data/test/tasks/generate_task_actions_test.rb +1 -1
  39. data/test/unit/actions/action_with_sub_plans_test.rb +2 -2
  40. data/test/unit/actions/bulk_action_test.rb +6 -6
  41. data/test/unit/actions/proxy_action_test.rb +20 -20
  42. data/test/unit/actions/recurring_action_test.rb +30 -32
  43. data/test/unit/cleaner_test.rb +24 -24
  44. data/test/unit/dashboard_table_filter_test.rb +5 -5
  45. data/test/unit/otp_manager_test.rb +2 -2
  46. data/test/unit/proxy_selector_test.rb +9 -9
  47. data/test/unit/recurring_logic_test.rb +32 -38
  48. data/test/unit/remote_task_test.rb +2 -2
  49. data/test/unit/task_groups_test.rb +4 -4
  50. data/test/unit/task_test.rb +18 -18
  51. data/test/unit/triggering_test.rb +8 -8
  52. data/test/unit/troubleshooting_help_generator_test.rb +6 -6
  53. data/test/unit/ui_notifications_test.rb +11 -11
  54. data/webpack/ForemanTasks/Components/TaskDetails/Components/RunningSteps.js +3 -3
  55. data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +8 -157
  56. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskButtons.js +168 -0
  57. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +6 -7
  58. data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskSkeleton.js +48 -0
  59. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +1 -1
  60. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +12 -70
  61. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskButtons.test.js +95 -0
  62. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +78 -225
  63. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskButtons.test.js.snap +212 -0
  64. data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +8 -4
  65. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.js +87 -70
  66. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +48 -125
  67. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -16
  68. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +55 -29
  69. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +2 -2
  70. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +6 -0
  71. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +2 -18
  72. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +77 -27
  73. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +14 -101
  74. data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -3
  75. data/webpack/ForemanTasks/Components/common/urlHelpers.js +7 -0
  76. data/webpack/ForemanTasks/ForemanTasksReducers.js +0 -2
  77. data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
  78. data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
  79. data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
  80. data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
  81. metadata +17 -14
  82. data/.travis.yml +0 -7
  83. data/script/travis_run_js_tests.sh +0 -7
  84. data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -38
  85. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +0 -33
  86. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsReducer.test.js.snap +0 -26
  87. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/integration.test.js.snap +0 -122
  88. data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +0 -72
  89. data/webpack/__mocks__/foremanReact/redux/API.js +0 -7
@@ -17,15 +17,15 @@ module ForemanTasksCore
17
17
 
18
18
  it 'triggers an action' do
19
19
  Support::DummyDynflowAction.any_instance.expects(:plan).with do |arg|
20
- arg.must_equal(expected_result)
20
+ _(arg).must_equal(expected_result)
21
21
  end
22
22
  launcher.launch!(launcher_input)
23
23
  end
24
24
 
25
25
  it 'provides results' do
26
26
  plan = launcher.launch!(launcher_input).finished.value!
27
- launcher.results[:result].must_equal 'success'
28
- plan.result.must_equal :success
27
+ _(launcher.results[:result]).must_equal 'success'
28
+ _(plan.result).must_equal :success
29
29
  end
30
30
  end
31
31
 
@@ -36,17 +36,17 @@ module ForemanTasksCore
36
36
  Support::DummyDynflowAction.any_instance.expects(:plan).with { |arg| arg == expected_result }.twice
37
37
  parent = launcher.launch!('foo' => launcher_input, 'bar' => launcher_input)
38
38
  plan = parent.finished.value!
39
- plan.result.must_equal :success
40
- plan.sub_plans.count.must_equal 2
39
+ _(plan.result).must_equal :success
40
+ _(plan.sub_plans.count).must_equal 2
41
41
  end
42
42
 
43
43
  it 'provides results' do
44
44
  launcher.launch!('foo' => launcher_input, 'bar' => launcher_input)
45
- launcher.results.keys.must_equal %w[foo bar]
45
+ _(launcher.results.keys).must_equal %w[foo bar]
46
46
  launcher.results.values.each do |result|
47
47
  plan = ForemanTasks.dynflow.world.persistence.load_execution_plan(result[:task_id])
48
- result[:result].must_equal 'success'
49
- plan.result.must_equal :success
48
+ _(result[:result]).must_equal 'success'
49
+ _(plan.result).must_equal :success
50
50
  end
51
51
  end
52
52
  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
- items.count.must_equal 1
14
- items.first[:caption].must_equal 'Tasks'
15
- items.first[:url].must_be_nil
13
+ _(items.count).must_equal 1
14
+ _(items.first[:caption]).must_equal 'Tasks'
15
+ _(items.first[:url]).must_be_nil
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
- items.map { |i| i[:caption] }.must_equal ['Tasks', 'A task']
24
- items.last[:url].must_be_nil
23
+ _(items.map { |i| i[:caption] }).must_equal ['Tasks', 'A task']
24
+ _(items.last[:url]).must_be_nil
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
- items.map { |i| i[:caption] }.must_equal ['Tasks', 'A task', 'Sub tasks']
35
- items.last[:url].must_be_nil
34
+ _(items.map { |i| i[:caption] }).must_equal ['Tasks', 'A task', 'Sub tasks']
35
+ _(items.last[:url]).must_be_nil
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
- format_task_input(@task).must_equal("Create user 'Anonymous Admin'")
15
+ _(format_task_input(@task)).must_equal("Create user 'Anonymous Admin'")
16
16
  end
17
17
 
18
18
  it 'displays the dash if task is nil' do
19
- format_task_input(nil).must_equal('-')
19
+ _(format_task_input(nil)).must_equal('-')
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
- format_task_input(@task).must_equal("Create #{response}")
40
+ _(format_task_input(@task)).must_equal("Create #{response}")
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
- action.input[:current_request_id].must_equal expected_id
32
+ _(action.input[:current_request_id]).must_equal expected_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
- action.output[:run_result].must_equal expected_id
39
+ _(action.output[:run_result]).must_equal expected_id
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
- action.output[:finalize_result].must_equal expected_id
46
+ _(action.output[:finalize_result]).must_equal expected_id
47
47
  end
48
48
  end
49
49
  end
@@ -5,7 +5,7 @@ class HistoryTasksBuilder
5
5
  by_result: {
6
6
  'success' => { recent: 2, total: 4 },
7
7
  'warning' => { recent: 1, total: 2 },
8
- 'error' => { recent: 0, total: 1 }
8
+ 'error' => { recent: 0, total: 1 },
9
9
  } } }
10
10
  end
11
11
 
@@ -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
- ForemanTasks::Task.where(:action => label).count.must_equal tasks.count
29
+ _(ForemanTasks::Task.where(:action => label).count).must_equal tasks.count
30
30
  assert_match(%r{Processed #{tasks.count}/#{tasks.count} tasks}, stdout)
31
31
  end
32
32
 
@@ -43,8 +43,8 @@ module ForemanTasks
43
43
  end
44
44
 
45
45
  specify 'the sub-plan stores the information about its parent' do
46
- task.sub_tasks.size.must_equal 1
47
- task.sub_tasks.first.label.must_equal ChildAction.name
46
+ _(task.sub_tasks.size).must_equal 1
47
+ _(task.sub_tasks.first.label).must_equal ChildAction.name
48
48
  end
49
49
 
50
50
  specify "the locks of the sub-plan don't colide with the locks of its parent" do
@@ -31,20 +31,20 @@ module ForemanTasks
31
31
  Target.expects(:unscoped).returns(Target)
32
32
  Target.expects(:where).with(:id => targets.map(&:id)).returns(targets)
33
33
 
34
- task.sub_tasks.count.must_equal targets.count
34
+ _(task.sub_tasks.count).must_equal targets.count
35
35
  success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
36
- failed.must_be :empty?
37
- success.count.must_equal 5
36
+ _(failed).must_be :empty?
37
+ _(success.count).must_equal 5
38
38
  end
39
39
 
40
40
  specify 'it plans a task for each target even if target cannot be found' do
41
41
  Target.expects(:unscoped).returns(Target)
42
42
  Target.expects(:where).with(:id => targets.map(&:id)).returns(targets.take(4))
43
43
 
44
- task.sub_tasks.count.must_equal targets.count
44
+ _(task.sub_tasks.count).must_equal targets.count
45
45
  success, failed = task.sub_tasks.partition { |sub_task| sub_task.result == 'success' }
46
- success.count.must_equal 4
47
- failed.count.must_equal 1
46
+ _(success.count).must_equal 4
47
+ _(failed.count).must_equal 1
48
48
  end
49
49
  end
50
50
  end
@@ -37,17 +37,17 @@ module ForemanTasks
37
37
  'proxy_action_name' => 'Proxy::DummyAction',
38
38
  "proxy_version" => { "major" => 1, "minor" => 21, "patch" => 0 },
39
39
  'callback' => { 'task_id' => Support::DummyProxyAction.proxy.uuid, 'step_id' => @action.run_step_id } }]
40
- proxy_call.must_equal(expected_call)
40
+ _(proxy_call).must_equal(expected_call)
41
41
  end
42
42
 
43
43
  describe 'with batch triggering' do
44
44
  let(:batch_triggering) { true }
45
45
  it 'create remote tasks for batch triggering' do
46
46
  task = RemoteTask.first
47
- task.state.must_equal 'new'
48
- task.execution_plan_id.must_equal @action.execution_plan_id
49
- task.operation.must_equal 'support'
50
- task.remote_task_id.must_be :nil?
47
+ _(task.state).must_equal 'new'
48
+ _(task.execution_plan_id).must_equal @action.execution_plan_id
49
+ _(task.operation).must_equal 'support'
50
+ _(task.remote_task_id).must_be :nil?
51
51
  end
52
52
  end
53
53
  end
@@ -56,22 +56,22 @@ module ForemanTasks
56
56
  it "doesn't trigger the corresponding action again on the proxy" do
57
57
  action = run_action(@action)
58
58
 
59
- action.state.must_equal :suspended
59
+ _(action.state).must_equal :suspended
60
60
 
61
- Support::DummyProxyAction.proxy.log[:trigger_task].size.must_equal 1
61
+ _(Support::DummyProxyAction.proxy.log[:trigger_task].size).must_equal 1
62
62
  end
63
63
  end
64
64
 
65
65
  it 'supports skipping' do
66
66
  action = run_action(@action, ::Dynflow::Action::Skip)
67
- action.state.must_equal :success
67
+ _(action.state).must_equal :success
68
68
  end
69
69
 
70
70
  describe 'cancel' do
71
71
  it 'sends the cancel event to the proxy when the cancel event is sent for the first time' do
72
72
  action = run_action(@action, ::Dynflow::Action::Cancellable::Cancel)
73
- Support::DummyProxyAction.proxy.log[:cancel_task].first.must_equal [Support::DummyProxyAction.proxy.uuid]
74
- action.state.must_equal :suspended
73
+ _(Support::DummyProxyAction.proxy.log[:cancel_task].first).must_equal [Support::DummyProxyAction.proxy.uuid]
74
+ _(action.state).must_equal :suspended
75
75
  end
76
76
 
77
77
  it 'cancels the action immediatelly when cancel event is sent for the second time' do
@@ -82,14 +82,14 @@ module ForemanTasks
82
82
  e
83
83
  end
84
84
 
85
- Support::DummyProxyAction.proxy.log[:cancel_task].size.must_equal 1
86
- error.message.must_match 'Cancel enforced'
85
+ _(Support::DummyProxyAction.proxy.log[:cancel_task].size).must_equal 1
86
+ _(error.message).must_match 'Cancel enforced'
87
87
  end
88
88
  end
89
89
 
90
90
  it 'saves the data comming from the proxy to the output and finishes' do
91
91
  action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
92
- action.output[:proxy_output].must_equal('result' => 'success')
92
+ _(action.output[:proxy_output]).must_equal('result' => 'success')
93
93
  end
94
94
 
95
95
  it 'handles connection errors' do
@@ -103,12 +103,12 @@ module ForemanTasks
103
103
  end
104
104
  end
105
105
  action = run_stubbed_action.call action
106
- action.state.must_equal :suspended
107
- action.world.clock.pending_pings.length.must_equal 1
108
- action.output[:metadata][:failed_proxy_tasks].length.must_equal 1
106
+ _(action.state).must_equal :suspended
107
+ _(action.world.clock.pending_pings.length).must_equal 1
108
+ _(action.output[:metadata][:failed_proxy_tasks].length).must_equal 1
109
109
  2.times { action.output[:metadata][:failed_proxy_tasks] << {} }
110
- proc { action = run_stubbed_action.call action }.must_raise(Errno::ECONNREFUSED)
111
- action.state.must_equal :error
110
+ _ { proc { action = run_stubbed_action.call action } }.must_raise(Errno::ECONNREFUSED)
111
+ _(action.state).must_equal :error
112
112
  end
113
113
 
114
114
  it 'hides secrets' do
@@ -118,12 +118,12 @@ module ForemanTasks
118
118
  'foo' => 'bar',
119
119
  'secrets' => secrets)
120
120
  task = ForemanTasks::Task.where(:external_id => triggered.id).first
121
- task.input[:secrets].must_equal 'Secrets hidden'
121
+ _(task.input[:secrets]).must_equal 'Secrets hidden'
122
122
  triggered.future.wait # Wait for the task to get triggered before leaving the test
123
123
  end
124
124
 
125
125
  it 'wipes secrets' do
126
- @action.input[:secrets].must_equal secrets
126
+ _(@action.input[:secrets]).must_equal secrets
127
127
  action = run_action(@action, ::Actions::ProxyAction::CallbackData.new('result' => 'success'))
128
128
 
129
129
  # #wipe_secrets! gets called as a hook, hooks are not triggered when using action testing helpers
@@ -22,7 +22,7 @@ module ForemanTasks
22
22
  :minutes => 0,
23
23
  :hours => 12,
24
24
  :days => 1,
25
- :months => ((Time.zone.now.month + 1) % 12) + 1
25
+ :months => ((Time.zone.now.month + 1) % 12) + 1,
26
26
  }
27
27
  end
28
28
 
@@ -50,77 +50,75 @@ module ForemanTasks
50
50
  end
51
51
 
52
52
  specify 'it triggers the repeat when task is cancelled' do
53
- recurring_task.must_be :delayed?
54
- recurring_logic.tasks.count.must_equal 1
53
+ _(recurring_task).must_be :delayed?
54
+ _(recurring_logic.tasks.count).must_equal 1
55
55
  cancelled_events = recurring_task.execution_plan.cancel
56
56
  cancelled_events.each(&:wait!)
57
57
  recurring_logic.reload
58
- recurring_logic.tasks.count.must_equal 2
58
+ _(recurring_logic.tasks.count).must_equal 2
59
59
  new_task = recurring_logic.tasks.find { |task| task.id != recurring_task.id }
60
- new_task.execution_plan.delay_record.args.must_equal args
61
- new_task.start_at.must_equal(recurring_task.start_at + 1.year)
60
+ _(new_task.execution_plan.delay_record.args).must_equal args
61
+ _(new_task.start_at).must_equal(recurring_task.start_at + 1.year)
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
- recurring_logic.tasks.count.must_equal 1
67
+ _(recurring_logic.tasks.count).must_equal 1
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
- recurring_logic.tasks.count.must_equal 2
73
+ _(recurring_logic.tasks.count).must_equal 2
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
- recurring_logic.tasks.count.must_equal 1
79
+ _(recurring_logic.tasks.count).must_equal 1
80
80
 
81
81
  # Perform the planning (trigger repeat)
82
82
  task.execution_plan.delay_record.plan
83
- recurring_logic.tasks.count.must_equal 2
83
+ _(recurring_logic.tasks.count).must_equal 2
84
84
 
85
85
  # Let it fail
86
86
  task.execution_plan.delay_record.execute.finished.wait
87
87
  task.reload
88
- task.result.must_equal 'error'
88
+ _(task.result).must_equal 'error'
89
89
 
90
90
  # Check no new repetitions were planned
91
- recurring_logic.tasks.count.must_equal 2
91
+ _(recurring_logic.tasks.count).must_equal 2
92
92
  end
93
93
 
94
94
  specify 'it resets the request id on repetition' do
95
- begin
96
- expected_id = 'an_id'
97
- new_id = SecureRandom.uuid
98
- old_id = ::Logging.mdc['request']
99
- ::Logging.mdc['request'] = expected_id
100
-
101
- delay_options = recurring_logic.generate_delay_options
102
- task = ForemanTasks.delay HookedAction, delay_options, true, args.last
103
- task.input[:current_request_id].must_equal expected_id
104
-
105
- SecureRandom.stubs(:uuid).returns(new_id)
106
- # Perform the planning (trigger repeat)
107
- task.execution_plan.delay_record.plan
108
- repetition = recurring_logic.tasks.find { |t| t.id != task.id }
109
- repetition.input[:current_request_id].must_equal new_id
110
- ensure
111
- ::Logging.mdc['request'] = old_id
112
- end
95
+ expected_id = 'an_id'
96
+ new_id = SecureRandom.uuid
97
+ old_id = ::Logging.mdc['request']
98
+ ::Logging.mdc['request'] = expected_id
99
+
100
+ delay_options = recurring_logic.generate_delay_options
101
+ task = ForemanTasks.delay HookedAction, delay_options, true, args.last
102
+ _(task.input[:current_request_id]).must_equal expected_id
103
+
104
+ SecureRandom.stubs(:uuid).returns(new_id)
105
+ # Perform the planning (trigger repeat)
106
+ task.execution_plan.delay_record.plan
107
+ repetition = recurring_logic.tasks.find { |t| t.id != task.id }
108
+ _(repetition.input[:current_request_id]).must_equal new_id
109
+ ensure
110
+ ::Logging.mdc['request'] = old_id
113
111
  end
114
112
 
115
113
  specify 'it does not trigger tasks in the past' do
116
114
  delay_options = past_recurring_logic.generate_delay_options
117
115
  delay_options[:start_at] = Time.zone.now - 1.week
118
116
  task = ForemanTasks.delay HookedAction, delay_options, *args
119
- past_recurring_logic.tasks.count.must_equal 1
117
+ _(past_recurring_logic.tasks.count).must_equal 1
120
118
 
121
119
  task.execution_plan.delay_record.plan
122
120
  # Post planning, a new task should be scheduled
123
- past_recurring_logic.tasks.count.must_equal 2
121
+ _(past_recurring_logic.tasks.count).must_equal 2
124
122
  # The scheduled task should have the start date according to cron in future.
125
123
  assert_equal (Time.zone.now + 1.minute).change(:sec => 0), past_recurring_logic.tasks.where(:state => "scheduled").first.start_at
126
124
  end
@@ -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
- ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
26
- ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id).must_equal tasks_to_keep.map(&:id).sort
25
+ _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
26
+ _(ForemanTasks::Task.where(id: tasks_to_keep).order(:id).map(&:id)).must_equal tasks_to_keep.map(&:id).sort
27
27
 
28
- ForemanTasks.dynflow.world.persistence
29
- .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size.must_equal 0
28
+ _(ForemanTasks.dynflow.world.persistence
29
+ .find_execution_plans(filters: { 'uuid' => tasks_to_delete.map(&:external_id) }).size).must_equal 0
30
30
 
31
- ForemanTasks.dynflow.world.persistence
32
- .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size.must_equal tasks_to_keep.size
31
+ _(ForemanTasks.dynflow.world.persistence
32
+ .find_execution_plans(filters: { 'uuid' => tasks_to_keep.map(&:external_id) }).size).must_equal tasks_to_keep.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
- ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
71
- ForemanTasks::Task.where(id: tasks_to_keep).must_equal tasks_to_keep
70
+ _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
71
+ _(ForemanTasks::Task.where(id: tasks_to_keep)).must_equal tasks_to_keep
72
72
 
73
- ForemanTasks::Lock.find_by(id: lock_to_delete.id).must_be_nil
74
- ForemanTasks::Lock.find_by(id: lock_to_keep.id).wont_be_nil
73
+ _(ForemanTasks::Lock.find_by(id: lock_to_delete.id)).must_be_nil
74
+ _(ForemanTasks::Lock.find_by(id: lock_to_keep.id)).wont_be_nil
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
- ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
89
- ForemanTasks::Task.where(id: tasks_to_keep).must_equal tasks_to_keep
88
+ _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
89
+ _(ForemanTasks::Task.where(id: tasks_to_keep)).must_equal 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
- ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
104
- ForemanTasks::Task.where(id: task_to_keep).must_equal [task_to_keep]
103
+ _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
104
+ _(ForemanTasks::Task.where(id: task_to_keep)).must_equal [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
- header.must_equal ForemanTasks::Task.attribute_names.join(',')
120
+ _(header).must_equal ForemanTasks::Task.attribute_names.join(',')
121
121
  expected_lines = tasks_to_delete.map { |task| task.attributes.values.to_csv.chomp }
122
- data.count.must_equal expected_lines.count
123
- expected_lines.each { |line| data.must_include line }
124
- ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
122
+ _(data.count).must_equal expected_lines.count
123
+ expected_lines.each { |line| _(data).must_include line }
124
+ _(ForemanTasks::Task.where(id: tasks_to_delete)).must_be_empty
125
125
  end
126
126
 
127
127
  class ActionWithCleanup < Actions::Base
@@ -133,13 +133,13 @@ class TasksTest < ActiveSupport::TestCase
133
133
  describe 'default behaviour' do
134
134
  it 'searches for the actions that have the cleanup_after defined' do
135
135
  ForemanTasks::Cleaner.stubs(:cleanup_settings => {})
136
- ForemanTasks::Cleaner.actions_with_default_cleanup[ActionWithCleanup].must_equal '15d'
136
+ _(ForemanTasks::Cleaner.actions_with_default_cleanup[ActionWithCleanup]).must_equal '15d'
137
137
  end
138
138
 
139
139
  it 'searches for the actions that have the cleanup_after defined' do
140
140
  ForemanTasks::Cleaner.stubs(:cleanup_settings =>
141
141
  { :actions => [{ :name => ActionWithCleanup.name, :after => '5d' }] })
142
- ForemanTasks::Cleaner.actions_with_default_cleanup[ActionWithCleanup].must_equal '5d'
142
+ _(ForemanTasks::Cleaner.actions_with_default_cleanup[ActionWithCleanup]).must_equal '5d'
143
143
  end
144
144
 
145
145
  it 'deprecates the usage of :after' do
@@ -159,10 +159,10 @@ class TasksTest < ActiveSupport::TestCase
159
159
  :override_actions => true, :states => 'all' }]
160
160
  ForemanTasks::Cleaner.stubs(:cleanup_settings).returns(:rules => rules)
161
161
  r1, r2 = ForemanTasks::Cleaner.actions_by_rules actions_with_default
162
- r1[:filter].must_equal '(label !^ (action1, action2)) AND (label = something)'
163
- r1[:states].must_equal %w[stopped paused]
164
- r2[:filter].must_equal '(label = something_else)'
165
- r2[:states].must_equal []
162
+ _(r1[:filter]).must_equal '(label !^ (action1, action2)) AND (label = something)'
163
+ _(r1[:states]).must_equal %w[stopped paused]
164
+ _(r2[:filter]).must_equal '(label = something_else)'
165
+ _(r2[:states]).must_equal []
166
166
  end
167
167
  end
168
168
  end