foreman-tasks 0.10.8 → 0.10.9
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/.rubocop.yml +16 -1
- data/.rubocop_todo.yml +49 -68
- data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +1 -1
- data/app/models/foreman_tasks/lock.rb +7 -8
- data/deploy/foreman-tasks.sysconfig +0 -1
- data/foreman-tasks.gemspec +0 -2
- data/lib/foreman_tasks/version.rb +1 -1
- data/test/controllers/api/recurring_logics_controller_test.rb +1 -1
- data/test/controllers/api/tasks_controller_test.rb +1 -1
- data/test/factories/recurring_logic_factory.rb +1 -1
- data/test/factories/task_factory.rb +1 -1
- data/test/factories/triggering_factory.rb +1 -1
- data/test/foreman_tasks_test_helper.rb +2 -2
- data/test/helpers/foreman_tasks/tasks_helper_test.rb +2 -2
- data/test/unit/actions/action_with_sub_plans_test.rb +1 -1
- data/test/unit/cleaner_test.rb +12 -12
- data/test/unit/dynflow_console_authorizer_test.rb +11 -11
- data/test/unit/lock_test.rb +22 -0
- data/test/unit/proxy_selector_test.rb +4 -4
- data/test/unit/recurring_logic_test.rb +2 -2
- data/test/unit/task_test.rb +17 -17
- data/test/unit/triggering_test.rb +4 -4
- metadata +4 -16
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f56949ea2cda099243fd048786274ee80dd94920
|
|
4
|
+
data.tar.gz: 307449f1fe7f6a18fa029bf6f418e257231f2484
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a9d26057cf27ab1255eec075b935c201864ea4e47b46f3aae45e61a121b65d8817bdec5e878fd8822962e2d32cadb2e0fff3ab41c58a62f5a5c23a77dca9750
|
|
7
|
+
data.tar.gz: 99a89d2b357dd0a8a96dbcf3f9651bfafe14ad125b75c26455291e65ea064260f77715d45d936b6874ddf9659ba5a92794bdad6d5efe6b3dde6ada0b12b3f8e3
|
data/.rubocop.yml
CHANGED
|
@@ -76,5 +76,20 @@ Layout/IndentHeredoc:
|
|
|
76
76
|
- '*.gemspec'
|
|
77
77
|
- bin/*
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
Style/IfUnlessModifier:
|
|
80
|
+
Enabled: false
|
|
81
|
+
|
|
82
|
+
Style/NumericPredicate:
|
|
83
|
+
Enabled: false
|
|
84
|
+
|
|
85
|
+
Style/IfUnlessModifier:
|
|
86
|
+
Enabled: false
|
|
87
|
+
|
|
88
|
+
Style/SafeNavigation:
|
|
89
|
+
Enabled: false
|
|
90
|
+
|
|
91
|
+
Performance/RegexpMatch:
|
|
92
|
+
Enabled: false
|
|
93
|
+
|
|
94
|
+
Style/FormatStringToken:
|
|
80
95
|
Enabled: false
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,136 +1,117 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
|
-
# `rubocop --auto-gen-config`
|
|
3
|
-
# on
|
|
2
|
+
# `rubocop --auto-gen-config --exclude-limit 0`
|
|
3
|
+
# on 2017-12-20 11:41:34 +0100 using RuboCop version 0.49.1.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
# Offense count: 1
|
|
10
|
+
# Cop supports --auto-correct.
|
|
11
|
+
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
12
|
+
# SupportedStyles: final_newline, final_blank_line
|
|
13
|
+
Layout/TrailingBlankLines:
|
|
14
|
+
Enabled: false
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
# Offense count: 1
|
|
17
|
+
Lint/EmptyWhen:
|
|
18
|
+
Enabled: false
|
|
16
19
|
|
|
20
|
+
# Offense count: 2
|
|
17
21
|
Lint/UselessAssignment:
|
|
18
|
-
|
|
19
|
-
- 'lib/foreman_tasks/tasks/export_tasks.rake'
|
|
22
|
+
Enabled: false
|
|
20
23
|
|
|
24
|
+
# Offense count: 32
|
|
21
25
|
Metrics/AbcSize:
|
|
22
26
|
Max: 41
|
|
23
27
|
|
|
24
|
-
#
|
|
28
|
+
# Offense count: 15
|
|
29
|
+
# Configuration parameters: CountComments, ExcludedMethods.
|
|
25
30
|
Metrics/BlockLength:
|
|
26
31
|
Max: 105
|
|
27
32
|
|
|
33
|
+
# Offense count: 12
|
|
28
34
|
# Configuration parameters: CountComments.
|
|
29
35
|
Metrics/ClassLength:
|
|
30
36
|
Max: 230
|
|
31
37
|
|
|
38
|
+
# Offense count: 9
|
|
32
39
|
Metrics/CyclomaticComplexity:
|
|
33
|
-
Max:
|
|
40
|
+
Max: 9
|
|
34
41
|
|
|
42
|
+
# Offense count: 453
|
|
35
43
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
|
36
44
|
# URISchemes: http, https
|
|
37
45
|
Metrics/LineLength:
|
|
38
|
-
Max:
|
|
46
|
+
Max: 211
|
|
39
47
|
|
|
48
|
+
# Offense count: 51
|
|
40
49
|
# Configuration parameters: CountComments.
|
|
41
50
|
Metrics/MethodLength:
|
|
42
|
-
Max:
|
|
51
|
+
Max: 29
|
|
43
52
|
|
|
53
|
+
# Offense count: 2
|
|
44
54
|
# Configuration parameters: CountComments.
|
|
45
55
|
Metrics/ModuleLength:
|
|
46
|
-
Max:
|
|
56
|
+
Max: 168
|
|
47
57
|
|
|
58
|
+
# Offense count: 1
|
|
48
59
|
# Configuration parameters: CountKeywordArgs.
|
|
49
60
|
Metrics/ParameterLists:
|
|
50
61
|
Max: 6
|
|
51
62
|
|
|
63
|
+
# Offense count: 4
|
|
52
64
|
Metrics/PerceivedComplexity:
|
|
53
|
-
Max:
|
|
65
|
+
Max: 9
|
|
54
66
|
|
|
67
|
+
# Offense count: 4
|
|
68
|
+
# Cop supports --auto-correct.
|
|
55
69
|
# Configuration parameters: Include.
|
|
56
|
-
# Include:
|
|
57
|
-
Rails/Exit:
|
|
58
|
-
Exclude:
|
|
59
|
-
- 'lib/**/*.rake'
|
|
60
|
-
|
|
70
|
+
# Include: spec/**/*, test/**/*
|
|
61
71
|
Rails/HttpPositionalArguments:
|
|
62
72
|
Enabled: false
|
|
63
73
|
|
|
74
|
+
# Offense count: 1
|
|
64
75
|
# Configuration parameters: Include.
|
|
65
76
|
# Include: app/**/*.rb, config/**/*.rb, db/**/*.rb, lib/**/*.rb
|
|
66
77
|
Rails/Output:
|
|
67
|
-
|
|
68
|
-
- 'lib/foreman_tasks/cleaner.rb'
|
|
78
|
+
Enabled: false
|
|
69
79
|
|
|
80
|
+
# Offense count: 5
|
|
70
81
|
Rails/OutputSafety:
|
|
71
|
-
|
|
72
|
-
- 'app/helpers/foreman_tasks/foreman_tasks_helper.rb'
|
|
82
|
+
Enabled: false
|
|
73
83
|
|
|
84
|
+
# Offense count: 11
|
|
74
85
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
75
86
|
# SupportedStyles: nested, compact
|
|
76
87
|
Style/ClassAndModuleChildren:
|
|
77
|
-
|
|
78
|
-
- 'app/lib/actions/action_with_sub_plans.rb'
|
|
79
|
-
- 'app/models/foreman_tasks/task/dynflow_task.rb'
|
|
80
|
-
- 'app/models/foreman_tasks/task/status_explicator.rb'
|
|
81
|
-
- 'app/models/foreman_tasks/task/summarizer.rb'
|
|
82
|
-
- 'app/models/foreman_tasks/task/task_cancelled_exception.rb'
|
|
83
|
-
- 'app/models/setting/foreman_tasks.rb'
|
|
84
|
-
- 'lib/foreman_tasks/dynflow/configuration.rb'
|
|
85
|
-
- 'lib/foreman_tasks/dynflow/console_authorizer.rb'
|
|
86
|
-
- 'lib/foreman_tasks/dynflow/persistence.rb'
|
|
87
|
-
- 'test/controllers/api/recurring_logics_controller_test.rb'
|
|
88
|
-
- 'test/controllers/api/tasks_controller_test.rb'
|
|
89
|
-
- 'test/unit/actions/action_with_sub_plans_test.rb'
|
|
88
|
+
Enabled: false
|
|
90
89
|
|
|
90
|
+
# Offense count: 2
|
|
91
91
|
Style/DoubleNegation:
|
|
92
|
-
|
|
93
|
-
- 'app/models/foreman_tasks/lock.rb'
|
|
94
|
-
- 'app/models/foreman_tasks/recurring_logic.rb'
|
|
95
|
-
|
|
96
|
-
# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts.
|
|
97
|
-
Style/FileName:
|
|
98
|
-
Exclude:
|
|
99
|
-
- 'db/seeds.d/20-foreman_tasks_permissions.rb'
|
|
100
|
-
- 'db/seeds.d/60-dynflow_proxy_feature.rb'
|
|
101
|
-
- 'db/seeds.d/61-foreman_tasks_bookmarks.rb'
|
|
102
|
-
- 'lib/foreman-tasks.rb'
|
|
103
|
-
|
|
104
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
|
105
|
-
# SupportedStyles: format, sprintf, percent
|
|
106
|
-
Style/FormatString:
|
|
107
|
-
Exclude:
|
|
108
|
-
- 'app/models/foreman_tasks/task/dynflow_task.rb'
|
|
109
|
-
- 'lib/foreman_tasks/tasks/export_tasks.rake'
|
|
92
|
+
Enabled: false
|
|
110
93
|
|
|
94
|
+
# Offense count: 31
|
|
111
95
|
# Configuration parameters: MinBodyLength.
|
|
112
96
|
Style/GuardClause:
|
|
113
97
|
Enabled: false
|
|
114
98
|
|
|
99
|
+
# Offense count: 1
|
|
115
100
|
# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist.
|
|
116
101
|
# NamePrefix: is_, has_, have_
|
|
117
102
|
# NamePrefixBlacklist: is_, has_, have_
|
|
118
103
|
# NameWhitelist: is_a?
|
|
119
104
|
Style/PredicateName:
|
|
120
|
-
|
|
121
|
-
- 'spec/**/*'
|
|
122
|
-
- 'app/models/foreman_tasks/task/status_explicator.rb'
|
|
105
|
+
Enabled: false
|
|
123
106
|
|
|
107
|
+
# Offense count: 1
|
|
108
|
+
# Cop supports --auto-correct.
|
|
109
|
+
Style/RedundantSelf:
|
|
110
|
+
Enabled: false
|
|
111
|
+
|
|
112
|
+
# Offense count: 1
|
|
124
113
|
# Cop supports --auto-correct.
|
|
125
114
|
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
|
|
126
115
|
# SupportedStyles: slashes, percent_r, mixed
|
|
127
116
|
Style/RegexpLiteral:
|
|
128
|
-
|
|
129
|
-
- 'lib/foreman_tasks/dynflow/console_authorizer.rb'
|
|
130
|
-
|
|
131
|
-
# Configuration parameters: Methods.
|
|
132
|
-
# Methods: {"reduce"=>["acc", "elem"]}, {"inject"=>["acc", "elem"]}
|
|
133
|
-
Style/SingleLineBlockParams:
|
|
134
|
-
Exclude:
|
|
135
|
-
- 'app/models/foreman_tasks/concerns/action_subject.rb'
|
|
136
|
-
- 'app/models/foreman_tasks/lock.rb'
|
|
117
|
+
Enabled: false
|
|
@@ -9,7 +9,7 @@ module ForemanTasks
|
|
|
9
9
|
api_base_url '/foreman_tasks/api'
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
before_action :find_resource, :only => %w[show cancel
|
|
12
|
+
before_action :find_resource, :only => %w[show cancel]
|
|
13
13
|
|
|
14
14
|
api :GET, '/recurring_logics', N_('List recurring logics')
|
|
15
15
|
def index
|
|
@@ -12,14 +12,13 @@ module ForemanTasks
|
|
|
12
12
|
class LockConflict < StandardError
|
|
13
13
|
attr_reader :required_lock, :conflicting_locks
|
|
14
14
|
def initialize(required_lock, conflicting_locks)
|
|
15
|
-
header =
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
header << "\n"
|
|
15
|
+
header = <<-HEADER.gsub(/^\s+\| ?/, '')
|
|
16
|
+
| #{_('Required lock is already taken by other running tasks.')}
|
|
17
|
+
| #{_('Please inspect their state, fix their errors and resume them.')}
|
|
18
|
+
|
|
|
19
|
+
| #{_('Required lock: %s') % required_lock.name}
|
|
20
|
+
| #{_('Conflicts with tasks:')}
|
|
21
|
+
HEADER
|
|
23
22
|
url_helpers = Rails.application.routes.url_helpers
|
|
24
23
|
conflicting_tasks = conflicting_locks
|
|
25
24
|
.map(&:task)
|
data/foreman-tasks.gemspec
CHANGED
|
@@ -33,6 +33,4 @@ same resource. It also optionally provides Dynflow infrastructure for using it f
|
|
|
33
33
|
s.add_dependency "sinatra" # for Dynflow web console
|
|
34
34
|
s.add_dependency "parse-cron", '~> 0.1.4'
|
|
35
35
|
s.add_dependency "get_process_mem" # for memory polling
|
|
36
|
-
|
|
37
|
-
s.add_development_dependency 'factory_bot_rails', '~> 4.8.0'
|
|
38
36
|
end
|
|
@@ -9,7 +9,7 @@ module ForemanRecurringLogic
|
|
|
9
9
|
User.current = User.where(:login => 'apiadmin').first
|
|
10
10
|
@request.env['HTTP_ACCEPT'] = 'application/json'
|
|
11
11
|
@request.env['CONTENT_TYPE'] = 'application/json'
|
|
12
|
-
@recurring_logic =
|
|
12
|
+
@recurring_logic = FactoryGirl.create(:recurring_logic)
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
describe 'GET /api/recurring_logics' do
|
|
@@ -13,7 +13,7 @@ module ForemanTasks
|
|
|
13
13
|
|
|
14
14
|
describe 'GET /api/tasks/show' do
|
|
15
15
|
it 'searches for task' do
|
|
16
|
-
task =
|
|
16
|
+
task = FactoryGirl.create(:dynflow_task, :user_create_task)
|
|
17
17
|
get :show, :id => task.id
|
|
18
18
|
assert_response :success
|
|
19
19
|
assert_template 'api/tasks/show'
|
|
@@ -4,8 +4,8 @@ require_relative './support/dummy_proxy_action'
|
|
|
4
4
|
|
|
5
5
|
require 'dynflow/testing'
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
FactoryGirl.definition_file_paths = ["#{ForemanTasks::Engine.root}/test/factories"]
|
|
8
|
+
FactoryGirl.find_definitions
|
|
9
9
|
|
|
10
10
|
ForemanTasks.dynflow.require!
|
|
11
11
|
ForemanTasks.dynflow.config.disable_active_record_actions = true
|
|
@@ -4,7 +4,7 @@ module ForemanTasks
|
|
|
4
4
|
class TasksHelperTest < ActionView::TestCase
|
|
5
5
|
describe 'when formatting simple input' do
|
|
6
6
|
before do
|
|
7
|
-
@task =
|
|
7
|
+
@task = FactoryGirl.build(:dynflow_task, :user_create_task)
|
|
8
8
|
humanized = { :humanized_name => 'Create', :humanized_input => [[:user, { :text => "user 'Anonymous Admin'", :link => nil }]] }
|
|
9
9
|
@task.instance_variable_set('@humanized_cache', humanized)
|
|
10
10
|
@task.stubs(:input).returns('user' => { 'id' => 1, 'name' => 'Anonymous Admin' }, 'locale' => 'en')
|
|
@@ -21,7 +21,7 @@ module ForemanTasks
|
|
|
21
21
|
|
|
22
22
|
describe 'when formatting input' do
|
|
23
23
|
before do
|
|
24
|
-
@task =
|
|
24
|
+
@task = FactoryGirl.build(:dynflow_task, :product_create_task)
|
|
25
25
|
humanized = { :humanized_name => 'Create',
|
|
26
26
|
:humanized_input => [[:product, { :text => "product 'product-2'", :link => '#/products/3/info' }], [:organization, { :text => "organization 'test-0'", :link => '/organizations/3/edit' }]] }
|
|
27
27
|
@task.instance_variable_set('@humanized_cache', humanized)
|
|
@@ -34,7 +34,7 @@ module ForemanTasks
|
|
|
34
34
|
|
|
35
35
|
describe Actions::ActionWithSubPlans do
|
|
36
36
|
let(:task) do
|
|
37
|
-
user =
|
|
37
|
+
user = FactoryGirl.create(:user)
|
|
38
38
|
triggered = ForemanTasks.trigger(ParentAction, user)
|
|
39
39
|
raise triggered.error if triggered.respond_to?(:error)
|
|
40
40
|
triggered.finished.wait(2)
|
data/test/unit/cleaner_test.rb
CHANGED
|
@@ -10,13 +10,13 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
10
10
|
it 'is able to delete tasks (including the dynflow plans) based on filter' do
|
|
11
11
|
cleaner = ForemanTasks::Cleaner.new(:filter => 'label = "Actions::User::Create"', :after => '10d')
|
|
12
12
|
|
|
13
|
-
tasks_to_delete = [
|
|
14
|
-
|
|
15
|
-
tasks_to_keep = [
|
|
13
|
+
tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task),
|
|
14
|
+
FactoryGirl.create(:dynflow_task, :user_create_task)]
|
|
15
|
+
tasks_to_keep = [FactoryGirl.create(:dynflow_task, :user_create_task) do |task|
|
|
16
16
|
task.started_at = task.ended_at = Time.zone.now
|
|
17
17
|
task.save
|
|
18
18
|
end,
|
|
19
|
-
|
|
19
|
+
FactoryGirl.create(:dynflow_task, :product_create_task)]
|
|
20
20
|
cleaner.expects(:tasks_to_csv)
|
|
21
21
|
cleaner.delete
|
|
22
22
|
ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
|
|
@@ -31,13 +31,13 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
31
31
|
|
|
32
32
|
it 'deletes all tasks matching the filter when the time limit is not specified' do
|
|
33
33
|
cleaner = ForemanTasks::Cleaner.new(:filter => 'label = "Actions::User::Create"')
|
|
34
|
-
tasks_to_delete = [
|
|
35
|
-
|
|
34
|
+
tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task),
|
|
35
|
+
FactoryGirl.create(:dynflow_task, :user_create_task) do |task|
|
|
36
36
|
task.started_at = task.ended_at = Time.zone.now
|
|
37
37
|
task.save
|
|
38
38
|
end]
|
|
39
39
|
|
|
40
|
-
tasks_to_keep = [
|
|
40
|
+
tasks_to_keep = [FactoryGirl.create(:dynflow_task, :product_create_task)]
|
|
41
41
|
cleaner.expects(:tasks_to_csv)
|
|
42
42
|
cleaner.delete
|
|
43
43
|
ForemanTasks::Task.where(id: tasks_to_delete).must_be_empty
|
|
@@ -46,10 +46,10 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
46
46
|
|
|
47
47
|
it 'supports passing empty filter (just delete all)' do
|
|
48
48
|
cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d')
|
|
49
|
-
tasks_to_delete = [
|
|
50
|
-
|
|
49
|
+
tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task),
|
|
50
|
+
FactoryGirl.create(:dynflow_task, :product_create_task)]
|
|
51
51
|
|
|
52
|
-
tasks_to_keep = [
|
|
52
|
+
tasks_to_keep = [FactoryGirl.create(:dynflow_task, :user_create_task) do |task|
|
|
53
53
|
task.started_at = task.ended_at = Time.zone.now
|
|
54
54
|
task.save
|
|
55
55
|
end]
|
|
@@ -62,8 +62,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
62
62
|
it 'backs tasks up before deleting' do
|
|
63
63
|
dir = '/tmp'
|
|
64
64
|
cleaner = ForemanTasks::Cleaner.new(:filter => '', :after => '10d', :backup_dir => dir)
|
|
65
|
-
tasks_to_delete = [
|
|
66
|
-
|
|
65
|
+
tasks_to_delete = [FactoryGirl.create(:dynflow_task, :user_create_task),
|
|
66
|
+
FactoryGirl.create(:dynflow_task, :product_create_task)]
|
|
67
67
|
|
|
68
68
|
r, w = IO.pipe
|
|
69
69
|
cleaner.expects(:with_backup_file)
|
|
@@ -8,8 +8,8 @@ module ForemanTasks
|
|
|
8
8
|
User.current = User.where(:login => 'apiadmin').first
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
let(:own_task) {
|
|
12
|
-
let(:foreign_task) {
|
|
11
|
+
let(:own_task) { FactoryGirl.create(:dynflow_task, :set_owner => user) }
|
|
12
|
+
let(:foreign_task) { FactoryGirl.create(:dynflow_task) }
|
|
13
13
|
|
|
14
14
|
let(:edit_foreman_tasks_permission) do
|
|
15
15
|
Permission.where(:name => :edit_foreman_tasks).first
|
|
@@ -24,7 +24,7 @@ module ForemanTasks
|
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
describe 'admin user' do
|
|
27
|
-
let(:user) {
|
|
27
|
+
let(:user) { FactoryGirl.create(:user, :admin) }
|
|
28
28
|
it 'can see all tasks' do
|
|
29
29
|
assert dynflow_console_authorized?
|
|
30
30
|
assert dynflow_console_authorized?(own_task)
|
|
@@ -34,9 +34,9 @@ module ForemanTasks
|
|
|
34
34
|
|
|
35
35
|
describe 'user with unlimited edit_foreman_tasks permissions' do
|
|
36
36
|
let(:user) do
|
|
37
|
-
user_role =
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
user_role = FactoryGirl.create(:user_user_role)
|
|
38
|
+
FactoryGirl.create(:filter,
|
|
39
|
+
:role => user_role.role, :permissions => [edit_foreman_tasks_permission])
|
|
40
40
|
user_role.owner
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -49,10 +49,10 @@ module ForemanTasks
|
|
|
49
49
|
|
|
50
50
|
describe 'user with limited edit_foreman_tasks permissions' do
|
|
51
51
|
let(:user) do
|
|
52
|
-
user_role =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
user_role = FactoryGirl.create(:user_user_role)
|
|
53
|
+
FactoryGirl.create(:filter,
|
|
54
|
+
:search => 'owner.id = current_user',
|
|
55
|
+
:role => user_role.role, :permissions => [edit_foreman_tasks_permission])
|
|
56
56
|
user_role.owner
|
|
57
57
|
end
|
|
58
58
|
|
|
@@ -64,7 +64,7 @@ module ForemanTasks
|
|
|
64
64
|
end
|
|
65
65
|
|
|
66
66
|
describe 'user without edit_foreman_tasks permissions' do
|
|
67
|
-
let(:user) {
|
|
67
|
+
let(:user) { FactoryGirl.create(:user) }
|
|
68
68
|
it 'can not see any tasks' do
|
|
69
69
|
refute dynflow_console_authorized?
|
|
70
70
|
refute dynflow_console_authorized?(own_task)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require 'ostruct'
|
|
2
|
+
require 'foreman_tasks_test_helper'
|
|
3
|
+
|
|
4
|
+
module ForemanTasks
|
|
5
|
+
class LockTest < ::ActiveSupport::TestCase
|
|
6
|
+
describe ::ForemanTasks::Lock::LockConflict do
|
|
7
|
+
class FakeLockConflict < ForemanTasks::Lock::LockConflict
|
|
8
|
+
def _(val)
|
|
9
|
+
val.freeze
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'does not modify frozen strings' do
|
|
14
|
+
required_lock = OpenStruct.new(:name => 'my_lock')
|
|
15
|
+
# Before #21770 the next line would raise
|
|
16
|
+
# RuntimeError: can't modify frozen String
|
|
17
|
+
conflict = FakeLockConflict.new(required_lock, [])
|
|
18
|
+
assert conflict._('this should be frozen').frozen?
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -12,7 +12,7 @@ describe ForemanTasks::ProxySelector do
|
|
|
12
12
|
count = 3
|
|
13
13
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).raises
|
|
14
14
|
.then.times(count - 1).returns(0)
|
|
15
|
-
proxies =
|
|
15
|
+
proxies = FactoryGirl.create_list(:smart_proxy, count)
|
|
16
16
|
|
|
17
17
|
available = proxies.reduce([]) do |found, _|
|
|
18
18
|
found << proxy_selector.select_by_jobs_count(proxies)
|
|
@@ -40,14 +40,14 @@ describe ForemanTasks::ProxySelector do
|
|
|
40
40
|
count = 3
|
|
41
41
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).times(count).raises
|
|
42
42
|
proxy_selector.stubs(:available_proxies =>
|
|
43
|
-
{ :global =>
|
|
43
|
+
{ :global => FactoryGirl.create_list(:smart_proxy, count) })
|
|
44
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
|
|
48
48
|
ProxyAPI::ForemanDynflow::DynflowProxy.any_instance.expects(:tasks_count).returns(0)
|
|
49
|
-
fallback_proxy =
|
|
50
|
-
global_proxy =
|
|
49
|
+
fallback_proxy = FactoryGirl.build(:smart_proxy)
|
|
50
|
+
global_proxy = FactoryGirl.build(:smart_proxy)
|
|
51
51
|
ForemanTasks::ProxySelector.any_instance.stubs(:available_proxies =>
|
|
52
52
|
{ :fallback => [fallback_proxy],
|
|
53
53
|
:global => [global_proxy] })
|
|
@@ -89,14 +89,14 @@ class RecurringLogicsTest < ActiveSupport::TestCase
|
|
|
89
89
|
end
|
|
90
90
|
|
|
91
91
|
it 'can be created from triggering' do
|
|
92
|
-
triggering =
|
|
92
|
+
triggering = FactoryGirl.build(:triggering, :recurring, :end_time_limited)
|
|
93
93
|
logic = ForemanTasks::RecurringLogic.new_from_triggering(triggering)
|
|
94
94
|
# Mysql coerces the times a bit
|
|
95
95
|
logic.end_time.must_be_close_to(triggering.end_time, 1.second)
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
describe 'validation' do
|
|
99
|
-
let(:logic) {
|
|
99
|
+
let(:logic) { FactoryGirl.build(:recurring_logic) }
|
|
100
100
|
|
|
101
101
|
it 'is valid by default' do
|
|
102
102
|
logic.must_be :valid?
|
data/test/unit/task_test.rb
CHANGED
|
@@ -4,11 +4,11 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
4
4
|
describe 'filtering by current user' do
|
|
5
5
|
before do
|
|
6
6
|
@original_current_user = User.current
|
|
7
|
-
@user_one =
|
|
8
|
-
@user_two =
|
|
7
|
+
@user_one = FactoryGirl.create(:user)
|
|
8
|
+
@user_two = FactoryGirl.create(:user)
|
|
9
9
|
|
|
10
|
-
@task_one =
|
|
11
|
-
|
|
10
|
+
@task_one = FactoryGirl.create(:some_task, :set_owner => @user_one)
|
|
11
|
+
FactoryGirl.create(:some_task, :set_owner => @user_two)
|
|
12
12
|
|
|
13
13
|
User.current = @user_one
|
|
14
14
|
end
|
|
@@ -25,16 +25,16 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
25
25
|
|
|
26
26
|
describe 'authorization filtering' do
|
|
27
27
|
it 'can filter by the task subject' do
|
|
28
|
-
user_role =
|
|
28
|
+
user_role = FactoryGirl.create(:user_user_role)
|
|
29
29
|
user = user_role.owner
|
|
30
30
|
role = user_role.role
|
|
31
|
-
permission =
|
|
31
|
+
permission = FactoryGirl.build(:permission)
|
|
32
32
|
permission.resource_type = 'ForemanTasks::Task'
|
|
33
33
|
permission.save!
|
|
34
|
-
|
|
34
|
+
FactoryGirl.create(:filter, :role => role, :permissions => [permission])
|
|
35
35
|
|
|
36
36
|
User.current = user
|
|
37
|
-
task =
|
|
37
|
+
task = FactoryGirl.create(:dynflow_task)
|
|
38
38
|
|
|
39
39
|
auth = Authorizer.new(user)
|
|
40
40
|
assert auth.can?(permission.name.to_sym, task)
|
|
@@ -42,8 +42,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
42
42
|
end
|
|
43
43
|
|
|
44
44
|
describe 'consistency check' do
|
|
45
|
-
let(:consistent_task) {
|
|
46
|
-
let(:inconsistent_task) {
|
|
45
|
+
let(:consistent_task) { FactoryGirl.create(:dynflow_task, :sync_with_dynflow => true) }
|
|
46
|
+
let(:inconsistent_task) { FactoryGirl.create(:dynflow_task, :inconsistent_dynflow_task) }
|
|
47
47
|
|
|
48
48
|
it 'ensures the tasks marked as running are really running in Dynflow' do
|
|
49
49
|
running_task_count = ForemanTasks::Task::DynflowTask.running.count
|
|
@@ -60,7 +60,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
60
60
|
|
|
61
61
|
describe 'task without valid execution plan' do
|
|
62
62
|
let(:task) do
|
|
63
|
-
|
|
63
|
+
FactoryGirl.create(:dynflow_task).tap do |task|
|
|
64
64
|
task.external_id = 'missing-task'
|
|
65
65
|
end
|
|
66
66
|
end
|
|
@@ -86,7 +86,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
86
86
|
:pending => 0
|
|
87
87
|
}
|
|
88
88
|
end
|
|
89
|
-
let(:task) {
|
|
89
|
+
let(:task) { FactoryGirl.create(:dynflow_task) }
|
|
90
90
|
|
|
91
91
|
describe 'without sub tasks' do
|
|
92
92
|
it 'calculates the progress report correctly' do
|
|
@@ -95,8 +95,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
95
95
|
end
|
|
96
96
|
|
|
97
97
|
describe 'with sub tasks' do
|
|
98
|
-
let(:failed) {
|
|
99
|
-
let(:success) {
|
|
98
|
+
let(:failed) { FactoryGirl.create(:dynflow_task).tap { |t| t.result = :error } }
|
|
99
|
+
let(:success) { FactoryGirl.create(:dynflow_task).tap { |t| t.result = :success } }
|
|
100
100
|
before { task.sub_tasks = [success, failed] }
|
|
101
101
|
|
|
102
102
|
it 'calculate the progress report correctly' do
|
|
@@ -121,8 +121,8 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
121
121
|
end
|
|
122
122
|
|
|
123
123
|
describe 'recurring task' do
|
|
124
|
-
let(:logic) {
|
|
125
|
-
let(:task) {
|
|
124
|
+
let(:logic) { FactoryGirl.build(:recurring_logic) }
|
|
125
|
+
let(:task) { FactoryGirl.create(:some_task) }
|
|
126
126
|
|
|
127
127
|
it 'can indicate it is recurring' do
|
|
128
128
|
refute task.recurring?
|
|
@@ -133,7 +133,7 @@ class TasksTest < ActiveSupport::TestCase
|
|
|
133
133
|
end
|
|
134
134
|
|
|
135
135
|
describe 'delayed task' do
|
|
136
|
-
let(:task) {
|
|
136
|
+
let(:task) { FactoryGirl.create(:some_task) }
|
|
137
137
|
|
|
138
138
|
it 'can indicate it is delayed' do
|
|
139
139
|
refute task.delayed?
|
|
@@ -3,18 +3,18 @@ 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
|
-
|
|
6
|
+
FactoryGirl.build(:triggering).must_be :valid?
|
|
7
7
|
end
|
|
8
8
|
|
|
9
9
|
it 'is validates future execution' do
|
|
10
|
-
triggering =
|
|
10
|
+
triggering = FactoryGirl.build(:triggering, :future)
|
|
11
11
|
triggering.must_be :valid?
|
|
12
12
|
triggering.start_before = triggering.start_at - 120
|
|
13
13
|
triggering.wont_be :valid?
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
it 'is invalid when recurring logic is invalid' do
|
|
17
|
-
triggering =
|
|
17
|
+
triggering = FactoryGirl.build(:triggering, :recurring)
|
|
18
18
|
triggering.must_be :valid?
|
|
19
19
|
triggering.recurring_logic.stubs(:valid?).returns(false)
|
|
20
20
|
triggering.wont_be :valid?
|
|
@@ -22,7 +22,7 @@ class TriggeringTest < ActiveSupport::TestCase
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
it 'cannot have mode set to arbitrary value' do
|
|
25
|
-
triggering =
|
|
25
|
+
triggering = FactoryGirl.build(:triggering)
|
|
26
26
|
triggering.must_be :valid?
|
|
27
27
|
proc { triggering.mode = 'bogus' }.must_raise ArgumentError
|
|
28
28
|
proc { triggering.mode = 27 }.must_raise ArgumentError
|
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.10.
|
|
4
|
+
version: 0.10.9
|
|
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:
|
|
11
|
+
date: 2018-01-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: foreman-tasks-core
|
|
@@ -80,20 +80,6 @@ dependencies:
|
|
|
80
80
|
- - ">="
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
82
|
version: '0'
|
|
83
|
-
- !ruby/object:Gem::Dependency
|
|
84
|
-
name: factory_bot_rails
|
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
|
86
|
-
requirements:
|
|
87
|
-
- - "~>"
|
|
88
|
-
- !ruby/object:Gem::Version
|
|
89
|
-
version: 4.8.0
|
|
90
|
-
type: :development
|
|
91
|
-
prerelease: false
|
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
93
|
-
requirements:
|
|
94
|
-
- - "~>"
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: 4.8.0
|
|
97
83
|
description: |
|
|
98
84
|
The goal of this plugin is to unify the way of showing task statuses across the Foreman instance.
|
|
99
85
|
It defines Task model for keeping the information about the tasks and Lock for assigning the tasks
|
|
@@ -246,6 +232,7 @@ files:
|
|
|
246
232
|
- test/unit/cleaner_test.rb
|
|
247
233
|
- test/unit/config/environment.rb
|
|
248
234
|
- test/unit/dynflow_console_authorizer_test.rb
|
|
235
|
+
- test/unit/lock_test.rb
|
|
249
236
|
- test/unit/otp_manager_test.rb
|
|
250
237
|
- test/unit/proxy_selector_test.rb
|
|
251
238
|
- test/unit/recurring_logic_test.rb
|
|
@@ -292,6 +279,7 @@ test_files:
|
|
|
292
279
|
- test/unit/cleaner_test.rb
|
|
293
280
|
- test/unit/config/environment.rb
|
|
294
281
|
- test/unit/dynflow_console_authorizer_test.rb
|
|
282
|
+
- test/unit/lock_test.rb
|
|
295
283
|
- test/unit/otp_manager_test.rb
|
|
296
284
|
- test/unit/proxy_selector_test.rb
|
|
297
285
|
- test/unit/recurring_logic_test.rb
|