Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #37983 - Remove syspurpose addons from Katello #11196

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def get_content_view_environments(label = nil, organization = nil)
end

def rhsm_params
params.slice(:name, :type, :facts, :installedProducts, :autoheal, :releaseVer, :usage, :role, :addOns, :serviceLevel, :uuid, :capabilities, :guestIds, :lastCheckin).to_h
params.slice(:name, :type, :facts, :installedProducts, :autoheal, :releaseVer, :usage, :role, :serviceLevel, :uuid, :capabilities, :guestIds, :lastCheckin).to_h
end

def logger
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/katello/api/v2/activation_keys_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Api::V2::ActivationKeysController < Api::V2::ApiController # rubocop:disa
before_action :verify_simple_content_access_disabled, :only => [:add_subscriptions]
before_action :validate_release_version, :only => [:create, :update]

wrap_parameters :include => (ActivationKey.attribute_names + %w(host_collection_ids service_level auto_attach purpose_role purpose_usage purpose_addons content_view_environments))
wrap_parameters :include => (ActivationKey.attribute_names + %w(host_collection_ids service_level auto_attach purpose_role purpose_usage content_view_environments))

def_param_group :activation_key do
param :organization_id, :number, :desc => N_("organization identifier"), :required => true
Expand All @@ -25,7 +25,6 @@ class Api::V2::ActivationKeysController < Api::V2::ApiController # rubocop:disa
param :auto_attach, :bool, :desc => N_("auto attach subscriptions upon registration"), deprecated: true
param :purpose_usage, String, :desc => N_("Sets the system purpose usage")
param :purpose_role, String, :desc => N_("Sets the system purpose usage")
param :purpose_addons, Array, :desc => N_("Sets the system add-ons")

param :environment, Hash, :desc => N_("Hash containing the Id of the single lifecycle environment to be associated with the activation key."), deprecated: true
param :content_view_id, Integer, :desc => N_("Id of the single content view to be associated with the activation key.")
Expand Down Expand Up @@ -386,7 +385,6 @@ def permitted_params
:unlimited_hosts,
:purpose_role,
:purpose_usage,
:purpose_addon_ids,
:content_overrides => [],
:host_collection_ids => [],
:content_view_environments => [],
Expand All @@ -397,9 +395,6 @@ def activation_key_params
key_params = permitted_params.except(:environment_id, :content_view_id,
:content_view_environments, :content_view_environment_ids)

unless params[:purpose_addons].nil?
key_params[:purpose_addon_ids] = params[:purpose_addons].map { |addon| ::Katello::PurposeAddon.find_or_create_by(name: addon).id }
end
unlimited = params[:activation_key].try(:[], :unlimited_hosts)
max_hosts = params[:activation_key].try(:[], :max_hosts)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ class Api::V2::HostSubscriptionsController < Katello::Api::V2::ApiController
param :autoheal, :bool, :desc => N_("Sets whether the Host will autoheal subscriptions upon checkin")
param :purpose_usage, String, :desc => N_("Sets the system purpose usage")
param :purpose_role, String, :desc => N_("Sets the system purpose usage")
param :purpose_addons, Array, :desc => N_("Sets the system add-ons")
param :service_level, String, :desc => N_("Service level to be used for autoheal")
param :hypervisor_guest_uuids, Array, :desc => N_("List of hypervisor guest uuids")
param :installed_products_attributes, Array, :desc => N_("List of products installed on the host") do
Expand Down Expand Up @@ -99,7 +98,6 @@ def params_to_rhsm_params
rhsm_params[:releaseVer] = params['release_version'] if params['release_version']
rhsm_params[:usage] = params['purpose_usage'] if params['purpose_usage']
rhsm_params[:role] = params['purpose_role'] if params['purpose_role']
rhsm_params[:addOns] = params['purpose_addons'] if params['purpose_addons']
rhsm_params[:serviceLevel] = params['service_level'] if params['service_level']
rhsm_params[:guestIds] = params['hypervisor_guest_uuids'] if params[:hypervisor_guest_uuids]
rhsm_params[:type] = Katello::Candlepin::Consumer::SYSTEM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,12 @@ def resolve_traces
param :service_level, String, :desc => N_("Service level of host")
param :purpose_role, String, :desc => N_("Role of host")
param :purpose_usage, String, :desc => N_("Usage of host")
param :purpose_addons, Array, :desc => N_("Sets the system add-ons")
def system_purpose
task = async_task(::Actions::BulkAction, ::Actions::Katello::Host::UpdateSystemPurpose,
@hosts,
params[:service_level],
params[:purpose_role],
params[:purpose_usage],
params[:purpose_addons])
params[:purpose_usage])

