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

Use Kafo's migration DSL #700

Draft
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::ansible'] ||= false
add_module('foreman::plugin::ansible')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::memcache'] ||= false
add_module('foreman::plugin::memcache')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::cockpit'] ||= false
add_module('foreman::plugin::cockpit')
2 changes: 1 addition & 1 deletion config/foreman.migrations/20160405122117_passenger_ruby.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Redetermine the value of passenger_ruby, as it changed on Debian in puppet-foreman f9329b6
answers['foreman'].delete('passenger_ruby') if answers['foreman']
unset_answer('foreman', 'passenger_ruby')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::discovery'] ||= false
add_module('foreman_proxy::plugin::discovery')
10 changes: 6 additions & 4 deletions config/foreman.migrations/20160420224417_puppet_autosign.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Redetermine the value of autosign, as it changed from string/boolean to path/boolean
# in puppet-puppet a2325f1 and was deleted from puppet-foreman_proxy 9f3c9aa
if answers['puppet']
current_autosign = answers['puppet']['autosign']
answers['puppet'].delete('autosign') unless !!current_autosign == current_autosign # rubocop:disable Style/DoubleNegation
migrate_module('puppet') do |mod|
current_autosign = mod['autosign']
unless current_autosign.is_a?(TrueClass) || current_autosign.is_a?(FalseClass)
mod.unset_answer('autosign')
end
end
answers['foreman_proxy'].delete('autosign_location') if answers['foreman_proxy']
unset_answer('foreman_proxy', 'autosign_location')
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Rename foreman_proxy puppetrun parameters to puppet
# https://github.com/theforeman/puppet-foreman_proxy/commit/c26cac15
answers['foreman_proxy']['puppet'] = answers['foreman_proxy'].delete('puppetrun') if answers['foreman_proxy'] && answers['foreman_proxy'].has_key?('puppetrun')
answers['foreman_proxy']['puppet_listen_on'] = answers['foreman_proxy'].delete('puppetrun_listen_on') if answers['foreman_proxy'] && answers['foreman_proxy'].has_key?('puppetrun_listen_on')
migrate_module('foreman_proxy') do |mod|
mod.rename_parameter('puppetrun', 'puppet')
mod.rename_parameter('puppetrun_listen_on', 'puppet_listen_on')
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Rename foreman_proxy provider "puppetssh" to "ssh"
# http://projects.theforeman.org/issues/15323
answers['foreman_proxy']['puppetrun_provider'] = 'ssh' if answers['foreman_proxy'] && answers['foreman_proxy']['puppetrun_provider'] == 'puppetssh'
migrate_module('foreman_proxy') do |mod|
mod['puppetrun_provider'] = 'ssh' if mod['puppetrun_provider'] == 'puppetssh'
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::expire_hosts'] ||= false
add_module('foreman::plugin::expire_hosts')
2 changes: 1 addition & 1 deletion config/foreman.migrations/20160615132930_foreman_azure.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::azure'] ||= false
add_module('foreman::plugin::azure')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::ovirt_provision'] ||= false
add_module('foreman::plugin::ovirt_provision')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::host_extra_validator'] ||= false
add_module('foreman::plugin::host_extra_validator')
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# rename foreman environment parameter to rails_env
# https://github.com/theforeman/puppet-foreman_proxy/commit/d239f0b
answers['foreman']['rails_env'] = answers['foreman'].delete('environment') if answers['foreman'] && answers['foreman'].has_key?('environment')
migrate_module('foreman') do |mod|
mod.rename_parameter('environment', 'rails_env')
end
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
answers['foreman::plugin::remote_execution'] ||= false
answers['foreman_proxy::plugin::remote_execution::ssh'] ||= false
add_module('foreman::plugin::remote_execution')
add_module('foreman_proxy::plugin::remote_execution::ssh')
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
if answers['foreman_proxy']
root = answers['foreman_proxy']['tftp_root']
if answers['foreman_proxy']['tftp_dirs']
dirs = answers['foreman_proxy']['tftp_dirs']
migrate_module('foreman_proxy') do |mod|
root = mod['tftp_root']
if (dirs = mod['tftp_dirs'])
dirs << "#{root}/grub"
dirs << "#{root}/grub2"
dirs.uniq!
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Redetermine the value of API whitelists, as it changed
# in puppet-puppet f9b4e87cd855d7d5d0bbf3a1831b5daf22cdb413
if answers['puppet']
answers['puppet'].delete('server_admin_api_whitelist')
answers['puppet'].delete('server_ca_client_whitelist')
migrate_module('puppet') do |mod|
mod.delete('server_admin_api_whitelist')
mod.delete('server_ca_client_whitelist')
end
4 changes: 2 additions & 2 deletions config/foreman.migrations/20160919172842_infoblox.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
answers['foreman_proxy::plugin::dns::infoblox'] ||= false
answers['foreman_proxy::plugin::dhcp::infoblox'] ||= false
add_module('foreman_proxy::plugin::dns::infoblox')
add_module('foreman_proxy::plugin::dhcp::infoblox')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::ansible'] ||= false
add_module('foreman_proxy::plugin::ansible')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::cli::openscap'] ||= false
add_module('foreman::cli::openscap')
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
answers['foreman']['email_config_method'] = 'database' if answers['foreman']
migrate_module('foreman') do |mod|
mod['email_config_method'] = 'database'
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::monitoring'] ||= false
add_module('foreman::plugin::monitoring')
2 changes: 1 addition & 1 deletion config/foreman.migrations/20170111083525_foreman_omaha.rb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::omaha'] ||= false
add_module('foreman::plugin::omaha')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::monitoring'] ||= false
add_module('foreman_proxy::plugin::monitoring')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::omaha'] ||= false
add_module('foreman_proxy::plugin::omaha')
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# false is no longer a valid value, the param should be undef/nil to be disabled
answers['foreman_proxy']['dhcp_range'] = nil if answers['foreman_proxy'] && answers['foreman_proxy']['dhcp_range'] == false
unset_answer('foreman_proxy', 'dhcp_range') if get_answer('foreman_proxy', 'dhcp_range') == false
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
answers['foreman_proxy']['realm_split_config_files'] = true if answers['foreman_proxy']
migrate_module('foreman_proxy') do |mod|
mod['realm_split_config_files'] = true
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::dhcp::remote_isc'] ||= false
add_module('foreman_proxy::plugin::dhcp::remote_isc')
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if answers['foreman_proxy'] && answers['foreman_proxy']['bind_host'].is_a?(String)
answers['foreman_proxy']['bind_host'] = [answers['foreman_proxy']['bind_host']]
migrate_module('foreman_proxy') do |mod|
if mod['bind_host'].is_a?(String)
mod['bind_host'] = [mod['bind_host']]
end
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::snapshot_management'] ||= false
add_module('foreman::plugin::snapshot_management')
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
if answers['foreman'].is_a?(Hash) && answers['foreman'].key?('jobs_service') && answers['foreman']['jobs_service'].nil?
answers['foreman'].delete('jobs_service')
end
unset_answer('foreman', 'jobs_service') if get_answer('foreman', 'jobs_service').nil?
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
plugin_conf = answers['foreman_proxy::plugin::remote_execution::ssh']
if plugin_conf
if plugin_conf.is_a?(Hash) && plugin_conf['ssh_identity_dir'] == '/usr/share/foreman-proxy/.ssh'
answers['foreman_proxy::plugin::remote_execution::ssh']['ssh_identity_dir'] = '/var/lib/foreman-proxy/ssh'
elsif !plugin_conf.is_a?(Hash)
answers['foreman_proxy::plugin::remote_execution::ssh'] = { 'ssh_identity_dir' => '/var/lib/foreman-proxy/ssh' }
migrate_module('foreman_proxy::plugin::remote_execution::ssh'] do |mod|
if mod['ssh_identity_dir'] == '/usr/share/foreman-proxy/.ssh' || mod['ssh_identity_dir'].nil?
mod['ssh_identity_dir'] = '/var/lib/foreman-proxy/ssh'
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
mod = answers['foreman']
if mod.is_a?(Hash)
migrate_module('foreman') do |mod|
['admin_username', 'admin_password', 'admin_first_name', 'admin_last_name', 'admin_email'].each do |var|
mod["initial_#{var}"] = mod[var] unless mod[var].nil?
mod.rename_parameter(var, "initial_#{var}")
end
end
8 changes: 4 additions & 4 deletions config/foreman.migrations/20181113150224-add-cli-plugins.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
answers['foreman::cli::discovery'] ||= false
answers['foreman::cli::remote_execution'] ||= false
answers['foreman::cli::tasks'] ||= false
answers['foreman::cli::templates'] ||= false
add_module('foreman::cli::discovery')
add_module('foreman::cli::remote_execution')
add_module('foreman::cli::tasks')
add_module('foreman::cli::templates')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::cli::ansible'] ||= false
add_module('foreman::cli::ansible')
Original file line number Diff line number Diff line change
@@ -1,74 +1,10 @@
DELETED = {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can be blamed for this. Kafo already removed unknown keys and this was never needed in the first place.

'foreman' => [
'custom_repo',
'dynflow_in_core',
'email_conf',
'email_config_method',
'email_source',
'puppet_home',
'puppet_ssldir',
],
'foreman_proxy' => [
'custom_repo',
'puppetca_modular',
'realm_split_config_files',
'use_autosignfile',
],
'foreman_proxy::plugin::dhcp::infoblox' => [
'use_ranges',
],
'puppet' => [
'agent_template',
'main_template',
'server_app_root',
'server_ca_proxy',
'server_directory_environments',
'server_dynamic_environments',
'server_environments',
'server_http_allow',
'server_httpd_service',
'server_implementation',
'server_main_template',
'server_passenger',
'server_passenger_min_instances',
'server_passenger_pre_start',
'server_passenger_ruby',
'server_rack_arguments',
'server_service_fallback',
'server_template',
],
}.freeze

