foreman_kernel_care 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/app/controllers/concerns/foreman_kernel_care/foreman_tasks.rb +22 -0
- data/app/models/concerns/foreman_kernel_care/host_managed_extensions.rb +49 -0
- data/app/views/foreman_kernel_care/job_templates/kernel_version.erb +15 -0
- data/db/seeds.d/100_assign_features_with_templates.rb +7 -0
- data/lib/foreman_kernel_care/engine.rb +1 -0
- data/lib/foreman_kernel_care/remote_execution.rb +6 -0
- data/lib/foreman_kernel_care/version.rb +1 -1
- data/test/unit/host_managed_extensions_test.rb +28 -3
- metadata +11 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1d0ef271076e4187e05dfbb9b3b46c15566c103e735e81edfbe864507664176
|
4
|
+
data.tar.gz: cbabb299ec2d3bd510f3828ac20713ceb065f8a551c0b5adec0310a26e0bfdd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68d4e8475ec10d76a71bf96adf0e20d832868b8263bcc613e685d36f0506e0eee809b2f8f02c968739dc4e6aeb9fe285dbc70a5821a3757f845e74e7e8fb129a
|
7
|
+
data.tar.gz: 1a6fc20bb8eb792f6bf4d85db1de7b2935f7b7a51b3ebbddcdc7da8994d5c21032e70cada23a526a73a555cfbeeb8df04ed377c8d1d1751492997d4522933c62
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# ForemanKernelCare
|
2
2
|
|
3
|
-
This plugin removes kernel [trace](https://theforeman.org/plugins/katello/
|
3
|
+
This plugin removes kernel [trace](https://theforeman.org/plugins/katello/nightly/user_guide/tracer/index.html) and update the kernel package version if [KernelCare](https://www.kernelcare.com/product/) package is installed on host
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
See [How_to_Install_a_Plugin](
|
7
|
+
See [How_to_Install_a_Plugin](https://www.theforeman.org/plugins/#2.Installation)
|
8
8
|
for how to install Foreman plugins
|
9
9
|
|
10
10
|
## Usage
|
@@ -17,7 +17,7 @@ Fork and send a Pull Request. Thanks!
|
|
17
17
|
|
18
18
|
## Copyright
|
19
19
|
|
20
|
-
Copyright (c)
|
20
|
+
Copyright (c) 2022 maccelf
|
21
21
|
|
22
22
|
This program is free software: you can redistribute it and/or modify
|
23
23
|
it under the terms of the GNU General Public License as published by
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module ForemanKernelCare
|
2
|
+
module ForemanTasks
|
3
|
+
def callback
|
4
|
+
callbacks = params.key?(:callback) ? Array(params) : params[:callbacks]
|
5
|
+
ids = callbacks.map { |payload| payload[:callback][:task_id] }
|
6
|
+
foreman_tasks = ::ForemanTasks::Task.where(:id => ids)
|
7
|
+
external_map = Hash[*foreman_tasks.pluck(:id, :external_id).flatten]
|
8
|
+
callbacks.each do |payload|
|
9
|
+
# We need to call .to_unsafe_h to unwrap the hash from ActionController::Parameters
|
10
|
+
callback = payload[:callback]
|
11
|
+
foreman_task = foreman_tasks.find { |task| task.id == callback[:task_id] }
|
12
|
+
if foreman_task.action.include?('Get patched kernel version')
|
13
|
+
version, release = payload[:data].to_unsafe_h['result'].first['output'].strip.split('-')
|
14
|
+
job_invocation = ::JobInvocation.where(:task_id => foreman_task.parent_task_id).first
|
15
|
+
job_invocation.targeting.hosts.each { |host| host.update_kernel_version(version, release) }
|
16
|
+
end
|
17
|
+
process_callback(external_map[callback[:task_id]], callback[:step_id].to_i, payload[:data].to_unsafe_h, :request_id => ::Logging.mdc['request'])
|
18
|
+
end
|
19
|
+
render :json => { :message => 'processing' }.to_json
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -1,5 +1,16 @@
|
|
1
1
|
module ForemanKernelCare
|
2
2
|
module HostManagedExtensions
|
3
|
+
def import_package_profile(simple_packages)
|
4
|
+
if kernelcare?
|
5
|
+
composer = ::JobInvocationComposer.for_feature(:kernel_version, self)
|
6
|
+
composer.triggering.mode = :future
|
7
|
+
composer.trigger!
|
8
|
+
end
|
9
|
+
|
10
|
+
found = import_package_profile_in_bulk(simple_packages)
|
11
|
+
sync_package_associations(found.map(&:id).uniq)
|
12
|
+
end
|
13
|
+
|
3
14
|
def import_tracer_profile(tracer_profile)
|
4
15
|
traces = []
|
5
16
|
tracer_profile.each do |trace, attributes|
|
@@ -20,6 +31,44 @@ module ForemanKernelCare
|
|
20
31
|
update_trace_status
|
21
32
|
end
|
22
33
|
|
34
|
+
def update_kernel_version(version, release)
|
35
|
+
packages = ::Katello::InstalledPackage.where('name LIKE ?', '%kernel%').where.not(name: 'kernelcare').to_a
|
36
|
+
delete_ids = []
|
37
|
+
simple_packages = packages.map do |p|
|
38
|
+
delete_ids << p.id
|
39
|
+
::Katello::Pulp::SimplePackage.new({
|
40
|
+
arch: p.arch,
|
41
|
+
epoch: p.epoch,
|
42
|
+
version: version,
|
43
|
+
release: release,
|
44
|
+
name: p.name
|
45
|
+
})
|
46
|
+
end
|
47
|
+
found = import_package_profile_in_bulk(simple_packages)
|
48
|
+
sync_kernel_associations(found.map(&:id).uniq, delete_ids)
|
49
|
+
end
|
50
|
+
|
51
|
+
def sync_kernel_associations(new_patched_kernel_ids, delete_ids)
|
52
|
+
::Katello::Util::Support.active_record_retry do
|
53
|
+
table_name = host_installed_packages.table_name
|
54
|
+
|
55
|
+
queries = []
|
56
|
+
|
57
|
+
if delete_ids.any?
|
58
|
+
queries << "DELETE FROM #{table_name} WHERE host_id=#{id} AND installed_package_id IN (#{delete_ids.join(', ')})"
|
59
|
+
end
|
60
|
+
|
61
|
+
unless new_patched_kernel_ids.empty?
|
62
|
+
inserts = new_patched_kernel_ids.map { |unit_id| "(#{unit_id.to_i}, #{id.to_i})" }
|
63
|
+
queries << "INSERT INTO #{table_name} (installed_package_id, host_id) VALUES #{inserts.join(', ')}"
|
64
|
+
end
|
65
|
+
|
66
|
+
queries.each do |query|
|
67
|
+
::ActiveRecord::Base.connection.execute(query)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
23
72
|
protected
|
24
73
|
|
25
74
|
def kernelcare?
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<%#
|
2
|
+
kind: job_template
|
3
|
+
name: Kernel version
|
4
|
+
model: JobTemplate
|
5
|
+
job_category: Commands
|
6
|
+
description_format: "Get patched kernel version"
|
7
|
+
provider_type: SSH
|
8
|
+
feature: kernel_version
|
9
|
+
%>
|
10
|
+
<%
|
11
|
+
unless @host.installed_packages.select { |package| package.name == 'kernelcare' }.empty?
|
12
|
+
render_error(N_('Unsupported host.'))
|
13
|
+
end
|
14
|
+
%>
|
15
|
+
/usr/bin/kcarectl --uname
|
@@ -16,6 +16,13 @@ User.as_anonymous_admin do
|
|
16
16
|
module_template.organizations << Organization.unscoped.all if module_template.organizations.empty?
|
17
17
|
module_template.locations << Location.unscoped.all if module_template.locations.empty?
|
18
18
|
end
|
19
|
+
|
20
|
+
module_template = JobTemplate.find_by(name: 'Kernel version')
|
21
|
+
if module_template && !Rails.env.test? && Setting[:remote_execution_sync_templates]
|
22
|
+
module_template.sync_feature('kernel_version')
|
23
|
+
module_template.organizations << Organization.unscoped.all if module_template.organizations.empty?
|
24
|
+
module_template.locations << Location.unscoped.all if module_template.locations.empty?
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
@@ -19,6 +19,7 @@ module ForemanKernelCare
|
|
19
19
|
# Include concerns in this config.to_prepare block
|
20
20
|
config.to_prepare do
|
21
21
|
Katello::Concerns::HostManagedExtensions.prepend ForemanKernelCare::HostManagedExtensions
|
22
|
+
ForemanTasks::Api::TasksController.prepend ForemanKernelCare::ForemanTasks
|
22
23
|
rescue StandardError => e
|
23
24
|
Rails.logger.warn "ForemanKernelCare: skipping engine hook (#{e})"
|
24
25
|
end
|
@@ -11,6 +11,12 @@ module ForemanKernelCare
|
|
11
11
|
N_('Run Update kernel'),
|
12
12
|
:description => N_('Runs Update kernel')
|
13
13
|
)
|
14
|
+
|
15
|
+
RemoteExecutionFeature.register(
|
16
|
+
:kernel_version,
|
17
|
+
N_('Get patched kernel version'),
|
18
|
+
:description => N_('Get patched kernel version')
|
19
|
+
)
|
14
20
|
end
|
15
21
|
end
|
16
22
|
end
|
@@ -2,15 +2,40 @@ require 'test_plugin_helper'
|
|
2
2
|
|
3
3
|
module ForemanKernelCare
|
4
4
|
class HostManagedExtensionsTestBase < ActiveSupport::TestCase
|
5
|
+
end
|
6
|
+
|
7
|
+
class HostInstalledPackagesTest < HostManagedExtensionsTestBase
|
5
8
|
def setup
|
6
|
-
|
7
|
-
template.
|
9
|
+
feature = RemoteExecutionFeature.register('kernel_version', 'Kernel version')
|
10
|
+
template = FactoryBot.create(:job_template, name: 'Kernel versionl')
|
11
|
+
template.sync_feature(feature.label)
|
12
|
+
|
13
|
+
@host = FactoryBot.create(:host, :with_kernelcare)
|
14
|
+
package_json = {:name => "kernel", :version => "1", :release => "1.el7", :arch => "x86_64", :epoch => "1",
|
15
|
+
:nvra => "kernel-1-1.el7.x86_64"}
|
16
|
+
@host.import_package_profile([::Katello::Pulp::SimplePackage.new(package_json)])
|
17
|
+
@nvra = 'kernel-1-1.el7.x86_64'
|
18
|
+
@host.reload
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_update_kernel_version
|
22
|
+
version = '2'
|
23
|
+
release = '2.el7'
|
24
|
+
@host.update_kernel_version(version, release)
|
25
|
+
kernel_package = @host.installed_packages.where(name: 'kernel').first
|
26
|
+
|
27
|
+
assert_not_equal kernel_package.nvra, @nvra
|
28
|
+
assert_equal kernel_package.version, version
|
29
|
+
assert_equal kernel_package.release, release
|
8
30
|
end
|
9
31
|
end
|
10
32
|
|
11
33
|
class HostTracerTest < HostManagedExtensionsTestBase
|
12
34
|
def setup
|
13
|
-
|
35
|
+
feature = RemoteExecutionFeature.register('update_kernel', 'Update Kernel')
|
36
|
+
template = FactoryBot.create(:job_template, name: 'Update kernel')
|
37
|
+
template.sync_feature(feature.label)
|
38
|
+
|
14
39
|
@tracer_json = {
|
15
40
|
"kernel": {
|
16
41
|
"type": 'static',
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_kernel_care
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Petukhov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: foreman_remote_execution
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.5.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.5.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: katello
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.8.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rdoc
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -77,7 +77,9 @@ files:
|
|
77
77
|
- LICENSE
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
+
- app/controllers/concerns/foreman_kernel_care/foreman_tasks.rb
|
80
81
|
- app/models/concerns/foreman_kernel_care/host_managed_extensions.rb
|
82
|
+
- app/views/foreman_kernel_care/job_templates/kernel_version.erb
|
81
83
|
- app/views/foreman_kernel_care/job_templates/update_kernel.erb
|
82
84
|
- db/seeds.d/100_assign_features_with_templates.rb
|
83
85
|
- db/seeds.d/70_job_templates.rb
|
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
110
|
- !ruby/object:Gem::Version
|
109
111
|
version: '0'
|
110
112
|
requirements: []
|
111
|
-
rubygems_version: 3.1.
|
113
|
+
rubygems_version: 3.1.2
|
112
114
|
signing_key:
|
113
115
|
specification_version: 4
|
114
116
|
summary: Plugin for KernelCare
|