respond_for_async :resource => task
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def action_permission

included do
prepend Overrides
before_action :purpose_addon_params, only: [:create, :update]
before_action :set_content_view_environments, only: [:create, :update]

def destroy
Expand All @@ -35,13 +34,6 @@ def host_collections
render(:locals => { :resource => @host }, :template => 'katello/api/v2/hosts/show', :status => :ok)
end

def purpose_addon_params
addons = params.dig(:host, :subscription_facet_attributes, :purpose_addons)
return if addons.nil?
params[:host][:subscription_facet_attributes][:purpose_addon_ids] = addons.map { |addon_name| ::Katello::PurposeAddon.find_or_create_by(name: addon_name).id }
params[:host][:subscription_facet_attributes].delete(:purpose_addons)
end

def set_content_view_environments
content_facet_attributes = params.dig(:host, :content_facet_attributes)
return if content_facet_attributes.blank? || @host&.content_facet.blank? ||
Expand Down
4 changes: 1 addition & 3 deletions app/lib/actions/candlepin/activation_key/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ActivationKey::Create < Candlepin::Abstract
param :release_version
param :purpose_role
param :purpose_usage
param :purpse_addons
end

def run
Expand All @@ -18,8 +17,7 @@ def run
input[:service_level],
input[:release_version],
input[:purpose_role],
input[:purpose_usage],
input[:purpose_addons])
input[:purpose_usage])
end
end
end
Expand Down
4 changes: 1 addition & 3 deletions app/lib/actions/candlepin/activation_key/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Update < Candlepin::Abstract
param :auto_attach
param :purpose_role
param :purpose_usage
param :purpose_addons
end

def run
Expand All @@ -19,8 +18,7 @@ def run
input[:service_level],
input[:auto_attach],
input[:purpose_role],
input[:purpose_usage],
input[:purpose_addons])
input[:purpose_usage])
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions app/lib/actions/katello/activation_key/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ def plan(activation_key, params = {})
service_level: params[:service_level],
release_version: activation_key.release_version,
purpose_role: activation_key.purpose_role,
purpose_usage: activation_key.purpose_usage,
purpose_addons: activation_key.purpose_addons.pluck(:name))
purpose_usage: activation_key.purpose_usage)
cp_id = cp_create.output[:response][:id]
action_subject(activation_key, :cp_id => cp_id)
plan_self
Expand Down
6 changes: 2 additions & 4 deletions app/lib/actions/katello/activation_key/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ def plan(activation_key, activation_key_params)
service_level: activation_key.service_level,
auto_attach: activation_key.auto_attach,
purpose_role: activation_key.purpose_role,
purpose_usage: activation_key.purpose_usage,
purpose_addons: activation_key.purpose_addons.pluck(:name))
purpose_usage: activation_key.purpose_usage)
end
end

Expand All @@ -24,8 +23,7 @@ def update_candlepin?(activation_key, activation_key_params)
cp_changed?(activation_key.service_level, activation_key_params[:service_level]) ||
cp_changed?(activation_key.release_version, activation_key_params[:release_version]) ||
cp_changed?(activation_key.purpose_role, activation_key_params[:purpose_role]) ||
cp_changed?(activation_key.purpose_usage, activation_key_params[:purpose_usage]) ||
cp_changed?(activation_key.purpose_addon_ids, activation_key_params[:purpose_addon_ids])
cp_changed?(activation_key.purpose_usage, activation_key_params[:purpose_usage])
end

def cp_changed?(activation_key, activation_key_params)
Expand Down
7 changes: 1 addition & 6 deletions app/lib/actions/katello/host/update_system_purpose.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ module Actions
module Katello
module Host
class UpdateSystemPurpose < Actions::EntryAction
def plan(host, service_level, purpose_role, purpose_usage, purpose_addons)
def plan(host, service_level, purpose_role, purpose_usage)
fail _("Host %s has not been registered with subscription-manager.") % host.name unless host.subscription_facet

host.subscription_facet.service_level = service_level unless service_level.nil?
host.subscription_facet.purpose_role = purpose_role unless purpose_role.nil?
host.subscription_facet.purpose_usage = purpose_usage unless purpose_usage.nil?

if purpose_addons
purpose_addon_objects = purpose_addons.delete_if(&:blank?).uniq.map { |x| ::Katello::PurposeAddon.find_or_create_by(name: x) }
host.subscription_facet.purpose_addons = purpose_addon_objects
end

