foreman-tasks 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/js_tests.yml +27 -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 +31 -58
- data/app/controllers/foreman_tasks/concerns/parameters/triggering.rb +1 -1
- data/app/controllers/foreman_tasks/recurring_logics_controller.rb +7 -0
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +3 -3
- data/app/models/foreman_tasks/recurring_logic.rb +4 -4
- data/app/models/foreman_tasks/task.rb +11 -0
- data/app/models/foreman_tasks/task/dynflow_task.rb +27 -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 +1 -1
- data/app/views/foreman_tasks/api/tasks/index.json.rabl +2 -0
- data/app/views/foreman_tasks/recurring_logics/index.html.erb +3 -1
- data/config/routes.rb +2 -1
- data/db/migrate/20200517215015_rename_bookmarks_controller.rb +2 -2
- data/db/seeds.d/30-notification_blueprints.rb +7 -7
- data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
- 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 -2
- data/lib/foreman_tasks/version.rb +1 -1
- data/package.json +0 -1
- data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +7 -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 -38
- 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/TaskDetails/Components/RunningSteps.js +3 -3
- data/webpack/ForemanTasks/Components/TaskDetails/Components/Task.js +8 -157
- 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 +1 -1
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/Task.test.js +12 -70
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/TaskButtons.test.js +95 -0
- data/webpack/ForemanTasks/Components/TaskDetails/Components/__tests__/__snapshots__/Task.test.js.snap +78 -225
- 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 +87 -70
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsActions.js +48 -125
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsConstants.js +3 -16
- data/webpack/ForemanTasks/Components/TaskDetails/TaskDetailsSelectors.js +55 -29
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.fixtures.js +2 -2
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetails.test.js +6 -0
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/TaskDetailsActions.test.js +2 -18
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetails.test.js.snap +77 -27
- data/webpack/ForemanTasks/Components/TaskDetails/__tests__/__snapshots__/TaskDetailsActions.test.js.snap +14 -101
- data/webpack/ForemanTasks/Components/TaskDetails/index.js +6 -3
- 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 +17 -14
- data/.travis.yml +0 -7
- 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 -72
- data/webpack/__mocks__/foremanReact/redux/API.js +0 -7
|
@@ -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
|
|
@@ -148,12 +148,6 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
|
148
148
|
assert ForemanTasks.dynflow.world.persistence.load_delayed_plan(task.execution_plan.id).frozen
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
it 'handles if the task has been deleted' do
|
|
152
|
-
logic.tasks.find_by(:state => 'scheduled').destroy
|
|
153
|
-
logic.update!(:enabled => false)
|
|
154
|
-
assert_equal 'disabled', logic.state
|
|
155
|
-
end
|
|
156
|
-
|
|
157
151
|
it 'properly re-enables on disable' do
|
|
158
152
|
logic.update!(:enabled => false)
|
|
159
153
|
logic.update!(:enabled => true)
|
|
@@ -170,24 +164,24 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
|
170
164
|
let(:logic) { FactoryBot.build(:recurring_logic) }
|
|
171
165
|
|
|
172
166
|
it 'is valid by default' do
|
|
173
|
-
logic.must_be :valid?
|
|
167
|
+
_(logic).must_be :valid?
|
|
174
168
|
end
|
|
175
169
|
|
|
176
170
|
it 'is invalid when end time in past' do
|
|
177
171
|
logic.end_time = (Time.zone.now - 120)
|
|
178
|
-
logic.wont_be :valid?
|
|
172
|
+
_(logic).wont_be :valid?
|
|
179
173
|
end
|
|
180
174
|
|
|
181
175
|
it 'is invalid when iteration limit < 1' do
|
|
182
176
|
logic.max_iteration = 0
|
|
183
|
-
logic.wont_be :valid?
|
|
177
|
+
_(logic).wont_be :valid?
|
|
184
178
|
end
|
|
185
179
|
|
|
186
180
|
it 'is valid when in active state' do
|
|
187
181
|
logic.end_time = (Time.zone.now - 120)
|
|
188
|
-
logic.wont_be :valid?
|
|
182
|
+
_(logic).wont_be :valid?
|
|
189
183
|
logic.state = 'active'
|
|
190
|
-
logic.must_be :valid?
|
|
184
|
+
_(logic).must_be :valid?
|
|
191
185
|
end
|
|
192
186
|
end
|
|
193
187
|
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
|
-
remote_task.state.must_equal 'triggered'
|
|
28
|
-
remote_task.remote_task_id.must_equal((remote_task.id + 5).to_s)
|
|
27
|
+
_(remote_task.state).must_equal 'triggered'
|
|
28
|
+
_(remote_task.remote_task_id).must_equal((remote_task.id + 5).to_s)
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -55,18 +55,18 @@ module ForemanTasks
|
|
|
55
55
|
|
|
56
56
|
it 'has the task group assigned' do
|
|
57
57
|
task = spawn_task.call ChildAction
|
|
58
|
-
task.task_groups.map(&:id).must_equal [1]
|
|
58
|
+
_(task.task_groups.map(&:id)).must_equal [1]
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
it 'tasks inherit task groups correctly' do
|
|
62
62
|
children_count = 3
|
|
63
63
|
task = spawn_task.call ParentAction, children_count
|
|
64
64
|
# Parent task has task groups of its children
|
|
65
|
-
task.task_groups.map(&:id).sort.must_equal [1, 2, 3, 4]
|
|
65
|
+
_(task.task_groups.map(&:id).sort).must_equal [1, 2, 3, 4]
|
|
66
66
|
# Children have the parent's and their own, they don't have their siblings' task groups
|
|
67
|
-
task.sub_tasks.count.must_equal children_count
|
|
67
|
+
_(task.sub_tasks.count).must_equal children_count
|
|
68
68
|
task.sub_tasks.each do |sub_task|
|
|
69
|
-
sub_task.task_groups.map(&:id).sort.must_equal [1, sub_task.input[:id]].sort
|
|
69
|
+
_(sub_task.task_groups.map(&:id).sort).must_equal [1, sub_task.input[:id]].sort
|
|
70
70
|
end
|
|
71
71
|
end
|
|
72
72
|
end
|
data/test/unit/task_test.rb
CHANGED
|
@@ -32,8 +32,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
32
32
|
end
|
|
33
33
|
|
|
34
34
|
test 'cannot search by arbitrary key' do
|
|
35
|
-
proc { ForemanTasks::Task.search_for('user.my_key ~ 5') }.must_raise(ScopedSearch::QueryNotSupported)
|
|
36
|
-
proc { ForemanTasks::Task.search_for('user. = 5') }.must_raise(ScopedSearch::QueryNotSupported)
|
|
35
|
+
_ { proc { ForemanTasks::Task.search_for('user.my_key ~ 5') } }.must_raise(ScopedSearch::QueryNotSupported)
|
|
36
|
+
_ { proc { ForemanTasks::Task.search_for('user. = 5') } }.must_raise(ScopedSearch::QueryNotSupported)
|
|
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
|
-
proc { ForemanTasks::Task.search_for("user.id ~ something") }.must_raise(ScopedSearch::QueryNotSupported)
|
|
63
|
-
proc { ForemanTasks::Task.search_for("user.id ~ 5") }.must_raise(ScopedSearch::QueryNotSupported)
|
|
62
|
+
_ { proc { ForemanTasks::Task.search_for("user.id ~ something") } }.must_raise(ScopedSearch::QueryNotSupported)
|
|
63
|
+
_ { proc { ForemanTasks::Task.search_for("user.id ~ 5") } }.must_raise(ScopedSearch::QueryNotSupported)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
test 'can search the tasks by user with wildcards' do
|
|
@@ -126,7 +126,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
126
126
|
end
|
|
127
127
|
|
|
128
128
|
it 'raises an exception if duration is unknown' do
|
|
129
|
-
proc { ForemanTasks::Task.search_for('duration = "25 potatoes"') }.must_raise ScopedSearch::QueryNotSupported
|
|
129
|
+
_ { proc { ForemanTasks::Task.search_for('duration = "25 potatoes"') } }.must_raise ScopedSearch::QueryNotSupported
|
|
130
130
|
end
|
|
131
131
|
end
|
|
132
132
|
end
|
|
@@ -176,13 +176,13 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
176
176
|
let(:inconsistent_task) { FactoryBot.create(:dynflow_task, :inconsistent_dynflow_task) }
|
|
177
177
|
|
|
178
178
|
it 'ensures the tasks marked as running are really running in Dynflow' do
|
|
179
|
-
consistent_task.state.must_equal 'planned'
|
|
180
|
-
inconsistent_task.state.must_equal 'running'
|
|
179
|
+
_(consistent_task.state).must_equal 'planned'
|
|
180
|
+
_(inconsistent_task.state).must_equal 'running'
|
|
181
181
|
|
|
182
182
|
ForemanTasks::Task::DynflowTask.consistency_check
|
|
183
183
|
|
|
184
|
-
consistent_task.reload.state.must_equal 'planned'
|
|
185
|
-
inconsistent_task.reload.state.must_equal 'planned'
|
|
184
|
+
_(consistent_task.reload.state).must_equal 'planned'
|
|
185
|
+
_(inconsistent_task.reload.state).must_equal 'planned'
|
|
186
186
|
end
|
|
187
187
|
end
|
|
188
188
|
|
|
@@ -190,8 +190,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
190
190
|
it 'when scheduled to the future, the label and action is set properly' do
|
|
191
191
|
job = Support::DummyActiveJob.set(:wait => 12.hours).perform_later
|
|
192
192
|
task = ForemanTasks::Task.find_by!(:external_id => job.provider_job_id)
|
|
193
|
-
task.action.must_equal "Dummy action"
|
|
194
|
-
task.label.must_equal "Support::DummyActiveJob"
|
|
193
|
+
_(task.action).must_equal "Dummy action"
|
|
194
|
+
_(task.label).must_equal "Support::DummyActiveJob"
|
|
195
195
|
end
|
|
196
196
|
end
|
|
197
197
|
|
|
@@ -224,14 +224,14 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
224
224
|
:total => 0,
|
|
225
225
|
:success => 0,
|
|
226
226
|
:cancelled => 0,
|
|
227
|
-
:pending => 0
|
|
227
|
+
:pending => 0,
|
|
228
228
|
}
|
|
229
229
|
end
|
|
230
230
|
let(:task) { FactoryBot.create(:dynflow_task) }
|
|
231
231
|
|
|
232
232
|
describe 'without sub tasks' do
|
|
233
233
|
it 'calculates the progress report correctly' do
|
|
234
|
-
task.sub_tasks_counts.must_equal result_base
|
|
234
|
+
_(task.sub_tasks_counts).must_equal result_base
|
|
235
235
|
end
|
|
236
236
|
end
|
|
237
237
|
|
|
@@ -242,7 +242,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
242
242
|
|
|
243
243
|
it 'calculate the progress report correctly' do
|
|
244
244
|
expected_result = result_base.merge(:success => 1, :error => 1, :total => 2)
|
|
245
|
-
task.sub_tasks_counts.must_equal expected_result
|
|
245
|
+
_(task.sub_tasks_counts).must_equal expected_result
|
|
246
246
|
end
|
|
247
247
|
|
|
248
248
|
it 'calculates the progress report correctly when using batch planning' do
|
|
@@ -252,11 +252,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
252
252
|
|
|
253
253
|
task.state = 'stopped'
|
|
254
254
|
expected_result = result_base.merge(:cancelled => 23)
|
|
255
|
-
task.sub_tasks_counts.must_equal expected_result
|
|
255
|
+
_(task.sub_tasks_counts).must_equal expected_result
|
|
256
256
|
|
|
257
257
|
task.state = 'pending'
|
|
258
258
|
expected_result = result_base.merge(:pending => 23)
|
|
259
|
-
task.sub_tasks_counts.must_equal expected_result
|
|
259
|
+
_(task.sub_tasks_counts).must_equal expected_result
|
|
260
260
|
end
|
|
261
261
|
end
|
|
262
262
|
end
|
|
@@ -278,10 +278,10 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
278
278
|
|
|
279
279
|
it 'can indicate it is delayed' do
|
|
280
280
|
assert_not task.delayed?
|
|
281
|
-
task.execution_type.must_equal 'Immediate'
|
|
281
|
+
_(task.execution_type).must_equal 'Immediate'
|
|
282
282
|
task.start_at = Time.now.utc + 100
|
|
283
283
|
assert task.delayed?
|
|
284
|
-
task.execution_type.must_equal 'Delayed'
|
|
284
|
+
_(task.execution_type).must_equal 'Delayed'
|
|
285
285
|
end
|
|
286
286
|
end
|
|
287
287
|
|
|
@@ -3,28 +3,28 @@ require 'foreman_tasks_test_helper'
|
|
|
3
3
|
class TriggeringTest < ActiveSupport::TestCase
|
|
4
4
|
describe 'validation' do
|
|
5
5
|
it 'is valid when immediate' do
|
|
6
|
-
FactoryBot.build(:triggering).must_be :valid?
|
|
6
|
+
_(FactoryBot.build(:triggering)).must_be :valid?
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'is validates future execution' do
|
|
10
10
|
triggering = FactoryBot.build(:triggering, :future)
|
|
11
|
-
triggering.must_be :valid?
|
|
11
|
+
_(triggering).must_be :valid?
|
|
12
12
|
triggering.start_before = triggering.start_at - 120
|
|
13
|
-
triggering.wont_be :valid?
|
|
13
|
+
_(triggering).wont_be :valid?
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it 'is invalid when recurring logic is invalid' do
|
|
17
17
|
triggering = FactoryBot.build(:triggering, :recurring)
|
|
18
|
-
triggering.must_be :valid?
|
|
18
|
+
_(triggering).must_be :valid?
|
|
19
19
|
triggering.recurring_logic.stubs(:valid?).returns(false)
|
|
20
|
-
triggering.wont_be :valid?
|
|
20
|
+
_(triggering).wont_be :valid?
|
|
21
21
|
end
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'cannot have mode set to arbitrary value' do
|
|
25
25
|
triggering = FactoryBot.build(:triggering)
|
|
26
|
-
triggering.must_be :valid?
|
|
27
|
-
proc { triggering.mode = 'bogus' }.must_raise ArgumentError
|
|
28
|
-
proc { triggering.mode = 27 }.must_raise ArgumentError
|
|
26
|
+
_(triggering).must_be :valid?
|
|
27
|
+
_ { proc { triggering.mode = 'bogus' } }.must_raise ArgumentError
|
|
28
|
+
_ { proc { triggering.mode = 27 } }.must_raise ArgumentError
|
|
29
29
|
end
|
|
30
30
|
end
|