foreman-tasks 0.8.6 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +35 -0
  3. data/.rubocop_todo.yml +138 -0
  4. data/app/controllers/foreman_tasks/api/recurring_logics_controller.rb +3 -4
  5. data/app/controllers/foreman_tasks/api/tasks_controller.rb +56 -72
  6. data/app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb +2 -4
  7. data/app/controllers/foreman_tasks/recurring_logics_controller.rb +2 -5
  8. data/app/controllers/foreman_tasks/tasks_controller.rb +7 -8
  9. data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +44 -46
  10. data/app/helpers/foreman_tasks/tasks_helper.rb +1 -1
  11. data/app/lib/actions/action_with_sub_plans.rb +6 -8
  12. data/app/lib/actions/base.rb +6 -7
  13. data/app/lib/actions/bulk_action.rb +13 -9
  14. data/app/lib/actions/entry_action.rb +1 -3
  15. data/app/lib/actions/foreman/host/import_facts.rb +2 -5
  16. data/app/lib/actions/foreman/puppetclass/import.rb +1 -1
  17. data/app/lib/actions/helpers/args_serialization.rb +0 -1
  18. data/app/lib/actions/helpers/humanizer.rb +16 -21
  19. data/app/lib/actions/helpers/with_continuous_output.rb +0 -1
  20. data/app/lib/actions/helpers/with_delegated_action.rb +2 -2
  21. data/app/lib/actions/middleware/inherit_task_groups.rb +3 -5
  22. data/app/lib/actions/middleware/keep_current_user.rb +0 -3
  23. data/app/lib/actions/middleware/recurring_logic.rb +0 -1
  24. data/app/lib/actions/proxy_action.rb +8 -8
  25. data/app/lib/actions/serializers/active_record_serializer.rb +0 -3
  26. data/app/lib/proxy_api/foreman_dynflow/dynflow_proxy.rb +3 -3
  27. data/app/models/foreman_tasks/concerns/action_subject.rb +4 -6
  28. data/app/models/foreman_tasks/concerns/action_triggering.rb +20 -33
  29. data/app/models/foreman_tasks/concerns/host_action_subject.rb +5 -5
  30. data/app/models/foreman_tasks/lock.rb +29 -37
  31. data/app/models/foreman_tasks/recurring_logic.rb +23 -24
  32. data/app/models/foreman_tasks/task.rb +65 -39
  33. data/app/models/foreman_tasks/task/dynflow_task.rb +23 -24
  34. data/app/models/foreman_tasks/task/status_explicator.rb +3 -3
  35. data/app/models/foreman_tasks/task/summarizer.rb +3 -3
  36. data/app/models/foreman_tasks/task_group.rb +0 -2
  37. data/app/models/foreman_tasks/task_group_member.rb +0 -2
  38. data/app/models/foreman_tasks/task_groups/recurring_logic_task_group.rb +1 -4
  39. data/app/models/foreman_tasks/triggering.rb +19 -19
  40. data/app/models/setting/foreman_tasks.rb +8 -11
  41. data/app/services/foreman_tasks/proxy_selector.rb +4 -5
  42. data/app/views/foreman_tasks/tasks/_details.html.erb +1 -1
  43. data/bin/dynflow-executor +1 -1
  44. data/bin/foreman-tasks +1 -1
  45. data/config/routes.rb +1 -1
  46. data/db/migrate/20150814204140_add_task_type_value_index.rb +1 -1
  47. data/db/migrate/20160924213030_change_tasks_widget_names.rb +8 -8
  48. data/db/seeds.d/61-foreman_tasks_bookmarks.rb +3 -3
  49. data/deploy/foreman-tasks.sysconfig +6 -0
  50. data/extra/dynflow-debug.sh +12 -0
  51. data/foreman-tasks.gemspec +1 -1
  52. data/lib/foreman_tasks.rb +3 -3
  53. data/lib/foreman_tasks/authorizer_ext.rb +1 -1
  54. data/lib/foreman_tasks/cleaner.rb +14 -16
  55. data/lib/foreman_tasks/dynflow.rb +11 -9
  56. data/lib/foreman_tasks/dynflow/configuration.rb +8 -10
  57. data/lib/foreman_tasks/dynflow/console_authorizer.rb +4 -5
  58. data/lib/foreman_tasks/dynflow/daemon.rb +17 -19
  59. data/lib/foreman_tasks/dynflow/persistence.rb +5 -8
  60. data/lib/foreman_tasks/engine.rb +30 -31
  61. data/lib/foreman_tasks/task_error.rb +1 -3
  62. data/lib/foreman_tasks/tasks/cleanup.rake +7 -19
  63. data/lib/foreman_tasks/tasks/dynflow.rake +1 -1
  64. data/lib/foreman_tasks/tasks/export_tasks.rake +51 -59
  65. data/lib/foreman_tasks/test_extensions.rb +1 -1
  66. data/lib/foreman_tasks/version.rb +1 -1
  67. data/lib/tasks/gettext.rake +10 -7
  68. data/locale/action_names.rb +3 -6
  69. data/locale/en/foreman_tasks.po +189 -177
  70. data/locale/foreman_tasks.pot +177 -137
  71. data/test/controllers/api/recurring_logics_controller_test.rb +3 -5
  72. data/test/controllers/api/tasks_controller_test.rb +5 -7
  73. data/test/factories/task_factory.rb +8 -8
  74. data/test/factories/triggering_factory.rb +2 -3
  75. data/test/helpers/foreman_tasks/tasks_helper_test.rb +11 -11
  76. data/test/support/dummy_proxy_action.rb +3 -4
  77. data/test/unit/actions/action_with_sub_plans_test.rb +5 -6
  78. data/test/unit/actions/proxy_action_test.rb +5 -8
  79. data/test/unit/cleaner_test.rb +11 -12
  80. data/test/unit/dynflow_console_authorizer_test.rb +4 -4
  81. data/test/unit/proxy_selector_test.rb +3 -3
  82. data/test/unit/recurring_logic_test.rb +19 -17
  83. data/test/unit/task_groups_test.rb +3 -4
  84. data/test/unit/task_test.rb +72 -5
  85. data/test/unit/triggering_test.rb +0 -1
  86. metadata +7 -6
  87. data/app/controllers/foreman_tasks/concerns/environments_extension.rb +0 -24
