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

Add a foreman-proxy scenario #737

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ MANDIR = ENV['MANDIR'] || "#{DATAROOTDIR}/man"
PKGDIR = ENV['PKGDIR'] || File.expand_path('pkg')

if BUILD_KATELLO
SCENARIOS = ['foreman', 'foreman-proxy-content', 'katello'].freeze
SCENARIOS = ['foreman', 'foreman-proxy', 'foreman-proxy-content', 'katello'].freeze
CERTS_SCENARIOS = ['foreman-proxy-certs'].freeze
else
SCENARIOS = ['foreman'].freeze
SCENARIOS = ['foreman', 'foreman-proxy'].freeze
CERTS_SCENARIOS = [].freeze
end

Expand Down
16 changes: 2 additions & 14 deletions bin/create-migration
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,8 @@ directories.each do |directory|
exit 2
end

if File.basename(directory) == 'foreman.migrations'
# Used by the foreman scenario
format = '+%Y%m%d%H%M%S'
to_replace = '-'
glue = '_'
else
# Recommended format by kafo
format = '+%y%m%d%H%M%S'
to_replace = '-'
glue = '-'
end

timestamp = `TZ=UTC date #{format}`.strip
filename = File.join(directory, "#{timestamp}#{glue}#{migration_name.gsub(to_replace, glue)}.rb")
timestamp = `TZ=UTC date '+%Y%m%d%H%M%S'`.strip
filename = File.join(directory, "#{timestamp}#{glue}#{migration_name.gsub('-', '_')}.rb")

File.open(filename, 'w') do |file|
file.puts(content) if content
Expand Down
36 changes: 36 additions & 0 deletions config/foreman-proxy-anwers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Format:
# <classname>: false - don't include this class
# <classname>: true - include and use the defaults
# <classname>:
# <param>: <value> - include and override the default(s)
#
# Every support plugin/compute class is listed, so that it
# shows up in the interactive menu
#
# See params.pp in each class for what options are available
---
foreman_proxy:
http: true
registration: true
templates: true
foreman_proxy::plugin::acd: false
foreman_proxy::plugin::ansible: false
foreman_proxy::plugin::chef: false
foreman_proxy::plugin::dhcp::infoblox: false
foreman_proxy::plugin::dhcp::remote_isc: false
foreman_proxy::plugin::discovery: false
foreman_proxy::plugin::dns::infoblox: false
foreman_proxy::plugin::dns::powerdns: false
foreman_proxy::plugin::dynflow: false
foreman_proxy::plugin::monitoring: false
foreman_proxy::plugin::omaha: false
foreman_proxy::plugin::openscap: false
foreman_proxy::plugin::remote_execution::ssh: false
foreman_proxy::plugin::reports: false
foreman_proxy::plugin::salt: false
foreman_proxy::plugin::shellhooks: false
puppet:
server: true
server_jvm_extra_args:
- "-Djruby.logger.class=com.puppetlabs.jruby_utils.jruby.Slf4jLogger"
- "-XX:ReservedCodeCacheSize=512m"
1 change: 1 addition & 0 deletions config/foreman-proxy.migrations
27 changes: 27 additions & 0 deletions config/foreman-proxy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
:name: Foreman Proxy
:description: Install a stand-alone Foreman Proxy

:log_dir: './_build/'
:log_name: 'foreman-proxy.log'
:log_level: DEBUG
:verbose: true
:verbose_log_level: notice

:answer_file: ./config/foreman-proxy-answers.yaml
:installer_dir: .
:module_dirs: ./_build/modules
:parser_cache_path: ./_build/parser_cache/foreman-proxy.yaml
:hiera_config: ./config/foreman-hiera.yaml

:order:
- foreman_proxy
- puppet
:low_priority_modules:
- foreman_proxy_plugin

# If using the Debian ruby-kafo package, uncomment this
# :kafo_modules_dir: /usr/lib/ruby/vendor_ruby/kafo/modules

# Unused, but remains present for older config migrations
:mapping: {}
25 changes: 25 additions & 0 deletions hooks/pre_migrations/rename_naming_convention.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Previously some migrations followed the convention of +%y%m%d%H%M%S as a date
# prefix and dashes. At some point the migrations were changed to +%Y%m%d%H%M%S
migrations_dir = kafo.config.migrations_dir
migrations = Kafo::Migrations.new(migrations_dir)

