foreman-tasks 0.9.1 → 0.9.2
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/Gemfile +2 -1
- data/app/helpers/foreman_tasks/foreman_tasks_helper.rb +1 -1
- data/app/lib/actions/bulk_action.rb +0 -1
- data/app/lib/actions/middleware/keep_current_user.rb +1 -1
- data/app/models/foreman_tasks/concerns/action_triggering.rb +7 -7
- data/app/models/foreman_tasks/task.rb +7 -5
- data/app/models/foreman_tasks/task/dynflow_task.rb +40 -12
- data/app/views/foreman_tasks/tasks/_errors.html.erb +5 -1
- data/bin/dynflow-executor +53 -28
- data/deploy/foreman-tasks.sysconfig +12 -0
- data/foreman-tasks.gemspec +2 -1
- data/lib/foreman_tasks/dynflow.rb +10 -2
- data/lib/foreman_tasks/dynflow/daemon.rb +90 -19
- data/lib/foreman_tasks/version.rb +1 -1
- data/locale/en/LC_MESSAGES/foreman_tasks.mo +0 -0
- data/locale/en/foreman_tasks.po +6 -9
- data/locale/foreman_tasks.pot +102 -107
- data/test/unit/actions/action_with_sub_plans_test.rb +1 -3
- data/test/unit/config/environment.rb +1 -0
- data/test/unit/daemon_test.rb +86 -0
- data/test/unit/task_test.rb +19 -1
- metadata +24 -5
| @@ -9,9 +9,7 @@ module ForemanTasks | |
| 9 9 | 
             
                end
         | 
| 10 10 |  | 
| 11 11 | 
             
                # to be able to use the locking
         | 
| 12 | 
            -
                 | 
| 13 | 
            -
                  include ForemanTasks::Concerns::ActionSubject
         | 
| 14 | 
            -
                end
         | 
| 12 | 
            +
                ::User.send(:include, ForemanTasks::Concerns::ActionSubject)
         | 
| 15 13 |  | 
| 16 14 | 
             
                class ParentAction < Actions::ActionWithSubPlans
         | 
| 17 15 | 
             
                  def plan(user)
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            # dummy appllication.rb - for unit testing dynflow-executor
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            require 'test_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            class DaemonTest < ActiveSupport::TestCase
         | 
| 4 | 
            +
              setup do
         | 
| 5 | 
            +
                @dynflow_memory_watcher = mock('memory_watcher')
         | 
| 6 | 
            +
                @daemons = mock('daemons')
         | 
| 7 | 
            +
                @daemon = ForemanTasks::Dynflow::Daemon.new(
         | 
| 8 | 
            +
                  @dynflow_memory_watcher,
         | 
| 9 | 
            +
                  @daemons
         | 
| 10 | 
            +
                )
         | 
| 11 | 
            +
                @world_class = mock('dummy world factory')
         | 
| 12 | 
            +
                @dummy_world = Dynflow::Testing::DummyWorld.new
         | 
| 13 | 
            +
                @dummy_world.stubs(:auto_execute)
         | 
| 14 | 
            +
                @dummy_world.stubs(:terminated).returns(Concurrent.event)
         | 
| 15 | 
            +
                @world_class.stubs(:new).returns(@dummy_world)
         | 
| 16 | 
            +
                @dynflow = ForemanTasks::Dynflow.new(@world_class)
         | 
| 17 | 
            +
                ForemanTasks.stubs(:dynflow).returns(@dynflow)
         | 
| 18 | 
            +
                @dynflow.require!
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
              test 'run command creates a watcher if memory_limit option specified' do
         | 
| 22 | 
            +
                current_folder = File.expand_path('../', __FILE__)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                @dynflow_memory_watcher.expects(:new).with do |_world, memory_limit, _watcher_options|
         | 
| 25 | 
            +
                  memory_limit == 1000
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
                @daemon.stubs(:sleep).returns(true) # don't pause the execution
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                @daemon.run(current_folder, memory_limit: 1000)
         | 
| 30 | 
            +
                # initialization should be performed inside the foreman environment,
         | 
| 31 | 
            +
                # which is mocked here
         | 
| 32 | 
            +
                @dynflow.initialize!
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              test 'run command sets parameters to watcher' do
         | 
