RedHatSatellite / katello-attach-subscription

automatically assign subscriptions to hypervisors based on certain rules
GNU General Public License v2.0
10 stars 5 forks source link

Not attaching the correct quantity of subscription entitlements because facts are not available #69

Open DoGab opened 4 years ago

DoGab commented 4 years ago

Problem

KAS is not able to assign the correct quantity of subscription entitlements. For example if a host has 4 CPU Sockets it would require 2 subscription entitlements to be full entitled and perform correctly.

Cause

It does not work correctly because the hosts facts are not exported when performing this api call.

sys = @api.resource(:hosts).call(:show, {:id => system['id'], :fields => 'full'})
...

# if the number of socket is setted, we can find the value from cpu::cpu_socket(s)
if sys.has_key?("facts") and sys["facts"].is_a?(Hash) and sys["facts"].has_key?("cpu::cpu_socket(s)")
  # if the field is present check if it's a valid entry or not, if not exit with error
  if sys["facts"]["cpu::cpu_socket(s)"].to_i > 0
    # set sys_socket to the value of cpu::cpu_socket(s)
    sys_socket = sys["facts"]["cpu::cpu_socket(s)"].to_i
    if @options[:debug]
      puts "   DEBUG: Setting sys_socket to #{sys_socket} for #{sys["name"]}"
    end
  else
    puts "   FATAL ERROR: The number of socket for #{sys["name"]} it's equal or lower then 0."
    exit 5
  end
else
  sys_socket = 1
  if @options[:debug]
    puts "   DEBUG: No cpu sockets entry found for #{sys['name']}, assigned 1 by default"
  end
end

Because KAS does only search for facts in the sys variable the quantity of needed subscription entitlement, which is based on how many CPU sockets a host has, can't be correctly calculated and attached.