@@ -1,4 +1,4 @@
1
- require "foreman_tasks_test_helper"
1
+ require 'foreman_tasks_test_helper'
2
2
 
3
3
  module ForemanTasks
4
4
  class TaskGroupsTest < ActiveSupport::TestCase
@@ -15,7 +15,6 @@ module ForemanTasks
15
15
  end
16
16
 
17
17
  class ParentAction < Actions::ActionWithSubPlans
18
-
19
18
  middleware.use ::Actions::Middleware::InheritTaskGroups
20
19
 
21
20
  def plan(count)
@@ -25,9 +24,9 @@ module ForemanTasks
25
24
  task.add_missing_task_groups(task_group)
26
25
  plan_self :count => count
27
26
  end
28
-
27
+
29
28
  def create_sub_plans
30
- input[:count].times.map { |i| trigger InheritingChildAction, i + 2 }
29
+ Array.new(input[:count]) { |i| trigger InheritingChildAction, i + 2 }
31
30
  end
32
31
  end
33
32
 
@@ -5,15 +5,15 @@ class TasksTest < ActiveSupport::TestCase
5
5
  before { @original_current_user = User.current }
6
6
  after { User.current = @original_current_user }
7
7
 
8
- test "can search the tasks by current_user" do
8
+ test 'can search the tasks by current_user' do
9
9
  user_one = FactoryGirl.create(:user)
10
10
  user_two = FactoryGirl.create(:user)
11
11
 
12
12
  task_one = FactoryGirl.create(:some_task, :set_owner => user_one)
13
- task_two = FactoryGirl.create(:some_task, :set_owner => user_two)
13
+ FactoryGirl.create(:some_task, :set_owner => user_two)
14
14
 
15
15
  User.current = user_one
16
- assert_equal [task_one], ForemanTasks::Task.search_for("owner.id = current_user")
16
+ assert_equal [task_one], ForemanTasks::Task.search_for('owner.id = current_user')
17
17
  end
18
18
  end
19
19
 
@@ -30,13 +30,12 @@ class TasksTest < ActiveSupport::TestCase
30
30
  User.current = user
31
31
  task = FactoryGirl.create(:dynflow_task)
32
32
 
33
- auth = Authorizer.new(user)
33
+ auth = Authorizer.new(user)
34
34
  assert auth.can?(permission.name.to_sym, task)
35
35
  end
36
36
  end
37
37
 
38
38
  describe 'consistency check' do
39
-
40
39
  let(:consistent_task) { FactoryGirl.create(:dynflow_task, :sync_with_dynflow => true) }
41
40
  let(:inconsistent_task) { FactoryGirl.create(:dynflow_task, :inconsistent_dynflow_task) }
42
41
 
@@ -52,4 +51,72 @@ class TasksTest < ActiveSupport::TestCase
52
51
  inconsistent_task.reload.state.must_equal 'planned'
53
52
  end
54
53
  end