| 36 | 
            +
                current_folder = File.expand_path('../', __FILE__)
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                @dynflow_memory_watcher.expects(:new).with do |_world, memory_limit, watcher_options|
         | 
| 39 | 
            +
                  memory_limit == 1000 &&
         | 
| 40 | 
            +
                    watcher_options[:polling_interval] == 100 &&
         | 
| 41 | 
            +
                    watcher_options[:initial_wait] == 200
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
                @daemon.stubs(:sleep).returns(true) # don't pause the execution
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                @daemon.run(
         | 
| 46 | 
            +
                  current_folder,
         | 
| 47 | 
            +
                  memory_limit: 1000,
         | 
| 48 | 
            +
                  memory_polling_interval: 100,
         | 
| 49 | 
            +
                  memory_init_delay: 200
         | 
| 50 | 
            +
                )
         | 
| 51 | 
            +
                # initialization should be performed inside the foreman environment,
         | 
| 52 | 
            +
                # which is mocked here
         | 
| 53 | 
            +
                @dynflow.initialize!
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
              test 'run_background command executes run with all params set as a daemon' do
         | 
| 57 | 
            +
                @daemon.expects(:run).twice.with do |_folder, options|
         | 
| 58 | 
            +
                  options[:memory_limit] == 1000 &&
         | 
| 59 | 
            +
                    options[:memory_init_delay] == 100 &&
         | 
| 60 | 
            +
                    options[:memory_polling_interval] == 200
         | 
| 61 | 
            +
                end
         | 
| 62 | 
            +
                @daemons.expects(:run_proc).twice.yields
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                @daemon.run_background(
         | 
| 65 | 
            +
                  'start',
         | 
| 66 | 
            +
                  executors_count: 2,
         | 
| 67 | 
            +
                  memory_limit: 1000,
         | 
| 68 | 
            +
                  memory_init_delay: 100,
         | 
| 69 | 
            +
                  memory_polling_interval: 200
         | 
| 70 | 
            +
                )
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              test 'default options read values from ENV' do
         | 
| 74 | 
            +
                ENV['EXECUTORS_COUNT'] = '2'
         | 
| 75 | 
            +
                ENV['EXECUTOR_MEMORY_LIMIT'] = '1gb'
         | 
| 76 | 
            +
                ENV['EXECUTOR_MEMORY_MONITOR_DELAY'] = '3'
         | 
| 77 | 
            +
                ENV['EXECUTOR_MEMORY_MONITOR_INTERVAL'] = '4'
         | 
| 78 | 
            +
             | 
| 79 | 
            +
                actual = @daemon.send(:default_options)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                assert_equal 2, actual[:executors_count]
         | 
| 82 | 
            +
                assert_equal 1.gigabytes, actual[:memory_limit]
         | 
| 83 | 
            +
                assert_equal 3, actual[:memory_init_delay]
         | 
| 84 | 
            +
                assert_equal 4, actual[:memory_polling_interval]
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
            end
         | 
    
        data/test/unit/task_test.rb
    CHANGED
    
    | @@ -52,6 +52,23 @@ class TasksTest < ActiveSupport::TestCase | |
| 52 52 | 
             
                end
         | 
| 53 53 | 
             
              end
         | 
| 54 54 |  | 
| 55 | 
            +
              describe 'task without valid execution plan' do
         | 
| 56 | 
            +
                let(:task) do
         | 
| 57 | 
            +
                  FactoryGirl.create(:dynflow_task).tap do |task|
         | 
| 58 | 
            +
                    task.external_id = 'missing-task'
         | 
| 59 | 
            +
                  end
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                it 'handles the error while loading the task and does not propagate errors unless necessary' do
         | 
| 63 | 
            +
                  task.cancellable?
         | 
| 64 | 
            +
                  task.resumable?
         | 
| 65 | 
            +
                  task.main_action
         | 
| 66 | 
            +
                  assert_equal 'Support::DummyDynflowAction', task.get_humanized(:humanized_name)
         | 
| 67 | 
            +
                  assert_equal 0, task.progress
         | 
| 68 | 
            +
                  assert_raises(KeyError) { task.cancel }
         | 
| 69 | 
            +
                end
         | 
| 70 | 
            +
              end
         | 
| 71 | 
            +
             | 
| 55 72 | 
             
              describe 'subtask count querying' do
         | 
