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

[3.13] Fixes #38010 & #38012 - OpenJDK 17 compatiblity #995

Merged
merged 3 commits into from
Nov 19, 2024
Merged
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
2 changes: 1 addition & 1 deletion Puppetfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ mod 'theforeman/foreman', '~> 25.3.0'
mod 'theforeman/foreman_proxy', '~> 27.0.0'
mod 'theforeman/puppet', '~> 20.0.0'
mod 'katello/foreman_proxy_content', '~> 30.0.0'
mod 'katello/certs', '~> 19.1.0'
mod 'katello/certs', '~> 19.1.1'
mod 'katello/katello', '~> 25.2.0'
4 changes: 2 additions & 2 deletions Puppetfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ FORGE
puppetlabs-concat (>= 1.0.0, < 10.0.0)
puppetlabs-postgresql (>= 9.2.0, < 11.0.0)
puppetlabs-stdlib (>= 9.0.0, < 10.0.0)
katello-certs (19.1.0)
katello-certs (19.1.1)
puppet-extlib (>= 3.0.0, < 8.0.0)
puppetlabs-stdlib (>= 4.25.0, < 10.0.0)
katello-foreman_proxy_content (30.0.0)
Expand Down Expand Up @@ -99,7 +99,7 @@ FORGE

DEPENDENCIES
katello-candlepin (~> 16.1.0)
katello-certs (~> 19.1.0)
katello-certs (~> 19.1.1)
katello-foreman_proxy_content (~> 30.0.0)
katello-katello (~> 25.2.0)
puppet-redis (>= 8.5.0)
Expand Down
10 changes: 10 additions & 0 deletions hooks/boot/01-kafo-hook-extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ def available_space(directory = nil)
end
mountpoint[:available_bytes]
end

def parse_java_version(output)
output&.match(/version "(?<version>\d+\.\d+)\.\d+/) do |java_match|
return unless (version = java_match[:version])

version = version.delete_prefix('1.') if version.start_with?('1.')

yield version.to_i
end
end
end

Kafo::HookContext.send(:include, HookContextExtension)
6 changes: 3 additions & 3 deletions hooks/pre/31-puppet_puppet_server_invalid_java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
logger.debug("Found Puppetserver #{puppetserver_match[:version]}")
if puppetserver_match[:version] == '8'
java_stdout_stderr, _status = execute_command("source #{sysconfig_file} ; $JAVA_BIN -version", false, true)
java_stdout_stderr&.match(/version "\d+\.(?<version>\d+)\.\d+/) do |java_match|
if java_match[:version] && java_match[:version].to_i < 11
logger.info "Detected Java #{java_match[:version]} which is too old for Puppetserver #{puppetserver_match[:version]}"
parse_java_version(java_stdout_stderr) do |java_version|
if java_version < 11
logger.info "Detected Java #{java_version} which is too old for Puppetserver #{puppetserver_match[:version]}"
if app_value(:noop)
logger.debug 'Would stop puppetserver.service'
else
Expand Down
58 changes: 58 additions & 0 deletions spec/hook_context_extension_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,64 @@
allow(context).to receive(:logger).and_return(logger)
end

describe '.parse_java_version' do
context 'java-1.8.0-openjdk-headless' do
let(:output) do
<<~OUTPUT
openjdk version "1.8.0_362"
OpenJDK Runtime Environment (build 1.8.0_362-b08)
OpenJDK 64-Bit Server VM (build 25.362-b08, mixed mode)
OUTPUT
end

it do
expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(8)
end
end

context 'java-11-openjdk-headless' do
let(:output) do
<<~OUTPUT
openjdk version "11.0.20.1" 2023-08-24 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS, mixed mode, sharing)
OUTPUT
end

it do
expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(11)
end
end

context 'java-17-openjdk-headless' do
let(:output) do
<<~OUTPUT
openjdk version "17.0.11" 2024-04-16 LTS
OpenJDK Runtime Environment (Red_Hat-17.0.11.0.9-5) (build 17.0.11+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-17.0.11.0.9-5) (build 17.0.11+9-LTS, mixed mode, sharing)
OUTPUT
end

it do
expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(17)
end
end

context 'java-21-openjdk-headless' do
let(:output) do
<<~OUTPUT
openjdk version "21.0.4" 2024-07-16 LTS
OpenJDK Runtime Environment (Red_Hat-21.0.4.0.7-1) (build 21.0.4+7-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-21.0.4.0.7-1) (build 21.0.4+7-LTS, mixed mode, sharing)
OUTPUT
end

it do
expect { |block| context.parse_java_version(output, &block) }.to yield_with_args(21)
end
end
end

describe '.ensure_packages' do
subject { context.ensure_packages(packages, state) }

Expand Down