Skip to content

Commit

Permalink
Fixes #34999 - retrieve the software vendor package from the installe…
Browse files Browse the repository at this point in the history
…d package (#10142)
  • Loading branch information
sjha4 committed Jun 3, 2022
1 parent ba22d6a commit 193cd01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
14 changes: 12 additions & 2 deletions app/models/katello/concerns/host_managed_extensions.rb
Expand Up @@ -204,7 +204,16 @@ def import_package_profile(simple_packages)

def import_package_profile_in_bulk(simple_packages)
nvreas = simple_packages.map { |sp| sp.nvrea }
found = InstalledPackage.where(:nvrea => nvreas).select(:id, :nvrea).to_a
found_nvrea = InstalledPackage.where(:nvrea => nvreas)
nil_vendor_installed_packages = found_nvrea.where(vendor: nil)
unless nil_vendor_installed_packages.blank?
packages_to_update = simple_packages.select { |sp| !sp.vendor.blank? && nil_vendor_installed_packages&.map(&:nvrea)&.include?(sp.nvrea) }
packages_to_update.each do |simple_package|
nil_vendor_installed_packages.where(nvrea: simple_package.nvrea).update(vendor: simple_package.vendor)
end
end

found = found_nvrea.select(:id, :nvrea).to_a
found_nvreas = found.map(&:nvrea)

new_packages = simple_packages.select { |sp| !found_nvreas.include?(sp.nvrea) }
Expand All @@ -217,7 +226,8 @@ def import_package_profile_in_bulk(simple_packages)
:epoch => simple_package.epoch,
:version => simple_package.version,
:release => simple_package.release,
:arch => simple_package.arch)
:arch => simple_package.arch,
:vendor => simple_package.vendor)
end
InstalledPackage.import(installed_packages, validate: false, on_duplicate_key_ignore: true)
#re-lookup all imported to pickup any duplicates/conflicts
Expand Down
1 change: 1 addition & 0 deletions app/models/katello/installed_package.rb
Expand Up @@ -23,5 +23,6 @@ class Jail < Safemode::Jail
scoped_search :on => :version
scoped_search :on => :release
scoped_search :on => :arch
scoped_search :on => :vendor
end
end
@@ -0,0 +1,5 @@
class AddVendorToKatelloInstalledPackages < ActiveRecord::Migration[6.1]
def change
add_column :katello_installed_packages, :vendor, :string
end
end
3 changes: 2 additions & 1 deletion test/models/concerns/host_managed_extensions_test.rb
Expand Up @@ -232,7 +232,7 @@ class HostInstalledPackagesTest < HostManagedExtensionsTestBase
def setup
super
package_json = {:name => "foo", :version => "1", :release => "1.el7", :arch => "x86_64", :epoch => "1",
:nvra => "foo-1-1.el7.x86_64"}
:nvra => "foo-1-1.el7.x86_64", :vendor => "Fedora"}
@foreman_host.import_package_profile([::Katello::Pulp::SimplePackage.new(package_json)])
@nvra = 'foo-1-1.el7.x86_64'
@foreman_host.reload
Expand All @@ -242,6 +242,7 @@ def test_installed_packages
assert_equal 1, @foreman_host.installed_packages.count
assert_equal 'foo', @foreman_host.installed_packages.first.name
assert_equal @nvra, @foreman_host.installed_packages.first.nvra
assert_equal 'Fedora', @foreman_host.installed_packages.first.vendor
end

def test_import_package_profile_adds_removes_bulk
Expand Down

0 comments on commit 193cd01

Please sign in to comment.