foreman-tasks 0.7.6 → 0.7.7
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 +5 -13
- data/app/assets/javascripts/trigger_form.js +41 -0
- data/app/controllers/foreman_tasks/recurring_logics_controller.rb +33 -0
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +144 -0
- data/app/helpers/foreman_tasks/tasks_helper.rb +8 -0
- data/app/lib/actions/base.rb +4 -0
- data/app/lib/actions/entry_action.rb +5 -1
- data/app/lib/actions/foreman/host/import_facts.rb +4 -0
- data/app/lib/actions/middleware/inherit_task_groups.rb +39 -0
- data/app/lib/actions/middleware/recurring_logic.rb +42 -0
- data/app/models/foreman_tasks/recurring_logic.rb +136 -0
- data/app/models/foreman_tasks/task.rb +10 -0
- data/app/models/foreman_tasks/task_group.rb +16 -0
- data/app/models/foreman_tasks/task_group_member.rb +8 -0
- data/app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb +16 -0
- data/app/models/foreman_tasks/triggering.rb +99 -0
- data/app/views/common/_trigger_form.html.erb +14 -0
- data/app/views/foreman_tasks/recurring_logics/_tab_related.html.erb +3 -0
- data/app/views/foreman_tasks/recurring_logics/index.html.erb +34 -0
- data/app/views/foreman_tasks/recurring_logics/show.html.erb +12 -0
- data/app/views/foreman_tasks/task_groups/_common.html.erb +12 -0
- data/app/views/foreman_tasks/task_groups/_detail.html.erb +7 -0
- data/app/views/foreman_tasks/task_groups/_tab_related.html.erb +17 -0
- data/app/views/foreman_tasks/task_groups/recurring_logic_task_groups/_recurring_logic_task_group.html.erb +39 -0
- data/config/routes.rb +6 -0
- data/db/migrate/20150814204140_add_task_type_value_index.rb +5 -0
- data/db/migrate/20150907124936_create_recurring_logic.rb +11 -0
- data/db/migrate/20150907131503_create_task_groups.rb +19 -0
- data/db/migrate/20151022123457_add_recurring_logic_state.rb +9 -0
- data/db/migrate/20151112152108_create_triggerings.rb +18 -0
- data/lib/foreman_tasks/engine.rb +12 -0
- data/lib/foreman_tasks/tasks/export_tasks.rake +2 -2
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/unit/recurring_logic_test.rb +74 -0
- data/test/unit/task_groups_test.rb +76 -0
- metadata +61 -29
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'foreman_tasks_test_helper'
|
2
|
+
|
3
|
+
class RecurringLogicsTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
describe 'generating times' do
|
6
|
+
|
7
|
+
it 'assembles cronline' do
|
8
|
+
hash = { }
|
9
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* * * * *'
|
10
|
+
hash.update :minutes => '*'
|
11
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* * * * *'
|
12
|
+
hash.update :hours => '0,12'
|
13
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 * * *'
|
14
|
+
hash.update :days => '*/2'
|
15
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 * *'
|
16
|
+
hash.update :months => '12'
|
17
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 12 *'
|
18
|
+
hash.update :days_of_week => '1,2,3,4,5,6,7'
|
19
|
+
ForemanTasks::RecurringLogic.assemble_cronline(hash).must_equal '* 0,12 */2 12 1,2,3,4,5,6,7'
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'generates correct times' do
|
23
|
+
year, month, day, hour, minute = [2015, 9, 29, 15, 0]
|
24
|
+
reference_time = Time.new(year, month, day, hour, minute)
|
25
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
26
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month, day, hour, minute + 1)
|
27
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 * * * *')
|
28
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month, day, hour, minute + 2)
|
29
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 * * *')
|
30
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month, day, 18)
|
31
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 * *')
|
32
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month + 1, 10, 18, minute)
|
33
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('*/2 18,19 10 11,12 *')
|
34
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, 11, 10, 18, 0)
|
35
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * 1')
|
36
|
+
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month + 1, 5)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'can have limited number of repeats' do
|
40
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
41
|
+
parser.state = 'active'
|
42
|
+
parser.must_be :can_continue?
|
43
|
+
parser.max_iteration = 5
|
44
|
+
parser.expects(:iteration).twice.returns(5)
|
45
|
+
parser.wont_be :can_continue?
|
46
|
+
parser.max_iteration = nil
|
47
|
+
time = Time.new(2015, 9, 29, 15, 0)
|
48
|
+
parser.end_time = time
|
49
|
+
parser.wont_be :can_continue?, time
|
50
|
+
parser.end_time = time + 120
|
51
|
+
parser.must_be :can_continue?, time
|
52
|
+
parser.max_iteration = 5
|
53
|
+
parser.wont_be :can_continue?, time
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'generates delay options' do
|
57
|
+
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
58
|
+
parser.stubs(:id).returns(1)
|
59
|
+
reference_time = Time.new(2015, 9, 29, 15)
|
60
|
+
expected_hash = { :start_at => reference_time + 60, :start_before => nil, :recurring_logic_id => parser.id }
|
61
|
+
parser.generate_delay_options(reference_time).must_equal expected_hash
|
62
|
+
parser.generate_delay_options(reference_time, 'start_before' => reference_time + 3600)
|
63
|
+
.must_equal expected_hash.merge(:start_before => reference_time + 3600)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'can start' do
|
67
|
+
recurring_logic = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
68
|
+
::ForemanTasks.expects(:delay)
|
69
|
+
recurring_logic.expects(:save!).twice
|
70
|
+
recurring_logic.start(::Support::DummyDynflowAction)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "foreman_tasks_test_helper"
|
2
|
+
|
3
|
+
module ForemanTasks
|
4
|
+
class TaskGroupsTest < ActiveSupport::TestCase
|
5
|
+
self.use_transactional_fixtures = false
|
6
|
+
include ::Dynflow::Testing
|
7
|
+
|
8
|
+
before do
|
9
|
+
User.current = User.where(:login => 'apiadmin').first
|
10
|
+
end
|
11
|
+
|
12
|
+
after do
|
13
|
+
::ForemanTasks::TaskGroup.all.each(&:destroy)
|
14
|
+
::ForemanTasks::Task::DynflowTask.all.each(&:destroy)
|
15
|
+
end
|
16
|
+
|
17
|
+
class ParentAction < Actions::ActionWithSubPlans
|
18
|
+
|
19
|
+
middleware.use ::Actions::Middleware::InheritTaskGroups
|
20
|
+
|
21
|
+
def plan(count)
|
22
|
+
task_group = ::ForemanTasks::TaskGroups::RecurringLogicTaskGroup.new
|
23
|
+
task_group.id = 1
|
24
|
+
task_group.save!
|
25
|
+
task.add_missing_task_groups(task_group)
|
26
|
+
plan_self :count => count
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_sub_plans
|
30
|
+
input[:count].times.map { |i| trigger InheritingChildAction, i + 2 }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class ChildAction < Actions::EntryAction
|
35
|
+
def plan(number = 1)
|
36
|
+
task_group = ::ForemanTasks::TaskGroups::RecurringLogicTaskGroup.new
|
37
|
+
task_group.id = number
|
38
|
+
task_group.save!
|
39
|
+
task.add_missing_task_groups task_group
|
40
|
+
input[:id] = task_group.id
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class InheritingChildAction < ChildAction
|
45
|
+
middleware.use ::Actions::Middleware::InheritTaskGroups
|
46
|
+
end
|
47
|
+
|
48
|
+
describe ForemanTasks::TaskGroup do
|
49
|
+
let(:spawn_task) do
|
50
|
+
lambda do |action_class, *args|
|
51
|
+
triggered = ForemanTasks.trigger(action_class, *args)
|
52
|
+
raise triggered.error if triggered.respond_to?(:error)
|
53
|
+
triggered.finished.wait
|
54
|
+
ForemanTasks::Task.find_by_external_id(triggered.id)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'has the task group assigned' do
|
59
|
+
task = spawn_task.call ChildAction
|
60
|
+
task.task_groups.map(&:id).must_equal [1]
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'tasks inherit task groups correctly' do
|
64
|
+
children_count = 3
|
65
|
+
task = spawn_task.call ParentAction, children_count
|
66
|
+
# Parent task has task groups of its children
|
67
|
+
task.task_groups.map(&:id).must_equal [1, 2, 3, 4]
|
68
|
+
# Children have the parent's and their own, they don't have their siblings' task groups
|
69
|
+
task.sub_tasks.count.must_equal children_count
|
70
|
+
task.sub_tasks.each do |sub_task|
|
71
|
+
sub_task.task_groups.map(&:id).must_equal [1, sub_task.input[:id]]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
metadata
CHANGED
@@ -1,84 +1,90 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman-tasks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Nečas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynflow
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.8
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.8
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sequel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sinatra
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: daemons
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: parse-cron
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.1.4
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.1.4
|
83
|
+
description: |
|
84
|
+
The goal of this plugin is to unify the way of showing task statuses across the Foreman instance.
|
85
|
+
It defines Task model for keeping the information about the tasks and Lock for assigning the tasks
|
86
|
+
to resources. The locking allows dealing with preventing multiple colliding tasks to be run on the
|
87
|
+
same resource. It also optionally provides Dynflow infrastructure for using it for managing the tasks.
|
82
88
|
email:
|
83
89
|
- inecas@redhat.com
|
84
90
|
executables: []
|
@@ -87,10 +93,13 @@ extra_rdoc_files: []
|
|
87
93
|
files:
|
88
94
|
- LICENSE
|
89
95
|
- README.md
|
96
|
+
- app/assets/javascripts/trigger_form.js
|
90
97
|
- app/assets/stylesheets/foreman_tasks/application.css.scss
|
91
98
|
- app/controllers/foreman_tasks/api/tasks_controller.rb
|
92
99
|
- app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb
|
100
|
+
- app/controllers/foreman_tasks/recurring_logics_controller.rb
|
93
101
|
- app/controllers/foreman_tasks/tasks_controller.rb
|
102
|
+
- app/helpers/foreman_tasks/foreman_tasks_helper.rb
|
94
103
|
- app/helpers/foreman_tasks/tasks_helper.rb
|
95
104
|
- app/lib/actions/action_with_sub_plans.rb
|
96
105
|
- app/lib/actions/base.rb
|
@@ -103,7 +112,9 @@ files:
|
|
103
112
|
- app/lib/actions/helpers/args_serialization.rb
|
104
113
|
- app/lib/actions/helpers/humanizer.rb
|
105
114
|
- app/lib/actions/helpers/lock.rb
|
115
|
+
- app/lib/actions/middleware/inherit_task_groups.rb
|
106
116
|
- app/lib/actions/middleware/keep_current_user.rb
|
117
|
+
- app/lib/actions/middleware/recurring_logic.rb
|
107
118
|
- app/lib/actions/proxy_action.rb
|
108
119
|
- app/lib/actions/serializers/active_record_serializer.rb
|
109
120
|
- app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb
|
@@ -112,13 +123,26 @@ files:
|
|
112
123
|
- app/models/foreman_tasks/concerns/architecture_action_subject.rb
|
113
124
|
- app/models/foreman_tasks/concerns/host_action_subject.rb
|
114
125
|
- app/models/foreman_tasks/lock.rb
|
126
|
+
- app/models/foreman_tasks/recurring_logic.rb
|
115
127
|
- app/models/foreman_tasks/task.rb
|
116
128
|
- app/models/foreman_tasks/task/dynflow_task.rb
|
117
129
|
- app/models/foreman_tasks/task/status_explicator.rb
|
118
130
|
- app/models/foreman_tasks/task/summarizer.rb
|
119
131
|
- app/models/foreman_tasks/task/task_cancelled_exception.rb
|
132
|
+
- app/models/foreman_tasks/task_group.rb
|
133
|
+
- app/models/foreman_tasks/task_group_member.rb
|
134
|
+
- app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb
|
135
|
+
- app/models/foreman_tasks/triggering.rb
|
120
136
|
- app/models/setting/foreman_tasks.rb
|
137
|
+
- app/views/common/_trigger_form.html.erb
|
121
138
|
- app/views/foreman_tasks/api/tasks/show.json.rabl
|
139
|
+
- app/views/foreman_tasks/recurring_logics/_tab_related.html.erb
|
140
|
+
- app/views/foreman_tasks/recurring_logics/index.html.erb
|
141
|
+
- app/views/foreman_tasks/recurring_logics/show.html.erb
|
142
|
+
- app/views/foreman_tasks/task_groups/_common.html.erb
|
143
|
+
- app/views/foreman_tasks/task_groups/_detail.html.erb
|
144
|
+
- app/views/foreman_tasks/task_groups/_tab_related.html.erb
|
145
|
+
- app/views/foreman_tasks/task_groups/recurring_logic_task_groups/_recurring_logic_task_group.html.erb
|
122
146
|
- app/views/foreman_tasks/tasks/_details.html.erb
|
123
147
|
- app/views/foreman_tasks/tasks/_errors.html.erb
|
124
148
|
- app/views/foreman_tasks/tasks/_locks.html.erb
|
@@ -136,7 +160,12 @@ files:
|
|
136
160
|
- db/migrate/20131209122644_create_foreman_tasks_locks.rb
|
137
161
|
- db/migrate/20140324104010_remove_foreman_tasks_progress.rb
|
138
162
|
- db/migrate/20140813215942_add_parent_task_id.rb
|
163
|
+
- db/migrate/20150814204140_add_task_type_value_index.rb
|
139
164
|
- db/migrate/20150817102538_add_delay_attributes.rb
|
165
|
+
- db/migrate/20150907124936_create_recurring_logic.rb
|
166
|
+
- db/migrate/20150907131503_create_task_groups.rb
|
167
|
+
- db/migrate/20151022123457_add_recurring_logic_state.rb
|
168
|
+
- db/migrate/20151112152108_create_triggerings.rb
|
140
169
|
- db/seeds.d/20-foreman_tasks_permissions.rb
|
141
170
|
- db/seeds.d/60-dynflow_proxy_feature.rb
|
142
171
|
- db/seeds.d/61-foreman_tasks_bookmarks.rb
|
@@ -171,6 +200,8 @@ files:
|
|
171
200
|
- test/unit/actions/proxy_action_test.rb
|
172
201
|
- test/unit/cleaner_test.rb
|
173
202
|
- test/unit/dynflow_console_authorizer_test.rb
|
203
|
+
- test/unit/recurring_logic_test.rb
|
204
|
+
- test/unit/task_groups_test.rb
|
174
205
|
- test/unit/task_test.rb
|
175
206
|
homepage: https://github.com/theforeman/foreman-tasks
|
176
207
|
licenses: []
|
@@ -181,17 +212,17 @@ require_paths:
|
|
181
212
|
- lib
|
182
213
|
required_ruby_version: !ruby/object:Gem::Requirement
|
183
214
|
requirements:
|
184
|
-
- -
|
215
|
+
- - ">="
|
185
216
|
- !ruby/object:Gem::Version
|
186
217
|
version: '0'
|
187
218
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
188
219
|
requirements:
|
189
|
-
- -
|
220
|
+
- - ">="
|
190
221
|
- !ruby/object:Gem::Version
|
191
222
|
version: '0'
|
192
223
|
requirements: []
|
193
224
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.4.
|
225
|
+
rubygems_version: 2.4.5
|
195
226
|
signing_key:
|
196
227
|
specification_version: 4
|
197
228
|
summary: Foreman plugin for showing tasks information for resoruces and users
|
@@ -204,7 +235,8 @@ test_files:
|
|
204
235
|
- test/factories/task_factory.rb
|
205
236
|
- test/unit/cleaner_test.rb
|
206
237
|
- test/unit/dynflow_console_authorizer_test.rb
|
238
|
+
- test/unit/recurring_logic_test.rb
|
207
239
|
- test/unit/actions/proxy_action_test.rb
|
208
240
|
- test/unit/actions/action_with_sub_plans_test.rb
|
209
241
|
- test/unit/task_test.rb
|
210
|
-
|
242
|
+
- test/unit/task_groups_test.rb
|