host.save!
plan_self(:hostname => host.name)
end
Expand Down
10 changes: 4 additions & 6 deletions app/lib/katello/resources/candlepin/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,22 @@ def get(id = nil, params = '', owner = nil)
::Katello::Util::Data.array_with_indifferent_access akeys
end

# rubocop:disable Metrics/ParameterLists
def create(name, owner_key, auto_attach, service_level, release_version, purpose_role, purpose_usage, purpose_addons)
def create(name, owner_key, auto_attach, service_level, release_version, purpose_role, purpose_usage)
url = "/candlepin/owners/#{owner_key}/activation_keys"
params = {
name: name,
autoAttach: auto_attach,
serviceLevel: service_level,
releaseVer: release_version,
role: purpose_role,
usage: purpose_usage,
addOns: purpose_addons
usage: purpose_usage
}
response = self.post(url, params.to_json, self.default_headers)
JSON.parse(response.body).with_indifferent_access
end

def update(id, release_version, service_level, auto_attach, purpose_role, purpose_usage, purpose_addons)
attrs = { :releaseVer => release_version, :serviceLevel => service_level, :autoAttach => auto_attach, :role => purpose_role, :usage => purpose_usage, :addOns => purpose_addons }.delete_if { |_k, v| v.nil? }
def update(id, release_version, service_level, auto_attach, purpose_role, purpose_usage)
attrs = { :releaseVer => release_version, :serviceLevel => service_level, :autoAttach => auto_attach, :role => purpose_role, :usage => purpose_usage }.delete_if { |_k, v| v.nil? }
JSON.parse(self.put(path(id), attrs.to_json, self.default_headers).body).with_indifferent_access
end

Expand Down
11 changes: 0 additions & 11 deletions app/models/katello/activation_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ class ActivationKey < Katello::Model
has_many :subscription_facet_activation_keys, :class_name => "Katello::SubscriptionFacetActivationKey", :dependent => :destroy
has_many :subscription_facets, :through => :subscription_facet_activation_keys

has_many :activation_key_purpose_addons, :class_name => "Katello::ActivationKeyPurposeAddon", :dependent => :destroy, :inverse_of => :activation_key
has_many :purpose_addons, :class_name => "Katello::PurposeAddon", :through => :activation_key_purpose_addons

before_destroy :validate_destroyable!
accepts_nested_attributes_for :purpose_addons

validates_lengths_from_database
validates_with Validators::KatelloNameFormatValidator, :attributes => :name
Expand Down Expand Up @@ -88,7 +84,6 @@ class ActivationKey < Katello::Model
:only_explicit => true, :validator => ScopedSearch::Validators::INTEGER, :ext_method => :find_by_subscription_id
scoped_search :on => :purpose_usage, :rename => :usage, :complete_value => true
scoped_search :on => :purpose_role, :rename => :role, :complete_value => true
scoped_search :on => :name, :rename => :addon, :relation => :purpose_addon, :complete_value => true, :ext_method => :find_by_purpose_addons

def self.in_environments(envs)
with_environments(envs)
Expand Down Expand Up @@ -270,12 +265,6 @@ def self.return_activation_keys_by_id(activation_key_ids)
end
end

def self.find_by_purpose_addons(_key, operator, value)
conditions = sanitize_sql_for_conditions(["#{Katello::PurposeAddon.table_name}.name #{operator} ?", value_to_sql(operator, value)])
activation_keys = ::Katello::ActivationKey.joins(:purpose_addons).where(conditions)
return_activation_keys_by_id(activation_keys.pluck(:id))
end

