foreman-tasks 2.0.0 → 3.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/js_tests.yml +31 -0
- data/.github/workflows/ruby_tests.yml +74 -0
- data/.rubocop.yml +12 -4
- data/.rubocop_todo.yml +32 -25
- data/Gemfile +5 -0
- data/app/controllers/foreman_tasks/api/tasks_controller.rb +36 -60
- data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +1 -1
- data/app/controllers/foreman_tasks/recurring_logics_controller.rb +7 -0
- data/app/controllers/foreman_tasks/tasks_controller.rb +6 -3
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +3 -3
- data/app/lib/actions/proxy_action.rb +1 -1
- data/app/models/foreman_tasks/recurring_logic.rb +1 -1
- data/app/models/foreman_tasks/task.rb +11 -0
- data/app/models/foreman_tasks/task/dynflow_task.rb +29 -33
- data/app/models/foreman_tasks/task/status_explicator.rb +1 -1
- data/app/models/foreman_tasks/triggering.rb +1 -1
- data/app/models/setting/foreman_tasks.rb +9 -9
- data/app/services/foreman_tasks/dashboard_table_filter.rb +5 -1
- data/app/views/foreman_tasks/api/tasks/index.json.rabl +2 -0
- data/app/views/foreman_tasks/api/tasks/show.json.rabl +2 -0
- data/app/views/foreman_tasks/layouts/react.html.erb +1 -2
- data/app/views/foreman_tasks/recurring_logics/index.html.erb +3 -1
- data/app/views/foreman_tasks/tasks/show.html.erb +1 -6
- data/config/routes.rb +2 -1
- data/db/migrate/20200517215015_rename_bookmarks_controller.rb +2 -2
- data/db/migrate/20200611090846_add_task_lock_index_on_resource_type_and_task_id.rb +9 -0
- data/db/seeds.d/30-notification_blueprints.rb +7 -7
- data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
- data/foreman-tasks.gemspec +1 -0
- data/lib/foreman_tasks/cleaner.rb +4 -6
- data/lib/foreman_tasks/dynflow/configuration.rb +1 -1
- data/lib/foreman_tasks/dynflow/persistence.rb +4 -6
- data/lib/foreman_tasks/engine.rb +2 -7
- data/lib/foreman_tasks/tasks/cleanup.rake +2 -2
- data/lib/foreman_tasks/tasks/dynflow.rake +6 -0
- data/lib/foreman_tasks/tasks/export_tasks.rake +1 -1
- data/lib/foreman_tasks/version.rb +1 -1
- data/locale/en/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/en/foreman_tasks.po +50 -20
- data/locale/foreman_tasks.pot +173 -126
- data/locale/fr/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/fr/foreman_tasks.po +817 -0
- data/locale/ja/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/ja/foreman_tasks.po +817 -0
- data/locale/zh_CN/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/zh_CN/foreman_tasks.po +816 -0
- data/package.json +1 -1
- data/script/npm_link_foreman_js.sh +26 -0
- data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +17 -7
- data/test/controllers/tasks_controller_test.rb +6 -6
- data/test/core/unit/runner_test.rb +20 -20
- data/test/core/unit/task_launcher_test.rb +8 -8
- 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/support/history_tasks_builder.rb +1 -1
- data/test/tasks/generate_task_actions_test.rb +1 -1
- data/test/unit/actions/action_with_sub_plans_test.rb +2 -2
- data/test/unit/actions/bulk_action_test.rb +6 -6
- data/test/unit/actions/proxy_action_test.rb +20 -20
- data/test/unit/actions/recurring_action_test.rb +30 -32
- data/test/unit/cleaner_test.rb +24 -24
- data/test/unit/dashboard_table_filter_test.rb +5 -5
- data/test/unit/otp_manager_test.rb +2 -2
- data/test/unit/proxy_selector_test.rb +9 -9
- data/test/unit/recurring_logic_test.rb +32 -32
- data/test/unit/remote_task_test.rb +2 -2
- data/test/unit/task_groups_test.rb +4 -4
- data/test/unit/task_test.rb +18 -18
- data/test/unit/triggering_test.rb +8 -8
- data/test/unit/troubleshooting_help_generator_test.rb +6 -6
- data/test/unit/ui_notifications_test.rb +11 -11
- data/webpack/ForemanTasks/Components/TaskActions/TaskAction.test.js +2 -2
- data/webpack/ForemanTasks/Components/TaskActions/index.js +1 -1
- data/webpack/ForemanTasks/Components/TaskDetails/Components/RunningSteps.js +17 -3
- data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +8 -153
- data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskButtons.js +168 -0
- data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskInfo.js +6 -7
- data/webpack/ForemanTasks/Components/TaskDetails/Components/TaskSkeleton.js +48 -0
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/RunningSteps.test.js +8 -1
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +13 -70
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskButtons.test.js +95 -0
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/RunningSteps.test.js.snap +1 -1
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +78 -208
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskButtons.test.js.snap +212 -0
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/TaskInfo.test.js.snap +8 -4
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.js +100 -53
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetails.scss +13 -14
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +57 -95
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -12
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +57 -28
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +8 -0
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +8 -1
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +6 -6
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +84 -12
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +25 -21
- data/webpack/ForemanTasks/Components/TaskDetails/index.js +8 -3
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/ScheduledTasksCard/ScheduledTasksCard.scss +4 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.js +53 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/OtherInfo.test.js +14 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.js +27 -19
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.scss +14 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCard.test.js +1 -34
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/{StoppedTasksCardHelper.js → StoppedTasksCardTable.js} +28 -1
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/StoppedTasksCardTable.test.js +54 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/OtherInfo.test.js.snap +48 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCard.test.js.snap +60 -1367
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/Components/StoppedTasksCard/__snapshots__/StoppedTasksCardTable.test.js.snap +960 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/Components/TasksCardsGrid/__snapshots__/TasksCardsGrid.test.js.snap +14 -11
- data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardActions.js +1 -1
- data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardConstants.js +2 -0
- data/webpack/ForemanTasks/Components/TasksDashboard/TasksDashboardSelectors.js +17 -11
- data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardActions.test.js +2 -2
- data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/TasksDashboardSelectors.test.js +26 -14
- data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboard.test.js.snap +14 -11
- data/webpack/ForemanTasks/Components/TasksDashboard/__tests__/__snapshots__/TasksDashboardSelectors.test.js.snap +38 -22
- data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/ConfirmModalSelectors.js +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/ConfirmModalSelectors.test.js +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/Components/ConfirmModal/__test__/__snapshots__/ConfirmModalSelectors.test.js.snap +2 -0
- data/webpack/ForemanTasks/Components/TasksTable/TasksBulkActions.js +25 -8
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableActions.js +3 -3
- data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.js +6 -3
- data/webpack/ForemanTasks/Components/TasksTable/TasksTablePage.scss +0 -10
- data/webpack/ForemanTasks/Components/TasksTable/TasksTableSelectors.js +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksBulkActions.test.js +15 -2
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTable.fixtures.js +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/TasksTablePage.test.js +2 -1
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/SubTasksPage.test.js.snap +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksBulkActions.test.js.snap +48 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksIndexPage.test.js.snap +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/__tests__/__snapshots__/TasksTablePage.test.js.snap +39 -7
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/actionCellFormatter.test.js.snap +1 -0
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/__snapshots__/selectionCellFormatter.test.js.snap +2 -0
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/actionCellFormatter.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/formatters/__test__/selectionCellFormatter.test.js +1 -1
- data/webpack/ForemanTasks/Components/TasksTable/formatters/actionCellFormatter.js +10 -7
- data/webpack/ForemanTasks/Components/TasksTable/formatters/selectionCellFormatter.js +7 -0
- data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.js +39 -31
- data/webpack/ForemanTasks/Components/common/ActionButtons/ActionButton.test.js +17 -8
- data/webpack/ForemanTasks/Components/common/ActionButtons/__snapshots__/ActionButton.test.js.snap +8 -0
- data/webpack/ForemanTasks/Components/common/urlHelpers.js +7 -0
- data/webpack/ForemanTasks/ForemanTasksReducers.js +0 -2
- data/webpack/__mocks__/foremanReact/common/helpers.js +2 -0
- data/webpack/__mocks__/foremanReact/redux/API/APISelectors.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/API/index.js +10 -0
- data/webpack/__mocks__/foremanReact/redux/middlewares/IntervalMiddleware.js +5 -0
- metadata +35 -17
- data/.travis.yml +0 -5
- data/app/assets/stylesheets/foreman_tasks/tasks.scss +0 -9
- data/script/travis_run_js_tests.sh +0 -7
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsReducer.js +0 -38
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsReducer.test.js +0 -33
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsReducer.test.js.snap +0 -26
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/integration.test.js.snap +0 -122
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/integration.test.js +0 -67
- data/webpack/__mocks__/foremanReact/API.js +0 -7
@@ -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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
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
|
-
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
|
@@ -24,7 +24,7 @@ class DashboardTableFilterTest < ActiveSupport::TestCase
|
|
24
24
|
let(:params) { { result: 'warning' } }
|
25
25
|
|
26
26
|
it 'filters' do
|
27
|
-
filtered_scope.count.must_equal @tasks_builder.distribution['stopped'][:by_result]['warning'][:total]
|
27
|
+
_(filtered_scope.count).must_equal @tasks_builder.distribution['stopped'][:by_result]['warning'][:total]
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,7 +32,7 @@ class DashboardTableFilterTest < ActiveSupport::TestCase
|
|
32
32
|
let(:params) { { state: 'running' } }
|
33
33
|
|
34
34
|
it 'filters' do
|
35
|
-
filtered_scope.count.must_equal @tasks_builder.distribution['running'][:total]
|
35
|
+
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:total]
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -44,7 +44,7 @@ class DashboardTableFilterTest < ActiveSupport::TestCase
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it 'filters' do
|
47
|
-
filtered_scope.count.must_equal @tasks_builder.distribution['running'][:recent]
|
47
|
+
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:recent]
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -56,7 +56,7 @@ class DashboardTableFilterTest < ActiveSupport::TestCase
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'filters' do
|
59
|
-
filtered_scope.count.must_equal @tasks_builder.distribution['running'][:recent]
|
59
|
+
_(filtered_scope.count).must_equal @tasks_builder.distribution['running'][:recent]
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
@@ -70,7 +70,7 @@ class DashboardTableFilterTest < ActiveSupport::TestCase
|
|
70
70
|
it 'filters' do
|
71
71
|
old_tasks_count = @tasks_builder.distribution['running'][:total] -
|
72
72
|
@tasks_builder.distribution['running'][:recent]
|
73
|
-
filtered_scope.count.must_equal old_tasks_count
|
73
|
+
_(filtered_scope.count).must_equal old_tasks_count
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -28,7 +28,7 @@ module ForemanTasksCore
|
|
28
28
|
it 'generates OTPs using SecureRandom.hex and converts them to strings' do
|
29
29
|
otp = 4
|
30
30
|
SecureRandom.stubs(:hex).returns(otp)
|
31
|
-
TestOtpManager.generate_otp(username).must_equal otp.to_s
|
31
|
+
_(TestOtpManager.generate_otp(username)).must_equal otp.to_s
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'provides #drop_otp method that removes OTP only when correct username and password is provided' do
|
@@ -64,7 +64,7 @@ module ForemanTasksCore
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'creates token from username and password correctly' do
|
67
|
-
TestOtpManager.tokenize(username, password).must_equal base64
|
67
|
+
_(TestOtpManager.tokenize(username, password)).must_equal base64
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'overwrites old OTP when generating a new one for the same username' do
|
@@ -18,22 +18,22 @@ describe ForemanTasks::ProxySelector do
|
|
18
18
|
found << proxy_selector.select_by_jobs_count(proxies)
|
19
19
|
end
|
20
20
|
|
21
|
-
available.count.must_equal count
|
22
|
-
available.uniq.count.must_equal count - 1
|
23
|
-
proxy_selector.offline.count.must_equal 1
|
21
|
+
_(available.count).must_equal count
|
22
|
+
_(available.uniq.count).must_equal count - 1
|
23
|
+
_(proxy_selector.offline.count).must_equal 1
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'returns nil for if no proxy is available' do
|
27
|
-
proxy_selector.select_by_jobs_count([]).must_be_nil
|
27
|
+
_(proxy_selector.select_by_jobs_count([])).must_be_nil
|
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
|
-
proxy_selector.determine_proxy.must_equal :not_defined
|
34
|
+
_(proxy_selector.determine_proxy).must_equal :not_defined
|
35
35
|
proxy_selector.stubs(:available_proxies => { :global => [] })
|
36
|
-
proxy_selector.determine_proxy.must_equal :not_defined
|
36
|
+
_(proxy_selector.determine_proxy).must_equal :not_defined
|
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
|
-
proxy_selector.determine_proxy.must_equal :not_available
|
44
|
+
_(proxy_selector.determine_proxy).must_equal :not_available
|
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
|
-
ForemanTasks::ProxySelector.new.determine_proxy.must_equal fallback_proxy
|
54
|
+
_(ForemanTasks::ProxySelector.new.determine_proxy).must_equal fallback_proxy
|
55
55
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).raises.then.returns(0)
|
56
|
-
ForemanTasks::ProxySelector.new.determine_proxy.must_equal global_proxy
|
56
|
+
_(ForemanTasks::ProxySelector.new.determine_proxy).must_equal global_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
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* * * * *'
|
7
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* * * * *'
|
8
8
|
hash.update :minutes => '*'
|
9
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* * * * *'
|
9
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* * * * *'
|
10
10
|
hash.update :hours => '0,12'
|
11
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 * * *'
|
11
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 * * *'
|
12
12
|
hash.update :days => '*/2'
|
13
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 * *'
|
13
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 * *'
|
14
14
|
hash.update :months => '12'
|
15
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 12 *'
|
15
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 12 *'
|
16
16
|
hash.update :days_of_week => '1,2,3,4,5,6,7'
|
17
|
-
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 12 1,2,3,4,5,6,7'
|
17
|
+
_(ForemanTasks::RecurringLogic.assemble_cronline(hash)).must_equal '* 0,12 */2 12 1,2,3,4,5,6,7'
|
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
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, month, day, hour, minute)
|
28
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, hour, minute)
|
29
29
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 * * * *')
|
30
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, month, day, hour, minute)
|
30
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, hour, minute)
|
31
31
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 * * *')
|
32
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, month, day, 18)
|
32
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month, day, 18)
|
33
33
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 * *')
|
34
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, month + 1, 10, 18, minute)
|
34
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month + 1, 10, 18, minute)
|
35
35
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 11,12 *')
|
36
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, 11, 10, 18, 0)
|
36
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, 11, 10, 18, 0)
|
37
37
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * 1')
|
38
|
-
parser.next_occurrence_time(reference_time).must_equal Time.utc(year, month + 1, 5)
|
38
|
+
_(parser.next_occurrence_time(reference_time)).must_equal Time.utc(year, month + 1, 5)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'creates correct cronline hash' do
|
@@ -48,27 +48,27 @@ 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
|
-
ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week).must_equal expected_result_hourly
|
52
|
-
ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week).must_equal expected_result_daily
|
53
|
-
ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week).must_equal expected_result_weekly
|
54
|
-
ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week).must_equal expected_result_monthly
|
51
|
+
_(ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days, days_of_week)).must_equal expected_result_hourly
|
52
|
+
_(ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days, days_of_week)).must_equal expected_result_daily
|
53
|
+
_(ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days, days_of_week)).must_equal expected_result_weekly
|
54
|
+
_(ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days, days_of_week)).must_equal expected_result_monthly
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'can have limited number of repeats' do
|
58
58
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
59
59
|
parser.state = 'active'
|
60
|
-
parser.must_be :can_continue?
|
60
|
+
_(parser).must_be :can_continue?
|
61
61
|
parser.max_iteration = 5
|
62
62
|
parser.expects(:iteration).twice.returns(5)
|
63
|
-
parser.wont_be :can_continue?
|
63
|
+
_(parser).wont_be :can_continue?
|
64
64
|
parser.max_iteration = nil
|
65
65
|
time = Time.utc(2015, 9, 29, 15, 0)
|
66
66
|
parser.end_time = time
|
67
|
-
parser.wont_be :can_continue?, time
|
67
|
+
_(parser).wont_be :can_continue?, time
|
68
68
|
parser.end_time = time + 120
|
69
|
-
parser.must_be :can_continue?, time
|
69
|
+
_(parser).must_be :can_continue?, time
|
70
70
|
parser.max_iteration = 5
|
71
|
-
parser.wont_be :can_continue?, time
|
71
|
+
_(parser).wont_be :can_continue?, time
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'generates delay options' do
|
@@ -76,9 +76,9 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
76
76
|
parser.stubs(:id).returns(1)
|
77
77
|
reference_time = Time.utc(2015, 9, 29, 15)
|
78
78
|
expected_hash = { :start_at => reference_time, :start_before => nil, :recurring_logic_id => parser.id, :frozen => false }
|
79
|
-
parser.generate_delay_options(reference_time).must_equal expected_hash
|
80
|
-
parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600)
|
81
|
-
|
79
|
+
_(parser.generate_delay_options(reference_time)).must_equal expected_hash
|
80
|
+
_(parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600))
|
81
|
+
.must_equal expected_hash.merge(:start_before => reference_time + 3600)
|
82
82
|
end
|
83
83
|
|
84
84
|
it 'can start' do
|
@@ -108,19 +108,19 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
108
108
|
it 'has a task group associated to all tasks that were created as part of the recurring logic' do
|
109
109
|
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
110
110
|
recurring_logic.save
|
111
|
-
recurring_logic.task_group.must_be_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup
|
111
|
+
_(recurring_logic.task_group).must_be_kind_of ForemanTasks::TaskGroups::RecurringLogicTaskGroup
|
112
112
|
task = FactoryBot.build(:dynflow_task, :user_create_task)
|
113
113
|
task.task_groups << Support::DummyTaskGroup.new
|
114
114
|
task.save!
|
115
115
|
recurring_logic.task_group.tasks << task
|
116
|
-
recurring_logic.task_groups.must_include(*task.task_groups)
|
116
|
+
_(recurring_logic.task_groups).must_include(*task.task_groups)
|
117
117
|
end
|
118
118
|
|
119
119
|
it 'can be created from triggering' do
|
120
120
|
triggering = FactoryBot.build(:triggering, :recurring, :end_time_limited)
|
121
121
|
logic = ForemanTasks::RecurringLogic.new_from_triggering(triggering)
|
122
122
|
# Mysql coerces the times a bit
|
123
|
-
logic.end_time.must_be_close_to(triggering.end_time, 1.second)
|
123
|
+
_(logic.end_time).must_be_close_to(triggering.end_time, 1.second)
|
124
124
|
end
|
125
125
|
|
126
126
|
it 'cannot trigger tasks when cancelled' do
|
@@ -164,24 +164,24 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
164
164
|
let(:logic) { FactoryBot.build(:recurring_logic) }
|
165
165
|
|
166
166
|
it 'is valid by default' do
|
167
|
-
logic.must_be :valid?
|
167
|
+
_(logic).must_be :valid?
|
168
168
|
end
|
169
169
|
|
170
170
|
it 'is invalid when end time in past' do
|
171
171
|
logic.end_time = (Time.zone.now - 120)
|
172
|
-
logic.wont_be :valid?
|
172
|
+
_(logic).wont_be :valid?
|
173
173
|
end
|
174
174
|
|
175
175
|
it 'is invalid when iteration limit < 1' do
|
176
176
|
logic.max_iteration = 0
|
177
|
-
logic.wont_be :valid?
|
177
|
+
_(logic).wont_be :valid?
|
178
178
|
end
|
179
179
|
|
180
180
|
it 'is valid when in active state' do
|
181
181
|
logic.end_time = (Time.zone.now - 120)
|
182
|
-
logic.wont_be :valid?
|
182
|
+
_(logic).wont_be :valid?
|
183
183
|
logic.state = 'active'
|
184
|
-
logic.must_be :valid?
|
184
|
+
_(logic).must_be :valid?
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|