From 83d52ac6969d5cd3b991e482d7b4397ee9386480 Mon Sep 17 00:00:00 2001 From: Bernhard Suttner Date: Fri, 13 Oct 2023 18:27:37 +0200 Subject: [PATCH] Handle new debian profiles upload --- .../host_managed_extensions.rb | 12 ++++++------ .../foreman_kernel_care/profiles_uploader.rb | 15 +++++++++++++++ lib/foreman_kernel_care/engine.rb | 2 ++ 3 files changed, 23 insertions(+), 6 deletions(-) create mode 100644 app/services/concerns/foreman_kernel_care/profiles_uploader.rb diff --git a/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb b/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb index 4a1488b..13ead93 100644 --- a/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb +++ b/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb @@ -48,8 +48,13 @@ def update_kernel_version(version, release, old_kernel_version) end end + def kernelcare? + !installed_packages.select { |package| package.name == 'kernelcare' }.empty? || + !installed_debs.select { |package| package.name == 'kernelcare' }.empty? + end + class ::Host::Managed::Jail < Safemode::Jail - allow :installed_debs + allow :installed_debs, :kernelcare? end protected @@ -138,10 +143,5 @@ def sync_deb_kernel_associations(new_patched_kernel_ids, old_kernel_ids) self.installed_deb_ids = new_installed_debs.concat(new_patched_kernel_ids) save! end - - def kernelcare? - !installed_packages.select { |package| package.name == 'kernelcare' }.empty? || - !installed_debs.select { |package| package.name == 'kernelcare' }.empty? - end end end diff --git a/app/services/concerns/foreman_kernel_care/profiles_uploader.rb b/app/services/concerns/foreman_kernel_care/profiles_uploader.rb new file mode 100644 index 0000000..6427105 --- /dev/null +++ b/app/services/concerns/foreman_kernel_care/profiles_uploader.rb @@ -0,0 +1,15 @@ +module ForemanKernelCare + module ProfilesUploader + extend ActiveSupport::Concern + + def import_deb_package_profile(profile) + if @host.kernelcare? + composer = ::JobInvocationComposer.for_feature(:kernel_version, @host) + composer.triggering.mode = :future + composer.trigger! + end + + super(profile) + end + end +end diff --git a/lib/foreman_kernel_care/engine.rb b/lib/foreman_kernel_care/engine.rb index 0b59a85..273993c 100644 --- a/lib/foreman_kernel_care/engine.rb +++ b/lib/foreman_kernel_care/engine.rb @@ -8,6 +8,7 @@ class Engine < ::Rails::Engine engine_name 'foreman_kernel_care' config.autoload_paths += Dir["#{config.root}/app/models/concerns"] + config.autoload_paths += Dir["#{config.root}/app/services/concerns"] initializer 'foreman_kernel_care.register_plugin', :before => :finisher_hook do |_app| Foreman::Plugin.register :foreman_kernel_care do @@ -19,6 +20,7 @@ class Engine < ::Rails::Engine # make sure the plugin is initialized before katello loads the host extensions initializer 'foreman_kernel_care.load_kernelcare_override', :before => :finisher_hook, :after => ['katello.register_plugin', 'foreman_tasks.register_plugin'] do ::Katello::Concerns::HostManagedExtensions.prepend ForemanKernelCare::HostManagedExtensions + ::Katello::Host::ProfilesUploader.prepend ForemanKernelCare::ProfilesUploader ::ForemanTasks::Api::TasksController.prepend ForemanKernelCare::ForemanTasks end