def validate_destroyable!
if !organization.being_deleted? && Parameter.where(name: 'kt_activation_keys').pluck(:value).any? { |value| value.split(",").include?(name) }
fail _("This activation key is associated to one or more Hosts/Hostgroups. "\
Expand Down
6 changes: 0 additions & 6 deletions app/models/katello/activation_key_purpose_addon.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ module SubscriptionFacetHostExtensions

has_many :activation_keys, :through => :subscription_facet
has_many :pools, :through => :subscription_facet
has_many :purpose_addons, :through => :subscription_facet
has_many :subscriptions, :through => :pools
has_one :rhel_lifecycle_status_object, :class_name => 'Katello::RhelLifecycleStatus', :foreign_key => 'host_id', :dependent => :destroy
has_one :hypervisor_host, :through => :subscription_facet
Expand All @@ -38,7 +37,6 @@ module SubscriptionFacetHostExtensions
scoped_search :on => :id, :relation => :pools, :rename => :subscription_id, :complete_value => true, :ext_method => :find_by_subscription_id, :only_explicit => true
scoped_search :on => :purpose_role, :rename => :role, :relation => :subscription_facet, :complete_value => true
scoped_search :on => :purpose_usage, :rename => :usage, :relation => :subscription_facet, :complete_value => true
scoped_search :on => :name, :rename => :addon, :relation => :purpose_addons, :complete_value => true, :ext_method => :find_by_purpose_addon
before_update :update_candlepin_associations, if: -> { subscription_facet.try(:backend_update_needed?) }
end

Expand Down Expand Up @@ -81,12 +79,6 @@ def rhel_lifecycle_status_map
::Katello::RhelLifecycleStatus.status_map
end

def find_by_purpose_addon(_key, operator, value)
conditions = sanitize_sql_for_conditions(["#{Katello::PurposeAddon.table_name}.name #{operator} ?", value_to_sql(operator, value)])
hosts = ::Host::Managed.joins(:purpose_addons).where(conditions)
return_hosts(hosts)
end

def find_by_activation_key(_key, operator, value)
conditions = sanitize_sql_for_conditions(["#{Katello::ActivationKey.table_name}.name #{operator} ?", value_to_sql(operator, value)])
hosts = ::Host::Managed.joins(:activation_keys).where(conditions)
Expand Down
2 changes: 1 addition & 1 deletion app/models/katello/glue/candlepin/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def self.included(base)
lazy_accessor :subscription_facts, :initializer => lambda { |_s| self.subscription ? self.subscription.attributes : {} }

lazy_accessor :pool_derived, :owner, :source_pool_id, :virt_limit, :arch, :description, :product_family,
:variant, :suggested_quantity, :support_type, :product_id, :type, :upstream_entitlement_id, :roles, :usage, :addons,
:variant, :suggested_quantity, :support_type, :product_id, :type, :upstream_entitlement_id, :roles, :usage,
:initializer => :pool_facts

lazy_accessor :name, :support_level, :org, :sockets, :cores, :instance_multiplier,
Expand Down
13 changes: 2 additions & 11 deletions app/models/katello/host/subscription_facet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class SubscriptionFacet < Katello::Model
has_many :subscription_facet_activation_keys, :class_name => "Katello::SubscriptionFacetActivationKey", :dependent => :destroy, :inverse_of => :subscription_facet
has_many :activation_keys, :through => :subscription_facet_activation_keys, :class_name => "Katello::ActivationKey"

has_many :subscription_facet_purpose_addons, :class_name => "Katello::SubscriptionFacetPurposeAddon", :dependent => :destroy, :inverse_of => :subscription_facet
has_many :purpose_addons, :class_name => "Katello::PurposeAddon", :through => :subscription_facet_purpose_addons

has_many :subscription_facet_pools, :class_name => "Katello::SubscriptionFacetPool", :dependent => :delete_all, :inverse_of => :subscription_facet
has_many :pools, :through => :subscription_facet_pools, :class_name => "Katello::Pool"

Expand All @@ -27,9 +24,7 @@ class SubscriptionFacet < Katello::Model

DEFAULT_TYPE = 'system'.freeze

accepts_nested_attributes_for :installed_products, :purpose_addons

dirty_has_many_associations :purpose_addons
accepts_nested_attributes_for :installed_products

attr_accessor :facts

Expand Down Expand Up @@ -63,9 +58,6 @@ def import_database_attributes(consumer_params = candlepin_consumer.consumer_att
self.update_installed_products(consumer_params['installedProducts']) if consumer_params.key?('installedProducts')
self.purpose_role = consumer_params['role'] unless consumer_params['role'].nil?
self.purpose_usage = consumer_params['usage'] unless consumer_params['usage'].nil?
unless consumer_params['addOns'].nil?
self.purpose_addon_ids = consumer_params['addOns'].map { |addon_name| ::Katello::PurposeAddon.find_or_create_by(name: addon_name).id }
end

unless consumer_params['releaseVer'].nil?
release = consumer_params['releaseVer']
Expand Down Expand Up @@ -141,7 +133,6 @@ def consumer_attributes
:autoheal => autoheal,
:usage => purpose_usage,
:role => purpose_role,
:addOns => purpose_addons.pluck(:name),
:serviceLevel => service_level,
:releaseVer => release_version,
:environments => self.candlepin_environments,
Expand Down Expand Up @@ -283,7 +274,7 @@ def candlepin_consumer
end

def backend_update_needed?
%w(release_version service_level autoheal purpose_role purpose_usage purpose_addon_ids).each do |method|
%w(release_version service_level autoheal purpose_role purpose_usage).each do |method|
if self.send("#{method}_changed?")
Rails.logger.debug("backend_update_needed: subscription facet #{method} changed")
return true
Expand Down
Loading
Loading