changed = []
migrations.applied.each_with_index do |item, index|
old_filename = File.join(migrations_dir, "#{item}.rb")
next if File.exist?(old_filename)

["20#{item.gsub('-', '_')}", item.gsub('-', '_')].each do |new_name|
new_filename = File.join(migrations_dir, "#{new_name}.rb")
if File.exist?(new_filename)
migrations.applied[index] = new_name
changed << item
end
end
end

if changed.any?
migrations.store_applied
Kafo.request_config_reload
end

changed
111 changes: 111 additions & 0 deletions spec/hooks/rename_naming_convention.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
require 'spec_helper'
require 'tmpdir'
require 'fileutils'
require 'kafo/hook_context'

describe 'rename_naming_convention' do
let(:config) { instance_double('Kafo::Configuration') }
let(:kafo) { instance_double('Kafo::KafoConfigure') }
let(:logger) { instance_double('Logger') }
let(:migrations_dir) { Dir.mktmpdir('installer-rename_naming_convention-') }
let(:applied) { File.join(migrations_dir, '.applied') }
let(:new_migration_name) { '20201217175955_stricter_ciphers' }

subject do
file = 'hooks/pre_migrations/rename_naming_convention.rb'
hook = File.read(file)
hook_block = proc { instance_eval(hook, file, 1) }
Kafo::HookContext.execute(kafo, logger, &hook_block)
end

before do
allow(kafo).to receive(:config).and_return(config)
allow(config).to receive(:migrations_dir).and_return(migrations_dir)
allow(Kafo).to receive(:request_config_reload)
end

after do
FileUtils.rm_r(migrations_dir)
end

describe 'no migrations' do
it do
expect(subject).to match_array([])
expect(Kafo).not_to have_received(:request_config_reload)
end
end

describe 'with migrations' do
before do
FileUtils.touch(File.join(migrations_dir, "#{new_migration_name}.rb"))
end

context 'without an applied' do
it do
expect(subject).to match_array([])
expect(Kafo).not_to have_received(:request_config_reload)
end
end

context 'with an applied' do
before do
File.write(applied, applied_content.to_yaml)
end

context 'that is empty' do
let(:applied_content) { [] }

it do
expect(subject).to match_array([])
expect(Kafo::Migrations.new(migrations_dir).applied).to match_array([])
expect(Kafo).not_to have_received(:request_config_reload)
end
end

context 'that has a renamed migration' do
let(:applied_content) { ['201217175955-stricter-ciphers'] }

it do
expect(subject).to match_array(['201217175955-stricter-ciphers'])
expect(Kafo::Migrations.new(migrations_dir).applied).to match_array([new_migration_name])
expect(Kafo).to have_received(:request_config_reload).once
end
end

context 'that has multiple renamed migrations' do
# This just renames dashes to underscores, already has YYYY
before do
FileUtils.touch(File.join(migrations_dir, "20210331121715_clear_puppetserver_nil_metrics.rb"))
end

let(:applied_content) { ['20210331121715_clear_puppetserver-nil-metrics', '201217175955-stricter-ciphers'] }

it do
expect(subject).to match_array(['20210331121715_clear_puppetserver-nil-metrics', '201217175955-stricter-ciphers'])
expect(Kafo::Migrations.new(migrations_dir).applied).to match_array(['20210331121715_clear_puppetserver_nil_metrics', new_migration_name])
expect(Kafo).to have_received(:request_config_reload).once
end
end

context 'that has a removed migration' do
let(:applied_content) { ['has-been-removed'] }

it do
expect(subject).to match_array([])
expect(Kafo::Migrations.new(migrations_dir).applied).to match_array(['has-been-removed'])
expect(Kafo).not_to have_received(:request_config_reload)
end
end

context 'that is up to date' do
let(:applied_content) { [new_migration_name] }

it do
expect(subject).to match_array([])
expect(Kafo::Migrations.new(migrations_dir).applied).to match_array([new_migration_name])
expect(Kafo).not_to have_received(:request_config_reload)
end
end
end
end
end