From b87fe18a41f660f0946ca20be0732bc2fc93faa2 Mon Sep 17 00:00:00 2001 From: Stephen Benjamin Date: Wed, 11 Mar 2015 14:59:08 +0100 Subject: [PATCH] Make foreman-tasks a hard requirement --- .../foreman_salt/api/v2/jobs_controller.rb | 10 ++---- app/lib/actions/foreman_salt/report_import.rb | 32 +++++++++---------- foreman_salt.gemspec | 1 + lib/foreman_salt/engine.rb | 6 ++-- lib/foreman_salt/version.rb | 2 +- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/app/controllers/foreman_salt/api/v2/jobs_controller.rb b/app/controllers/foreman_salt/api/v2/jobs_controller.rb index faf0d47c..35e52f78 100644 --- a/app/controllers/foreman_salt/api/v2/jobs_controller.rb +++ b/app/controllers/foreman_salt/api/v2/jobs_controller.rb @@ -22,14 +22,8 @@ def upload Rails.logger.info("Processing job #{params[:job][:job_id]} from Salt.") case params[:job][:function] when 'state.highstate' - # Dynflowize the action if we can, otherwise we'll do it live - if defined? ForemanTasks - task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id)) - render :json => { :task_id => task.id } - else - reports = ForemanSalt::ReportImporter.import(params[:job][:result], detected_proxy.try(:id)) - render :json => { :message => "Imported #{reports.count} new reports." } - end + task = ForemanTasks.async_task(::Actions::ForemanSalt::ReportImport, params[:job], detected_proxy.try(:id)) + render :json => { :task_id => task.id } else render :json => { :message => 'Unsupported function' }, :status => :unprocessable_entity end diff --git a/app/lib/actions/foreman_salt/report_import.rb b/app/lib/actions/foreman_salt/report_import.rb index c2624932..5d761bf5 100644 --- a/app/lib/actions/foreman_salt/report_import.rb +++ b/app/lib/actions/foreman_salt/report_import.rb @@ -1,27 +1,25 @@ module Actions module ForemanSalt - if defined? ForemanTasks - class ReportImport < Actions::EntryAction - def resource_locks - :report_import - end + class ReportImport < Actions::EntryAction + def resource_locks + :report_import + end - def plan(job, proxy_id) - plan_self(:job_id => job[:job_id], :report => job[:result], :proxy_id => proxy_id) - end + def plan(job, proxy_id) + plan_self(:job_id => job[:job_id], :report => job[:result], :proxy_id => proxy_id) + end - def run - ::User.as_anonymous_admin do - reports = ::ForemanSalt::ReportImporter.import(input[:report], input[:proxy_id]) + def run + ::User.as_anonymous_admin do + reports = ::ForemanSalt::ReportImporter.import(input[:report], input[:proxy_id]) - output[:state] = { :message => "Imported #{reports.count} new reports" } - output[:hosts] = reports.map { |report| report.host.name } - end + output[:state] = { :message => "Imported #{reports.count} new reports" } + output[:hosts] = reports.map { |report| report.host.name } end + end - def humanized_name - _("Process Highstate Report: #{input[:job_id]}") - end + def humanized_name + _("Process Highstate Report: #{input[:job_id]}") end end end diff --git a/foreman_salt.gemspec b/foreman_salt.gemspec index 2a5350c2..1a07b847 100644 --- a/foreman_salt.gemspec +++ b/foreman_salt.gemspec @@ -14,4 +14,5 @@ Gem::Specification.new do |s| s.test_files = Dir['test/**/*'] s.add_dependency 'deface', '< 1.0' + s.add_dependency "foreman-tasks", '~> 0.6.9' end diff --git a/lib/foreman_salt/engine.rb b/lib/foreman_salt/engine.rb index 9ae24876..48f8fdeb 100644 --- a/lib/foreman_salt/engine.rb +++ b/lib/foreman_salt/engine.rb @@ -9,10 +9,8 @@ class Engine < ::Rails::Engine config.autoload_paths += Dir["#{config.root}/app/services"] config.autoload_paths += Dir["#{config.root}/app/lib"] - if defined? ForemanTasks - initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app| - ForemanTasks.dynflow.require! - end + initializer 'foreman_salt.require_dynflow', :before => 'foreman_tasks.initialize_dynflow' do |_app| + ForemanTasks.dynflow.require! end initializer 'foreman_salt.load_default_settings', :before => :load_config_initializers do diff --git a/lib/foreman_salt/version.rb b/lib/foreman_salt/version.rb index 01fe0be0..3a78150f 100644 --- a/lib/foreman_salt/version.rb +++ b/lib/foreman_salt/version.rb @@ -1,3 +1,3 @@ module ForemanSalt - VERSION = '2.0.1' + VERSION = '2.0.2' end