CLEAR = {
'foreman' => [
'authentication',
'locations_enabled',
'organizations_enabled',
'repo',
],
'foreman_proxy' => [
'repo',
],
}.freeze

DELETED.each do |mod, parameters|
mod_answers = answers[mod]
next unless mod_answers.is_a?(Hash)

parameters.each do |parameter|
mod_answers.delete(parameter)
end
end

CLEAR.each do |mod, parameters|
mod_answers = answers[mod]
next unless mod_answers.is_a?(Hash)

parameters.each do |parameter|
mod_answers[parameter] = nil if mod_answers[parameter]
migrate_module('foreman') do |mod|
['authentication', 'locations_enabled', 'organizations_enabled', 'repo'].each do |parameter|
mod.unset_answer(parameter)
end
end

if (mod_answers = answers['foreman_proxy'])
mod_answers['dhcp_gateway'] = nil if mod_answers['dhcp_gateway'] == '192.168.100.1'
migrate_module('foreman_proxy') do |mod|
mod.unset_answer('repo')
mod.unset_answer('dhcp_gateway') if mod['dhcp_gateway'] == '192.168.100.1'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about some more advanced DSL here:

mod.migrate_answer('dhcp_gateway') do |param|
  param.unset_answer if param.value == '192.168.100.1'