54
+
55
+ describe 'subtask count querying' do
56
+ let(:result_base) do
57
+ {
58
+ :error => 0,
59
+ :warning => 0,
60
+ :total => 0,
61
+ :success => 0,
62
+ :cancelled => 0,
63
+ :pending => 0
64
+ }
65
+ end
66
+ let(:task) { FactoryGirl.create(:dynflow_task) }
67
+
68
+ describe 'without sub tasks' do
69
+ it 'calculates the progress report correctly' do
70
+ task.sub_tasks_counts.must_equal result_base
71
+ end
72
+ end
73
+
74
+ describe 'with sub tasks' do
75
+ let(:failed) { FactoryGirl.create(:dynflow_task).tap { |t| t.result = :error } }
76
+ let(:success) { FactoryGirl.create(:dynflow_task).tap { |t| t.result = :success } }
77
+ before { task.sub_tasks = [success, failed] }
78
+
79
+ it 'calculate the progress report correctly' do
80
+ expected_result = result_base.merge(:success => 1, :error => 1, :total => 2)
81
+ task.sub_tasks_counts.must_equal expected_result
82
+ end
83
+
84
+ it 'calculates the progress report correctly when using batch planning' do
85
+ result_base = result_base.merge(:success => 1, :error => 1, :total => 25)
86
+ fake_action = OpenStruct.new(:total_count => 25)
87
+ task.stubs(:main_action).returns(fake_action)
88
+
89
+ task.state = 'stopped'
90
+ expected_result = result_base.merge(:cancelled => 23)
91
+ task.sub_tasks_counts.must_equal expected_result
92
+
93
+ task.state = 'pending'
94
+ expected_result = result_base.merge(:pending => 23)
95
+ task.sub_tasks_counts.must_equal expected_result
96
+ end
97
+ end
98
+ end
99
+
100
+ describe 'recurring task' do
101
+ let(:logic) { FactoryGirl.build(:recurring_logic) }
102
+ let(:task) { FactoryGirl.create(:some_task) }
103
+
104
+ it 'can indicate it is recurring' do
105
+ refute task.recurring?
106
+ task.add_missing_task_groups(logic.task_group)
107
+ assert task.recurring?
108
+ end
109
+ end
110
+
111
+ describe 'delayed task' do
112
+ let(:task) { FactoryGirl.create(:some_task) }
113
+
114
+ it 'can indicate it is delayed' do
115
+ refute task.delayed?
116
+ task.execution_type.must_equal 'Immediate'
117
+ task.start_at = Time.now.utc + 100
118
+ assert task.delayed?
119
+ task.execution_type.must_equal 'Delayed'
120
+ end
121
+ end
55
122
  end
@@ -1,7 +1,6 @@
1
1
  require 'foreman_tasks_test_helper'
2
2
 
3
3
  class TriggeringTest < ActiveSupport::TestCase
4
-
5
4
  describe 'validation' do
6
5
  it 'is valid when immediate' do
7
6
  FactoryGirl.build(:triggering).must_be :valid?
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.8.6
4
+ version: 0.9.0
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: 2016-11-22 00:00:00.000000000 Z
11
+ date: 2017-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foreman-tasks-core
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.8.17
33
+ version: 0.8.22
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
- version: 0.8.17
40
+ version: 0.8.22
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sequel
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,8 @@ extra_rdoc_files:
108
108
  - LICENSE
109
109
  files:
110
110
  - ".gitignore"
111
+ - ".rubocop.yml"
112
+ - ".rubocop_todo.yml"
111
113
  - ".tx/config"
112
114
  - Gemfile
113
115
  - LICENSE
@@ -118,7 +120,6 @@ files:
118
120
  - app/assets/stylesheets/foreman_tasks/trigger_form.css
119
121
  - app/controllers/foreman_tasks/api/recurring_logics_controller.rb
120
122
  - app/controllers/foreman_tasks/api/tasks_controller.rb
121
- - app/controllers/foreman_tasks/concerns/environments_extension.rb
122
123
  - app/controllers/foreman_tasks/concerns/hosts_controller_extension.rb
123
124
  - app/controllers/foreman_tasks/concerns/parameters/triggering.rb
124
125
  - app/controllers/foreman_tasks/recurring_logics_controller.rb
@@ -267,7 +268,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
268
  version: '0'
268
269
  requirements: []
269
270
  rubyforge_project:
270
- rubygems_version: 2.4.5
271
+ rubygems_version: 2.5.1
271
272
  signing_key:
272
273
  specification_version: 4
273
274
  summary: Foreman plugin for showing tasks information for resoruces and users
@@ -1,24 +0,0 @@
1
- module ForemanTasks
2
- module Concerns
3
- module EnvironmentsExtension
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- alias_method_chain :obsolete_and_new, :dynflow
8
- end
9
-
10
- def obsolete_and_new_with_dynflow
11
- task = ForemanTasks.async_task(::Actions::Foreman::Puppetclass::Import,
12
- params)
13
-
14
- notice _("Added import task to queue, it will be run shortly")
15
- rescue ::Foreman::Exception => e
16
- error _("Failed to add task to queue: %s") % e.to_s
17
- ensure
18
- redirect_to :controller => controller_path
19
- end
20
-
21
- end
22
- end
23
- end
24
-