| 56 73 | 
             
                let(:result_base) do
         | 
| 57 74 | 
             
                  {
         | 
| @@ -82,7 +99,8 @@ class TasksTest < ActiveSupport::TestCase | |
| 82 99 | 
             
                  end
         | 
| 83 100 |  | 
| 84 101 | 
             
                  it 'calculates the progress report correctly when using batch planning' do
         | 
| 85 | 
            -
                     | 
| 102 | 
            +
                    # rubocop:disable Style/RedundantSelf - not redundant, as otherwise it conflicts with local variable
         | 
| 103 | 
            +
                    result_base = self.result_base.merge(:success => 1, :error => 1, :total => 25)
         | 
| 86 104 | 
             
                    fake_action = OpenStruct.new(:total_count => 25)
         | 
| 87 105 | 
             
                    task.stubs(:main_action).returns(fake_action)
         | 
| 88 106 |  | 
    
        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.9. | 
| 4 | 
            +
              version: 0.9.2
         | 
| 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: 2017- | 
| 11 | 
            +
            date: 2017-05-30 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. | 
| 33 | 
            +
                    version: 0.8.24
         | 
| 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. | 
| 40 | 
            +
                    version: 0.8.24
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: sequel
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -94,6 +94,20 @@ dependencies: | |
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: 0.1.4
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: get_process_mem
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - ">="
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: '0'
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - ">="
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: '0'
         | 
| 97 111 | 
             
            description: |
         | 
| 98 112 | 
             
              The goal of this plugin is to unify the way of showing task statuses across the Foreman instance.
         | 
| 99 113 | 
             
              It defines Task model for keeping the information about the tasks and Lock for assigning the tasks
         | 
| @@ -228,6 +242,7 @@ files: | |
| 228 242 | 
             
            - lib/tasks/gettext.rake
         | 
| 229 243 | 
             
            - locale/Makefile
         | 
| 230 244 | 
             
            - locale/action_names.rb
         | 
| 245 | 
            +
            - locale/en/LC_MESSAGES/foreman_tasks.mo
         | 
| 231 246 | 
             
            - locale/en/foreman_tasks.po
         | 
| 232 247 | 
             
            - locale/foreman_tasks.pot
         | 
| 233 248 | 
             
            - script/rails
         | 
| @@ -243,6 +258,8 @@ files: | |
| 243 258 | 
             
            - test/unit/actions/action_with_sub_plans_test.rb
         | 
| 244 259 | 
             
            - test/unit/actions/proxy_action_test.rb
         | 
| 245 260 | 
             
            - test/unit/cleaner_test.rb
         | 
| 261 | 
            +
            - test/unit/config/environment.rb
         | 
| 262 | 
            +
            - test/unit/daemon_test.rb
         | 
| 246 263 | 
             
            - test/unit/dynflow_console_authorizer_test.rb
         | 
| 247 264 | 
             
            - test/unit/proxy_selector_test.rb
         | 
| 248 265 | 
             
            - test/unit/recurring_logic_test.rb
         | 
| @@ -268,7 +285,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 268 285 | 
             
                  version: '0'
         | 
| 269 286 | 
             
            requirements: []
         | 
| 270 287 | 
             
            rubyforge_project: 
         | 
| 271 | 
            -
            rubygems_version: 2.5 | 
| 288 | 
            +
            rubygems_version: 2.4.5
         | 
| 272 289 | 
             
            signing_key: 
         | 
| 273 290 | 
             
            specification_version: 4
         | 
| 274 291 | 
             
            summary: Foreman plugin for showing tasks information for resoruces and users
         | 
| @@ -285,6 +302,8 @@ test_files: | |
| 285 302 | 
             
            - test/unit/actions/action_with_sub_plans_test.rb
         | 
| 286 303 | 
             
            - test/unit/actions/proxy_action_test.rb
         | 
| 287 304 | 
             
            - test/unit/cleaner_test.rb
         | 
| 305 | 
            +
            - test/unit/config/environment.rb
         | 
| 306 | 
            +
            - test/unit/daemon_test.rb
         | 
| 288 307 | 
             
            - test/unit/dynflow_console_authorizer_test.rb
         | 
| 289 308 | 
             
            - test/unit/proxy_selector_test.rb
         | 
| 290 309 | 
             
            - test/unit/recurring_logic_test.rb
         |