foreman-tasks 0.7.7 → 0.7.8
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/app/controllers/foreman_tasks/api/tasks_controller.rb +5 -1
- data/app/controllers/foreman_tasks/tasks_controller.rb +2 -2
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +1 -1
- data/app/lib/actions/base.rb +1 -1
- data/app/models/foreman_tasks/concerns/action_triggering.rb +1 -1
- data/app/models/foreman_tasks/concerns/host_action_subject.rb +2 -2
- data/app/models/foreman_tasks/recurring_logic.rb +7 -4
- data/app/models/foreman_tasks/task.rb +12 -5
- data/app/models/foreman_tasks/task/dynflow_task.rb +1 -1
- data/app/models/foreman_tasks/triggering.rb +10 -9
- data/db/seeds.d/60-dynflow_proxy_feature.rb +1 -1
- data/db/seeds.d/61-foreman_tasks_bookmarks.rb +1 -1
- data/lib/foreman_tasks.rb +2 -2
- data/lib/foreman_tasks/dynflow/console_authorizer.rb +1 -1
- data/lib/foreman_tasks/dynflow/persistence.rb +3 -3
- data/lib/foreman_tasks/engine.rb +6 -4
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +1 -1
- data/test/unit/actions/action_with_sub_plans_test.rb +1 -1
- data/test/unit/recurring_logic_test.rb +16 -0
- data/test/unit/task_groups_test.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28eae441ee8a39d7955e3d5a9fb33f87cea7b871
|
4
|
+
data.tar.gz: 21c37d4267f52e05e36ee008a33c38f3660f3fec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3ba85d54a8e1ee742a25b8c82299a377d685ab8628d9aee62af83009f6914d0b0e35e8cef029eacdd5bacc252c27e5b310e3b5fd5a495717112aa7e518189d35
|
7
|
+
data.tar.gz: 9278556260d43ff5f39c8269dc586e99ba6bb11205f3b680f7a5084d72fafe34d5611c046c18d4500e5c5617326ff6bf973e51ad40fa291b9ead4164c54dab57
|
@@ -29,7 +29,7 @@ module ForemanTasks
|
|
29
29
|
class BadRequest < Apipie::ParamError
|
30
30
|
end
|
31
31
|
|
32
|
-
before_filter :
|
32
|
+
before_filter :find_task, :only => [:show]
|
33
33
|
|
34
34
|
api :GET, "/tasks/summary", "Show task summary"
|
35
35
|
def summary
|
@@ -259,6 +259,10 @@ module ForemanTasks
|
|
259
259
|
|
260
260
|
private
|
261
261
|
|
262
|
+
def find_task
|
263
|
+
@task = Task.find(params[:id])
|
264
|
+
end
|
265
|
+
|
262
266
|
def resource_scope(options = {})
|
263
267
|
@resource_scope ||= ForemanTasks::Task.authorized("#{action_permission}_foreman_tasks")
|
264
268
|
end
|
@@ -5,7 +5,7 @@ module ForemanTasks
|
|
5
5
|
before_filter :restrict_dangerous_actions, :only => [:unlock, :force_unlock]
|
6
6
|
|
7
7
|
def show
|
8
|
-
@task =
|
8
|
+
@task = Task.find(params[:id])
|
9
9
|
end
|
10
10
|
|
11
11
|
def index
|
@@ -14,7 +14,7 @@ module ForemanTasks
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def sub_tasks
|
17
|
-
task =
|
17
|
+
task = Task.find(params[:id])
|
18
18
|
@tasks = filter(task.sub_tasks)
|
19
19
|
render :index
|
20
20
|
end
|
@@ -64,7 +64,7 @@ module ForemanTasks
|
|
64
64
|
def future_mode_fieldset(f, triggering)
|
65
65
|
tags = []
|
66
66
|
tags << text_f(f, :start_at_raw, :label => _('Start at'), :placeholder => 'YYYY-mm-dd HH:MM')
|
67
|
-
tags << text_f(f, :start_before_raw, :label => _('Start before'), :placeholder => 'YYYY-mm-dd HH:MM')
|
67
|
+
tags << text_f(f, :start_before_raw, :label => _('Start before'), :placeholder => 'YYYY-mm-dd HH:MM', :help_inline => popover(_('Explanation'), _('Indicates that the action should be cancelled if it cannot be started before this time.')))
|
68
68
|
content_tag(:fieldset, nil, :id => "trigger_mode_future", :class => "trigger_mode_form #{'hidden' unless triggering.future?}") do
|
69
69
|
tags.join.html_safe
|
70
70
|
end
|
data/app/lib/actions/base.rb
CHANGED
@@ -2,7 +2,7 @@ module Actions
|
|
2
2
|
class Base < Dynflow::Action
|
3
3
|
|
4
4
|
def task
|
5
|
-
@task ||= ::ForemanTasks::Task::DynflowTask.
|
5
|
+
@task ||= ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first!
|
6
6
|
end
|
7
7
|
|
8
8
|
# This method says what data form input gets into the task details in Rest API
|
@@ -130,7 +130,7 @@ module ForemanTasks
|
|
130
130
|
if @dynflow_sync_action
|
131
131
|
run.wait
|
132
132
|
if run.value.error?
|
133
|
-
task = ForemanTasks::Task::DynflowTask.
|
133
|
+
task = ForemanTasks::Task::DynflowTask.where(:external_id => @execution_plan.id).first!
|
134
134
|
raise ForemanTasks::TaskError.new(task)
|
135
135
|
end
|
136
136
|
end
|
@@ -22,8 +22,8 @@ module ForemanTasks
|
|
22
22
|
hostname.try(:downcase!)
|
23
23
|
certname.try(:downcase!)
|
24
24
|
|
25
|
-
host = certname.present? ? Host.
|
26
|
-
host ||= Host.
|
25
|
+
host = certname.present? ? Host.where(:certname => certname).first : nil
|
26
|
+
host ||= Host.where(:name => hostname).first
|
27
27
|
host ||= Host.new(:name => hostname, :certname => certname) if Setting[:create_new_host_when_facts_are_uploaded]
|
28
28
|
if host
|
29
29
|
# if we were given a certname but found the Host by hostname we should update the certname
|
@@ -9,7 +9,11 @@ module ForemanTasks
|
|
9
9
|
belongs_to :triggering
|
10
10
|
|
11
11
|
has_many :tasks, :through => :task_group
|
12
|
-
|
12
|
+
if Rails::VERSION::MAJOR < 4
|
13
|
+
has_many :task_groups, :through => :tasks, :uniq => true
|
14
|
+
else
|
15
|
+
has_many :task_groups, -> { uniq }, :through => :tasks
|
16
|
+
end
|
13
17
|
|
14
18
|
validates :cron_line, :presence => true
|
15
19
|
|
@@ -116,10 +120,9 @@ module ForemanTasks
|
|
116
120
|
|
117
121
|
def self.cronline_hash(recurring_type, time_hash, days_of_week_hash)
|
118
122
|
hash = Hash[[:years, :months, :days, :hours, :minutes].zip(time_hash.values)]
|
119
|
-
|
120
123
|
hash.update :days_of_week => days_of_week_hash
|
121
|
-
.select { |
|
122
|
-
.
|
124
|
+
.select { |key, value| value == "1" }
|
125
|
+
.keys.join(',')
|
123
126
|
allowed_keys = case recurring_type
|
124
127
|
when :monthly
|
125
128
|
[:minutes, :hours, :days]
|
@@ -15,12 +15,19 @@ module ForemanTasks
|
|
15
15
|
|
16
16
|
has_many :task_group_members
|
17
17
|
has_many :task_groups, :through => :task_group_members
|
18
|
-
|
18
|
+
if Rails::VERSION::MAJOR < 4
|
19
|
+
has_many :recurring_logic_task_groups, :through => :task_group_members, :conditions => { :type => 'ForemanTasks::TaskGroups::RecurringLogicTaskGroup' }, :source => :task_group
|
20
|
+
has_many :owners, :through => :locks, :source => :resource, :source_type => 'User',
|
21
|
+
:conditions => ["foreman_tasks_locks.name = ?", Lock::OWNER_LOCK_NAME]
|
22
|
+
else
|
23
|
+
has_many :recurring_logic_task_groups, -> { where :type => 'ForemanTasks::TaskGroups::RecurringLogicTaskGroup' },
|
24
|
+
:through => :task_group_members, :source => :task_group
|
25
|
+
# in fact, the task has only one owner but Rails don't let you to
|
26
|
+
# specify has_one relation though has_many relation
|
27
|
+
has_many :owners, lambda {where(["foreman_tasks_locks.name = ?", Lock::OWNER_LOCK_NAME])},
|
28
|
+
:through => :locks, :source => :resource, :source_type => 'User'
|
29
|
+
end
|
19
30
|
|
20
|
-
# in fact, the task has only one owner but Rails don't let you to
|
21
|
-
# specify has_one relation though has_many relation
|
22
|
-
has_many :owners, :through => :locks, :source => :resource, :source_type => 'User',
|
23
|
-
:conditions => ["foreman_tasks_locks.name = ?", Lock::OWNER_LOCK_NAME]
|
24
31
|
|
25
32
|
scoped_search :on => :id, :complete_value => false
|
26
33
|
scoped_search :on => :label, :complete_value => true
|
@@ -15,7 +15,7 @@ module ForemanTasks
|
|
15
15
|
self.start_before = data[:start_before] if data[:start_before]
|
16
16
|
self.parent_task_id ||= begin
|
17
17
|
if main_action.caller_execution_plan_id
|
18
|
-
DynflowTask.
|
18
|
+
DynflowTask.where(:external_id => main_action.caller_execution_plan_id).first!.id
|
19
19
|
end
|
20
20
|
end
|
21
21
|
self.label ||= main_action.class.name
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module ForemanTasks
|
2
2
|
class Triggering < ActiveRecord::Base
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
PARAMS = [:start_at_raw, :start_before_raw, :max_iteration, :input_type,
|
4
|
+
:cronline, :days, :days_of_week, :time, :end_time_limited,
|
5
|
+
:end_time]
|
6
|
+
attr_accessor *PARAMS
|
7
|
+
attr_accessible *PARAMS
|
7
8
|
|
8
9
|
before_save do
|
9
10
|
if future?
|
@@ -39,11 +40,11 @@ module ForemanTasks
|
|
39
40
|
validate :correct_cronline, :if => Proc.new { |t| t.recurring? && t.input_type == :cronline }
|
40
41
|
|
41
42
|
def self.new_from_params(params = {})
|
42
|
-
self.new(params).tap do |
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
self.new(params.except(:mode, :start_at, :start_before)).tap do |triggering|
|
44
|
+
triggering.mode = params.fetch(:mode, :immediate).to_sym
|
45
|
+
triggering.input_type = params.fetch(:input_type, :daily).to_sym
|
46
|
+
triggering.end_time_limited = params[:end_time_limited] == "true"
|
47
|
+
triggering.start_at_raw ||= Time.now.strftime(TIME_FORMAT)
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
@@ -1,2 +1,2 @@
|
|
1
|
-
f = Feature.
|
1
|
+
f = Feature.where(:name => 'Dynflow').first_or_create
|
2
2
|
raise "Unable to create proxy feature: #{format_errors f}" if f.nil? || f.errors.any?
|
@@ -4,7 +4,7 @@ Bookmark.without_auditing do
|
|
4
4
|
{ :name => "failed", :query => "state = paused or result = error or result = warning" }
|
5
5
|
|
6
6
|
].each do |item|
|
7
|
-
next if Bookmark.
|
7
|
+
next if Bookmark.where(:name => item[:name]).first
|
8
8
|
next if audit_modified? Bookmark, item[:name]
|
9
9
|
b = Bookmark.create({:controller => "foreman_tasks_tasks", :public => true}.merge(item))
|
10
10
|
raise "Unable to create bookmark: #{format_errors b}" if b.nil? || b.errors.any?
|
data/lib/foreman_tasks.rb
CHANGED
@@ -27,7 +27,7 @@ module ForemanTasks
|
|
27
27
|
end),
|
28
28
|
(on ::Dynflow::World::Triggered.(execution_plan_id: ~any, future: ~any) do |id, finished|
|
29
29
|
finished.wait if async == false
|
30
|
-
ForemanTasks::Task::DynflowTask.
|
30
|
+
ForemanTasks::Task::DynflowTask.where(:external_id => id).first!
|
31
31
|
end)
|
32
32
|
end
|
33
33
|
|
@@ -43,6 +43,6 @@ module ForemanTasks
|
|
43
43
|
|
44
44
|
def self.delay(action, delay_options, *args)
|
45
45
|
result = dynflow.world.delay action, delay_options, *args
|
46
|
-
ForemanTasks::Task::DynflowTask.
|
46
|
+
ForemanTasks::Task::DynflowTask.where(:external_id => result.id).first!
|
47
47
|
end
|
48
48
|
end
|
@@ -4,7 +4,7 @@ module ForemanTasks
|
|
4
4
|
def initialize(env)
|
5
5
|
@rack_request = Rack::Request.new(env)
|
6
6
|
@user_id, @expires_at = @rack_request.session.values_at('user', 'expires_at')
|
7
|
-
@user = User.
|
7
|
+
@user = User.where(:id => @user_id).first unless session_expired?
|
8
8
|
end
|
9
9
|
|
10
10
|
def allow?
|
@@ -31,15 +31,15 @@ module ForemanTasks
|
|
31
31
|
raise Foreman::Exception.new('Plan is delayed but the delay record is missing') if delayed_plan.nil?
|
32
32
|
# TODO: Rework this
|
33
33
|
delayed_plan = ::Dynflow::DelayedPlan.new_from_hash(ForemanTasks.dynflow.world, delayed_plan)
|
34
|
-
task = ::ForemanTasks::Task::DynflowTask.
|
34
|
+
task = ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first
|
35
35
|
task.update_from_dynflow(data.merge(:start_at => delayed_plan.start_at,
|
36
36
|
:start_before => delayed_plan.start_before))
|
37
37
|
when :planning
|
38
|
-
task = ::ForemanTasks::Task::DynflowTask.
|
38
|
+
task = ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first
|
39
39
|
task.update_from_dynflow(data)
|
40
40
|
Lock.owner!(::User.current, task.id) if ::User.current
|
41
41
|
else
|
42
|
-
if task = ::ForemanTasks::Task::DynflowTask.
|
42
|
+
if task = ::ForemanTasks::Task::DynflowTask.where(:external_id => execution_plan_id).first
|
43
43
|
unless task.state.to_s == data[:state].to_s
|
44
44
|
task.update_from_dynflow(data)
|
45
45
|
end
|
data/lib/foreman_tasks/engine.rb
CHANGED
@@ -26,11 +26,11 @@ module ForemanTasks
|
|
26
26
|
permission :edit_foreman_tasks, {:'foreman_tasks/tasks' => [:resume, :unlock, :force_unlock, :cancel_step, :cancel],
|
27
27
|
:'foreman_tasks/api/tasks' => [:bulk_resume]}, :resource_type => ForemanTasks::Task.name
|
28
28
|
|
29
|
-
permission :create_recurring_logics, { }, :resource_type => ForemanTasks::RecurringLogic
|
29
|
+
permission :create_recurring_logics, { }, :resource_type => ForemanTasks::RecurringLogic.name
|
30
30
|
|
31
|
-
permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:index, :show] }, :resource_type => ForemanTasks::RecurringLogic
|
31
|
+
permission :view_recurring_logics, { :'foreman_tasks/recurring_logics' => [:index, :show] }, :resource_type => ForemanTasks::RecurringLogic.name
|
32
32
|
|
33
|
-
permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel] }, :resource_type => ForemanTasks::RecurringLogic
|
33
|
+
permission :edit_recurring_logics, { :'foreman_tasks/recurring_logics' => [:cancel] }, :resource_type => ForemanTasks::RecurringLogic.name
|
34
34
|
|
35
35
|
end
|
36
36
|
|
@@ -70,7 +70,9 @@ module ForemanTasks
|
|
70
70
|
end
|
71
71
|
|
72
72
|
initializer "foreman_tasks.load_app_instance_data" do |app|
|
73
|
-
|
73
|
+
ForemanTasks::Engine.paths['db/migrate'].existent.each do |path|
|
74
|
+
app.config.paths['db/migrate'] << path
|
75
|
+
end
|
74
76
|
end
|
75
77
|
|
76
78
|
# to enable async Foreman operations using Dynflow
|
@@ -29,7 +29,7 @@ module ForemanTasks
|
|
29
29
|
triggered = ForemanTasks.trigger(Support::DummyProxyAction, Support::DummyProxyAction.proxy, 'foo' => 'bar')
|
30
30
|
Support::DummyProxyAction.proxy.task_triggered.wait(5)
|
31
31
|
|
32
|
-
task = ForemanTasks::Task.
|
32
|
+
task = ForemanTasks::Task.where(:external_id => triggered.id).first
|
33
33
|
task.state.must_equal 'running'
|
34
34
|
task.result.must_equal 'pending'
|
35
35
|
|
@@ -40,7 +40,7 @@ module ForemanTasks
|
|
40
40
|
triggered = ForemanTasks.trigger(ParentAction, user)
|
41
41
|
raise triggered.error if triggered.respond_to?(:error)
|
42
42
|
triggered.finished.wait(2)
|
43
|
-
ForemanTasks::Task.
|
43
|
+
ForemanTasks::Task.where(:external_id => triggered.id).first
|
44
44
|
end
|
45
45
|
|
46
46
|
specify "the sub-plan stores the information about its parent" do
|
@@ -36,6 +36,22 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
36
36
|
parser.next_occurrence_time(reference_time).must_equal Time.new(year, month + 1, 5)
|
37
37
|
end
|
38
38
|
|
39
|
+
it 'creates correct cronline hash' do
|
40
|
+
minutes = '52'
|
41
|
+
hours = '12'
|
42
|
+
days = '11'
|
43
|
+
days_of_week = { '1' => '1', '2' => '0', '3' => '0', '4' => '1', '5' => '0', '6' => '1', '7' => '0' }
|
44
|
+
time_hash = { '0' => '2015', '1' => '12', '2' => '11', '3' => hours, '4' => minutes }
|
45
|
+
expected_result_hourly = { :minutes => minutes }
|
46
|
+
expected_result_daily = { :minutes => minutes, :hours => hours }
|
47
|
+
expected_result_weekly = { :minutes => minutes, :hours => hours, :days_of_week => '1,4,6' }
|
48
|
+
expected_result_monthly = { :minutes => minutes, :hours => hours, :days => days }
|
49
|
+
ForemanTasks::RecurringLogic.cronline_hash(:hourly, time_hash, days_of_week).must_equal expected_result_hourly
|
50
|
+
ForemanTasks::RecurringLogic.cronline_hash(:daily, time_hash, days_of_week).must_equal expected_result_daily
|
51
|
+
ForemanTasks::RecurringLogic.cronline_hash(:weekly, time_hash, days_of_week).must_equal expected_result_weekly
|
52
|
+
ForemanTasks::RecurringLogic.cronline_hash(:monthly, time_hash, days_of_week).must_equal expected_result_monthly
|
53
|
+
end
|
54
|
+
|
39
55
|
it 'can have limited number of repeats' do
|
40
56
|
parser = ForemanTasks::RecurringLogic.new_from_cronline('* * * * *')
|
41
57
|
parser.state = 'active'
|
@@ -51,7 +51,7 @@ module ForemanTasks
|
|
51
51
|
triggered = ForemanTasks.trigger(action_class, *args)
|
52
52
|
raise triggered.error if triggered.respond_to?(:error)
|
53
53
|
triggered.finished.wait
|
54
|
-
ForemanTasks::Task.
|
54
|
+
ForemanTasks::Task.where(:external_id => triggered.id).first
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.8
|
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-12-
|
11
|
+
date: 2015-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dynflow
|