end

However, I didn't want to overload things too soon.

end
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
['foreman::plugin::docker', 'foreman_proxy::plugin::abrt'].each do |plugin|
answers.delete(plugin) if answers.include?(plugin)
end
delete_module('foreman::plugin::docker')
delete_module('foreman_proxy::plugin::abrt')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::kubevirt'] ||= false
add_module('foreman::plugin::kubevirt')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::cli::kubevirt'] ||= false
add_module('foreman::cli::kubevirt')
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
['foreman::plugin::cockpit'].each do |plugin|
answers.delete(plugin) if answers.include?(plugin)
end
delete_module('foreman::plugin::cockpit')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::remote_execution::cockpit'] ||= false
add_module('foreman::plugin::remote_execution::cockpit')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::cli::azure'] ||= false
add_module('foreman::cli::azure')
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
if answers['foreman_proxy'].is_a?(Hash) &&
answers['foreman_proxy']['bind_host'].is_a?(Array) &&
answers['foreman_proxy']['bind_host'].include?('::') &&
facts[:os][:release][:major] == '7' &&
facts[:os][:family] == 'RedHat'
answers['foreman_proxy'].delete('bind_host')
migrate_module('foreman_proxy') do |mod|
if mod['bind_host'].is_a?(Array) && mod['bind_host'].include?('::') && facts[:os][:release][:major] == '7' && facts[:os][:family] == 'RedHat'
mod.unset_answer('bind_host')
end
end
4 changes: 3 additions & 1 deletion config/foreman.migrations/20200305172758_enable_puma.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
answers['foreman']['passenger'] = false if answers['foreman'].is_a?(Hash) && answers['foreman']['passenger']
migrate_module('foreman') do |mod|
mod['passenger'] = false if mod['passenger']
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::leapp'] ||= false
add_module('foreman::plugin::leapp')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::statistics'] ||= false
add_module('foreman::plugin::statistics')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::column_view'] ||= false
add_module('foreman::plugin::column_view')
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
mod = answers['foreman']
layout_key = 'logging_layout'
if mod.is_a?(Hash) && mod[layout_key] == 'pattern'
mod[layout_key] = 'multiline_request_pattern'
migrate_module('foreman') do |mod|
layout_key = 'logging_layout'
mod[layout_key] = 'multiline_request_pattern' if mod[layout_key] == 'pattern'
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if answers['foreman_proxy'].is_a?(Hash) && facts[:os][:family] == 'Debian'
answers['foreman_proxy']['dhcp_manage_acls'] ||= true if answers['foreman_proxy'].key?('dhcp_manage_acls')
migrate_module('foreman_proxy') do |mod|
if facts[:os][:family] == 'Debian'
mod['dhcp_manage_acls'] ||= true if mod.key?('dhcp_manage_acls')
end
end
4 changes: 1 addition & 3 deletions config/foreman.migrations/20201020000326_drop_rackspace.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
if answers.key?('foreman::compute::rackspace')
answers.delete('foreman::compute::rackspace')
end
remove_module('foreman::compute::rackspace')
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
if answers.key?('foreman::plugin::digitalocean')
answers.delete('foreman::plugin::digitalocean')
end
remove_module('foreman::plugin::digitalocean')
6 changes: 4 additions & 2 deletions config/foreman.migrations/20201224125100_ansible_ssh_args.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# migrate the default
if answers['foreman_proxy::plugin::ansible'].is_a?(Hash) && answers['foreman_proxy::plugin::ansible']['ssh_args'] == '-o ProxyCommand=none'
answers['foreman_proxy::plugin::ansible']['ssh_args'] = '-o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s'
migrate_module('foreman_proxy::plugin::ansible') do |mod|
if mod['ssh_args'] == '-o ProxyCommand=none'
mod['ssh_args'] = '-o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s'
end
end
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers.delete('foreman_proxy::plugin::pulp')
remove_module('foreman_proxy::plugin::pulp')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman::plugin::webhooks'] ||= false
add_module('foreman::plugin::webhooks')
Original file line number Diff line number Diff line change
@@ -1 +1 @@
answers['foreman_proxy::plugin::shellhooks'] ||= false
add_module('foreman_proxy::plugin::shellhooks')
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
if answers['foreman::plugin::tasks'].is_a?(Hash) && !answers['foreman::plugin::tasks'].key?('backup')
answers['foreman::plugin::tasks']['backup'] = true
migrate_module('foreman::plugin::tasks') do |mod|
mod['backup'] = true unless mod.key?('backup')
end
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
if answers['puppet'].is_a?(Hash)
answers['puppet'].delete('server_puppetserver_metrics') if answers['puppet']['server_puppetserver_metrics'].nil?
end
unset_answer('puppet', 'server_puppetserver_metrics') if get_answer('puppet', 'server_puppetserver_metrics').nil?
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
if answers['foreman'].is_a?(Hash)
if answers['foreman']['user_groups'] && answers['foreman']['user_groups'].include?('puppet')
answers['foreman']['user_groups'].delete('puppet')
migrate_module('foreman') do |mod|
if mod['user_groups'] && mod['user_groups'].include?('puppet')
mod['user_groups'].delete('puppet')
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
unless answers.key?('foreman::plugin::puppet')
answers['foreman::plugin::puppet'] = true
end
add_module('foreman::plugin::puppet', true)