Skip to content

Commit

Permalink
fixes #8480 - Adds default setting for act key autoattach, BZ 1166889
Browse files Browse the repository at this point in the history
  • Loading branch information
cfouant authored and Vagrant User committed Dec 5, 2014
1 parent 1f935b9 commit 9b12978
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 18 deletions.
Expand Up @@ -69,7 +69,7 @@ def create
param :service_level, String, :desc => N_("service level")
param :auto_attach, :bool, :desc => N_("auto attach subscriptions upon registration")
def update
@activation_key.update_attributes!(activation_key_params)
sync_task(::Actions::Katello::ActivationKey::Update, @activation_key, activation_key_params)
respond_for_show(:resource => @activation_key)
end

Expand Down
34 changes: 34 additions & 0 deletions app/lib/actions/candlepin/activation_key/update.rb
@@ -0,0 +1,34 @@
#
# 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 Candlepin
module ActivationKey
class Update < Candlepin::Abstract
input_format do
param :cp_id
param :release_version
param :service_level
param :auto_attach
end

def plan(_activation_key)
::Katello::Resources::Candlepin::ActivationKey.update(
input[:cp_id],
input[:release_version],
input[:service_level],
input[:auto_attach])
end
end
end
end
end
30 changes: 30 additions & 0 deletions app/lib/actions/katello/activation_key/update.rb
@@ -0,0 +1,30 @@
#
# 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 ActivationKey
class Update < Actions::EntryAction
def plan(activation_key, activation_key_params)
activation_key.disable_auto_reindex!
activation_key.update_attributes!(activation_key_params)
plan_action(::Actions::Candlepin::ActivationKey::Update,
cp_id: "activation_key.cp_id",
release_version: "activation_key.releaseVer",
service_level: "activation_key.serviceLevel",
auto_attach: "activation_key.autoAttach")
action_subject activation_key
end
end
end
end
end
17 changes: 0 additions & 17 deletions app/models/katello/glue/candlepin/activation_key.rb
Expand Up @@ -18,8 +18,6 @@ def self.included(base)
base.send :include, InstanceMethods

base.class_eval do
before_save :save_activation_key_orchestration

lazy_accessor :service_level,
:initializer => (lambda do |_s|
Resources::Candlepin::ActivationKey.get(cp_id)[0][:serviceLevel] if cp_id
Expand Down Expand Up @@ -50,21 +48,6 @@ def get_key_pools
pools
end

def update_activation_key
Rails.logger.debug "Updating an activation key in candlepin: #{name}"
Resources::Candlepin::ActivationKey.update(self.cp_id, self.release_version, @service_level, self.auto_attach)
rescue => e
Rails.logger.error _("Failed to update candlepin activation_key %s") % "#{self.name}: #{e}, #{e.backtrace.join("\n")}"
raise e
end

def save_activation_key_orchestration
case self.orchestration_for
when :update
pre_queue.create(:name => "update candlepin activation_key: #{self.name}", :priority => 2, :action => [self, :update_activation_key])
end
end

def subscribe(pool_id, quantity = 1)
Resources::Candlepin::ActivationKey.add_pools self.cp_id, pool_id, quantity
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20141204203609_add_default_value_to_auto_attach.rb
@@ -0,0 +1,9 @@
class AddDefaultValueToAutoAttach < ActiveRecord::Migration
def up
change_column :katello_activation_keys, :auto_attach, :boolean, :default => true
end

def down
change_column :katello_activation_keys, :auto_attach, :boolean, :default => nil
end
end

0 comments on commit 9b12978

Please sign in to comment.