Skip to content

Commit

Permalink
fixes #9404 - fix sync_plan add/del product action getting stuck
Browse files Browse the repository at this point in the history
and dynflowing that action properly
  • Loading branch information
jlsherrill committed Feb 19, 2015
1 parent 546cb7e commit cf738d8
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
4 changes: 2 additions & 2 deletions app/controllers/katello/api/v2/sync_plans_controller.rb
Expand Up @@ -123,7 +123,7 @@ def add_products
ids = params[:product_ids]
@products = Product.where(:id => ids).editable
@sync_plan.product_ids = (@sync_plan.product_ids + @products.collect { |p| p.id }).uniq
@sync_plan.save!
sync_task(::Actions::Katello::SyncPlan::UpdateProducts, @sync_plan)
respond_for_show
end

Expand All @@ -134,7 +134,7 @@ def remove_products
ids = params[:product_ids]
@products = Product.where(:id => ids).editable
@sync_plan.product_ids = (@sync_plan.product_ids - @products.collect { |p| p.id }).uniq
@sync_plan.save!
sync_task(::Actions::Katello::SyncPlan::UpdateProducts, @sync_plan)
respond_for_show
end

Expand Down
31 changes: 31 additions & 0 deletions app/lib/actions/katello/sync_plan/update_products.rb
@@ -0,0 +1,31 @@
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

module Actions
module Katello
module SyncPlan
class UpdateProducts < Actions::EntryAction
def plan(sync_plan)
action_subject(sync_plan)
sync_plan.save!
sync_plan.products.each do |product|
plan_action(::Actions::Katello::Product::Update, product, :sync_plan_id => sync_plan.id)
end
end

def humanized_name
_("Update Sync Plan Products")
end
end
end
end
end
10 changes: 1 addition & 9 deletions app/models/katello/sync_plan.rb
Expand Up @@ -18,6 +18,7 @@ class SyncPlan < Katello::Model

include Glue
include Katello::Authorization::SyncPlan
include ForemanTasks::Concerns::ActionSubject

HOURLY = 'hourly'
DAILY = 'daily'
Expand All @@ -36,20 +37,11 @@ class SyncPlan < Katello::Model
validate :validate_sync_date
validates_with Validators::KatelloNameFormatValidator, :attributes => :name

before_save :reassign_sync_plan_to_products

scoped_search :on => :name, :complete_value => true
scoped_search :on => :organization_id, :complete_value => true
scoped_search :on => :interval, :complete_value => true
scoped_search :on => :enabled, :complete_value => true

def reassign_sync_plan_to_products
# triggers orchestration in products
self.products.each do |product|
::ForemanTasks.sync_task(::Actions::Katello::Product::Update, product, :sync_plan_id => self.id)
end
end

def validate_sync_date
errors.add :base, _("Start Date and Time can't be blank") if self.sync_date.nil?
end
Expand Down
39 changes: 39 additions & 0 deletions test/actions/katello/sync_plan_test.rb
@@ -0,0 +1,39 @@
#
# Copyright 2014 Red Hat, Inc.
#
# This software is licensed to you under the GNU General Public
# License as published by the Free Software Foundation; either version
# 2 of the License (GPLv2) or (at your option) any later version.
# There is NO WARRANTY for this software, express or implied,
# including the implied warranties of MERCHANTABILITY,
# NON-INFRINGEMENT, or FITNESS FOR A PARTICULAR PURPOSE. You should
# have received a copy of GPLv2 along with this software; if not, see
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.

require 'katello_test_helper'

module ::Actions::Katello::SyncPlan
class TestBase < ActiveSupport::TestCase
include Dynflow::Testing
include Support::Actions::RemoteAction
include Support::Actions::Fixtures
include FactoryGirl::Syntax::Methods

let(:action) { create_action action_class }
let(:sync_plan) { Katello::SyncPlan.find(katello_sync_plans(:sync_plan_hourly)) }
let(:product) { Katello::Product.find(katello_products(:redhat)) }
end

class CreateTest < TestBase
let(:action_class) { ::Actions::Katello::SyncPlan::UpdateProducts }

it 'plans' do
sync_plan.expects(:save!)
action.expects(:action_subject)
sync_plan.products << product

plan_action action, sync_plan
assert_action_planed_with(action, ::Actions::Katello::Product::Update, product, :sync_plan_id => sync_plan.id)
end
end
end
9 changes: 2 additions & 7 deletions test/controllers/api/v2/sync_plans_controller_test.rb
Expand Up @@ -25,7 +25,7 @@ def self.before_suite

def models
@organization = get_organization
@sync_plan = katello_sync_plans(:sync_plan_hourly)
@sync_plan = Katello::SyncPlan.find(katello_sync_plans(:sync_plan_hourly))
@products = katello_products(:fedora, :redhat, :empty_product)
end

Expand Down Expand Up @@ -148,12 +148,7 @@ def test_available_products_protected
end

def test_add_products
@products.each do |product|
::ForemanTasks.expects(:sync_task).
with(::Actions::Katello::Product::Update,
product,
:sync_plan_id => @sync_plan.id)
end
::ForemanTasks.expects(:sync_task).with(::Actions::Katello::SyncPlan::UpdateProducts, @sync_plan)

put :add_products, :id => @sync_plan.id, :organization_id => @organization.id,
:product_ids => @products.collect { |p| p.id }
Expand Down

0 comments on commit cf738d8

Please sign in to comment.