From 8e5369f99dd00b4e07bd6f11756e8fef7efd83b0 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Wed, 21 Jul 2021 20:27:07 +0200 Subject: [PATCH] Use Kafo's migration DSL This rewrites most Foreman migrations to a new migration DSL. The DSL decouples from the actual answer file structure and is more expressive. Technically the DSL doesn't exist, but this at least makes sure that it's possible to express everything with the DSL I had in mind. --- .../20160405121109_foreman_ansible.rb | 2 +- .../20160405121739_foreman_memcache.rb | 2 +- .../20160405121855_foreman_cockpit.rb | 2 +- .../20160405122117_passenger_ruby.rb | 2 +- .../20160405135043_foreman_proxy_discovery.rb | 2 +- .../20160420224417_puppet_autosign.rb | 10 ++- ...18125928_foreman_proxy_puppetrun_rename.rb | 6 +- ...07133050_foreman_proxy_puppetssh_rename.rb | 4 +- .../20160614145332_foreman_expire_hosts.rb | 2 +- .../20160615132930_foreman_azure.rb | 2 +- .../20160705103630_readd_ovirt_provision.rb | 2 +- ...0708111111_foreman_host_extra_validator.rb | 2 +- ...20160722161820_environment_to_rails_env.rb | 4 +- ...20160725151907_foreman_remote_execution.rb | 4 +- ...20160831180000_foreman_proxy_tftp_grub2.rb | 7 +- .../20160906121542_puppetserver_whitelist.rb | 6 +- .../20160919172842_infoblox.rb | 4 +- .../20160919173201_smart_proxy_ansible.rb | 2 +- .../20161122124500_hammer_cli_openscap.rb | 2 +- ...61125153500_foreman_email_config_method.rb | 4 +- .../20170111083507_foreman_monitoring.rb | 2 +- .../20170111083525_foreman_omaha.rb | 2 +- .../20170111083555_smart_proxy_monitoring.rb | 2 +- .../20170111083612_smart_proxy_omaha.rb | 2 +- ...18105627_foreman_proxy_dhcp_range_false.rb | 2 +- ...23300_foreman_proxy_realm_split_configs.rb | 4 +- ...331081217_foreman_proxy_dhcp_remote_isc.rb | 2 +- ...405155121_foreman_proxy_bind_host_array.rb | 6 +- ...80801104012_foreman_snapshot_management.rb | 2 +- .../20180821005330_foreman_jobs_service.rb | 4 +- .../20180829115142_change_rex_ssh_dir.rb | 9 +-- .../20181015123542_migrate_seed_params.rb | 5 +- .../20181113150224-add-cli-plugins.rb | 8 +- .../20181114569402_add_ansible_cli.rb | 2 +- .../20190111180118_delete_removed_settings.rb | 76 ++----------------- ...190423154755_remove-docker-abrt-plugins.rb | 5 +- .../20190502234130_foreman_kubevirt.rb | 2 +- .../20190520122507_hammer_cli_kubevirt.rb | 2 +- .../20190903120000_remove-cockpit-plugin.rb | 4 +- .../20191029130301_add_rex-cockpit.rb | 2 +- .../20191121124856_hammer_cli_azure.rb | 2 +- ...113133837_reset_bind-host-foreman-proxy.rb | 10 +-- .../20200305172758_enable_puma.rb | 4 +- .../20200504073814_add_foreman_leapp.rb | 2 +- .../20200803163936_add_statistics-plugin.rb | 2 +- .../20200803185054_add_column-view-plugin.rb | 2 +- .../20200805102253_change_logging_layout.rb | 7 +- .../20200909151007_manage_acls_on_debian.rb | 6 +- .../20201020000326_drop_rackspace.rb | 4 +- ...201207225700_remove_digitalocean-plugin.rb | 4 +- .../20201224125100_ansible_ssh_args.rb | 6 +- ...29165012_drop_foreman_proxy_plugin_pulp.rb | 2 +- .../20210304102210_add_webhooks_plugin.rb | 2 +- ...10304102446_add_proxy_shellhooks_plugin.rb | 2 +- .../20210323145821_foreman_tasks-backup.rb | 4 +- ...31121715_clear_puppetserver-nil-metrics.rb | 4 +- ...142707_dynamic_puppet_in_foreman_groups.rb | 6 +- .../20210708144320_add_foreman_puppet.rb | 4 +- 58 files changed, 111 insertions(+), 176 deletions(-) diff --git a/config/foreman.migrations/20160405121109_foreman_ansible.rb b/config/foreman.migrations/20160405121109_foreman_ansible.rb index 34dc0f32..bfbb2d28 100644 --- a/config/foreman.migrations/20160405121109_foreman_ansible.rb +++ b/config/foreman.migrations/20160405121109_foreman_ansible.rb @@ -1 +1 @@ -answers['foreman::plugin::ansible'] ||= false +add_module('foreman::plugin::ansible') diff --git a/config/foreman.migrations/20160405121739_foreman_memcache.rb b/config/foreman.migrations/20160405121739_foreman_memcache.rb index 8f5012a4..654afebe 100644 --- a/config/foreman.migrations/20160405121739_foreman_memcache.rb +++ b/config/foreman.migrations/20160405121739_foreman_memcache.rb @@ -1 +1 @@ -answers['foreman::plugin::memcache'] ||= false +add_module('foreman::plugin::memcache') diff --git a/config/foreman.migrations/20160405121855_foreman_cockpit.rb b/config/foreman.migrations/20160405121855_foreman_cockpit.rb index 32c24255..7b399830 100644 --- a/config/foreman.migrations/20160405121855_foreman_cockpit.rb +++ b/config/foreman.migrations/20160405121855_foreman_cockpit.rb @@ -1 +1 @@ -answers['foreman::plugin::cockpit'] ||= false +add_module('foreman::plugin::cockpit') diff --git a/config/foreman.migrations/20160405122117_passenger_ruby.rb b/config/foreman.migrations/20160405122117_passenger_ruby.rb index b7879d9d..22f7f5d4 100644 --- a/config/foreman.migrations/20160405122117_passenger_ruby.rb +++ b/config/foreman.migrations/20160405122117_passenger_ruby.rb @@ -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') diff --git a/config/foreman.migrations/20160405135043_foreman_proxy_discovery.rb b/config/foreman.migrations/20160405135043_foreman_proxy_discovery.rb index 7b18c3ab..870805d2 100644 --- a/config/foreman.migrations/20160405135043_foreman_proxy_discovery.rb +++ b/config/foreman.migrations/20160405135043_foreman_proxy_discovery.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::discovery'] ||= false +add_module('foreman_proxy::plugin::discovery') diff --git a/config/foreman.migrations/20160420224417_puppet_autosign.rb b/config/foreman.migrations/20160420224417_puppet_autosign.rb index 828fc9bb..6a0e79d2 100644 --- a/config/foreman.migrations/20160420224417_puppet_autosign.rb +++ b/config/foreman.migrations/20160420224417_puppet_autosign.rb @@ -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') diff --git a/config/foreman.migrations/20160518125928_foreman_proxy_puppetrun_rename.rb b/config/foreman.migrations/20160518125928_foreman_proxy_puppetrun_rename.rb index 0a6f33a1..522ef065 100644 --- a/config/foreman.migrations/20160518125928_foreman_proxy_puppetrun_rename.rb +++ b/config/foreman.migrations/20160518125928_foreman_proxy_puppetrun_rename.rb @@ -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 diff --git a/config/foreman.migrations/20160607133050_foreman_proxy_puppetssh_rename.rb b/config/foreman.migrations/20160607133050_foreman_proxy_puppetssh_rename.rb index fdbaa9e8..6c8ff08a 100644 --- a/config/foreman.migrations/20160607133050_foreman_proxy_puppetssh_rename.rb +++ b/config/foreman.migrations/20160607133050_foreman_proxy_puppetssh_rename.rb @@ -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 diff --git a/config/foreman.migrations/20160614145332_foreman_expire_hosts.rb b/config/foreman.migrations/20160614145332_foreman_expire_hosts.rb index efee4b0f..b1c19cff 100644 --- a/config/foreman.migrations/20160614145332_foreman_expire_hosts.rb +++ b/config/foreman.migrations/20160614145332_foreman_expire_hosts.rb @@ -1 +1 @@ -answers['foreman::plugin::expire_hosts'] ||= false +add_module('foreman::plugin::expire_hosts') diff --git a/config/foreman.migrations/20160615132930_foreman_azure.rb b/config/foreman.migrations/20160615132930_foreman_azure.rb index 0af3a466..7d8ac4d7 100644 --- a/config/foreman.migrations/20160615132930_foreman_azure.rb +++ b/config/foreman.migrations/20160615132930_foreman_azure.rb @@ -1 +1 @@ -answers['foreman::plugin::azure'] ||= false +add_module('foreman::plugin::azure') diff --git a/config/foreman.migrations/20160705103630_readd_ovirt_provision.rb b/config/foreman.migrations/20160705103630_readd_ovirt_provision.rb index 246fb67f..a6f11589 100644 --- a/config/foreman.migrations/20160705103630_readd_ovirt_provision.rb +++ b/config/foreman.migrations/20160705103630_readd_ovirt_provision.rb @@ -1 +1 @@ -answers['foreman::plugin::ovirt_provision'] ||= false +add_module('foreman::plugin::ovirt_provision') diff --git a/config/foreman.migrations/20160708111111_foreman_host_extra_validator.rb b/config/foreman.migrations/20160708111111_foreman_host_extra_validator.rb index 049a6b24..6383430a 100644 --- a/config/foreman.migrations/20160708111111_foreman_host_extra_validator.rb +++ b/config/foreman.migrations/20160708111111_foreman_host_extra_validator.rb @@ -1 +1 @@ -answers['foreman::plugin::host_extra_validator'] ||= false +add_module('foreman::plugin::host_extra_validator') diff --git a/config/foreman.migrations/20160722161820_environment_to_rails_env.rb b/config/foreman.migrations/20160722161820_environment_to_rails_env.rb index 0818a43b..ffc93e4e 100644 --- a/config/foreman.migrations/20160722161820_environment_to_rails_env.rb +++ b/config/foreman.migrations/20160722161820_environment_to_rails_env.rb @@ -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 diff --git a/config/foreman.migrations/20160725151907_foreman_remote_execution.rb b/config/foreman.migrations/20160725151907_foreman_remote_execution.rb index 3f57f326..2a745b57 100644 --- a/config/foreman.migrations/20160725151907_foreman_remote_execution.rb +++ b/config/foreman.migrations/20160725151907_foreman_remote_execution.rb @@ -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') diff --git a/config/foreman.migrations/20160831180000_foreman_proxy_tftp_grub2.rb b/config/foreman.migrations/20160831180000_foreman_proxy_tftp_grub2.rb index bb56f881..c224f295 100644 --- a/config/foreman.migrations/20160831180000_foreman_proxy_tftp_grub2.rb +++ b/config/foreman.migrations/20160831180000_foreman_proxy_tftp_grub2.rb @@ -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! diff --git a/config/foreman.migrations/20160906121542_puppetserver_whitelist.rb b/config/foreman.migrations/20160906121542_puppetserver_whitelist.rb index 0d477b4c..483e2c7c 100644 --- a/config/foreman.migrations/20160906121542_puppetserver_whitelist.rb +++ b/config/foreman.migrations/20160906121542_puppetserver_whitelist.rb @@ -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 diff --git a/config/foreman.migrations/20160919172842_infoblox.rb b/config/foreman.migrations/20160919172842_infoblox.rb index df40bd80..22d3aa69 100644 --- a/config/foreman.migrations/20160919172842_infoblox.rb +++ b/config/foreman.migrations/20160919172842_infoblox.rb @@ -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') diff --git a/config/foreman.migrations/20160919173201_smart_proxy_ansible.rb b/config/foreman.migrations/20160919173201_smart_proxy_ansible.rb index c2398c32..9bb3644d 100644 --- a/config/foreman.migrations/20160919173201_smart_proxy_ansible.rb +++ b/config/foreman.migrations/20160919173201_smart_proxy_ansible.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::ansible'] ||= false +add_module('foreman_proxy::plugin::ansible') diff --git a/config/foreman.migrations/20161122124500_hammer_cli_openscap.rb b/config/foreman.migrations/20161122124500_hammer_cli_openscap.rb index f2327129..d8595521 100644 --- a/config/foreman.migrations/20161122124500_hammer_cli_openscap.rb +++ b/config/foreman.migrations/20161122124500_hammer_cli_openscap.rb @@ -1 +1 @@ -answers['foreman::cli::openscap'] ||= false +add_module('foreman::cli::openscap') diff --git a/config/foreman.migrations/20161125153500_foreman_email_config_method.rb b/config/foreman.migrations/20161125153500_foreman_email_config_method.rb index ccdd3658..465beb8b 100644 --- a/config/foreman.migrations/20161125153500_foreman_email_config_method.rb +++ b/config/foreman.migrations/20161125153500_foreman_email_config_method.rb @@ -1 +1,3 @@ -answers['foreman']['email_config_method'] = 'database' if answers['foreman'] +migrate_module('foreman') do |mod| + mod['email_config_method'] = 'database' +end diff --git a/config/foreman.migrations/20170111083507_foreman_monitoring.rb b/config/foreman.migrations/20170111083507_foreman_monitoring.rb index f4e56bc5..e2743ccf 100644 --- a/config/foreman.migrations/20170111083507_foreman_monitoring.rb +++ b/config/foreman.migrations/20170111083507_foreman_monitoring.rb @@ -1 +1 @@ -answers['foreman::plugin::monitoring'] ||= false +add_module('foreman::plugin::monitoring') diff --git a/config/foreman.migrations/20170111083525_foreman_omaha.rb b/config/foreman.migrations/20170111083525_foreman_omaha.rb index 5ccaa1cd..1c73d135 100644 --- a/config/foreman.migrations/20170111083525_foreman_omaha.rb +++ b/config/foreman.migrations/20170111083525_foreman_omaha.rb @@ -1 +1 @@ -answers['foreman::plugin::omaha'] ||= false +add_module('foreman::plugin::omaha') diff --git a/config/foreman.migrations/20170111083555_smart_proxy_monitoring.rb b/config/foreman.migrations/20170111083555_smart_proxy_monitoring.rb index c07dee1d..b62184b5 100644 --- a/config/foreman.migrations/20170111083555_smart_proxy_monitoring.rb +++ b/config/foreman.migrations/20170111083555_smart_proxy_monitoring.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::monitoring'] ||= false +add_module('foreman_proxy::plugin::monitoring') diff --git a/config/foreman.migrations/20170111083612_smart_proxy_omaha.rb b/config/foreman.migrations/20170111083612_smart_proxy_omaha.rb index 951e017b..05e7d73c 100644 --- a/config/foreman.migrations/20170111083612_smart_proxy_omaha.rb +++ b/config/foreman.migrations/20170111083612_smart_proxy_omaha.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::omaha'] ||= false +add_module('foreman_proxy::plugin::omaha') diff --git a/config/foreman.migrations/20170118105627_foreman_proxy_dhcp_range_false.rb b/config/foreman.migrations/20170118105627_foreman_proxy_dhcp_range_false.rb index 8393fde8..da51045e 100644 --- a/config/foreman.migrations/20170118105627_foreman_proxy_dhcp_range_false.rb +++ b/config/foreman.migrations/20170118105627_foreman_proxy_dhcp_range_false.rb @@ -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 diff --git a/config/foreman.migrations/20170213123300_foreman_proxy_realm_split_configs.rb b/config/foreman.migrations/20170213123300_foreman_proxy_realm_split_configs.rb index 91406a4b..0bf3d836 100644 --- a/config/foreman.migrations/20170213123300_foreman_proxy_realm_split_configs.rb +++ b/config/foreman.migrations/20170213123300_foreman_proxy_realm_split_configs.rb @@ -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 diff --git a/config/foreman.migrations/20170331081217_foreman_proxy_dhcp_remote_isc.rb b/config/foreman.migrations/20170331081217_foreman_proxy_dhcp_remote_isc.rb index c6a1cb8a..c38974a7 100644 --- a/config/foreman.migrations/20170331081217_foreman_proxy_dhcp_remote_isc.rb +++ b/config/foreman.migrations/20170331081217_foreman_proxy_dhcp_remote_isc.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::dhcp::remote_isc'] ||= false +add_module('foreman_proxy::plugin::dhcp::remote_isc') diff --git a/config/foreman.migrations/20170405155121_foreman_proxy_bind_host_array.rb b/config/foreman.migrations/20170405155121_foreman_proxy_bind_host_array.rb index 85405c32..6677bcc5 100644 --- a/config/foreman.migrations/20170405155121_foreman_proxy_bind_host_array.rb +++ b/config/foreman.migrations/20170405155121_foreman_proxy_bind_host_array.rb @@ -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 diff --git a/config/foreman.migrations/20180801104012_foreman_snapshot_management.rb b/config/foreman.migrations/20180801104012_foreman_snapshot_management.rb index 130a88a4..ca73542d 100644 --- a/config/foreman.migrations/20180801104012_foreman_snapshot_management.rb +++ b/config/foreman.migrations/20180801104012_foreman_snapshot_management.rb @@ -1 +1 @@ -answers['foreman::plugin::snapshot_management'] ||= false +add_module('foreman::plugin::snapshot_management') diff --git a/config/foreman.migrations/20180821005330_foreman_jobs_service.rb b/config/foreman.migrations/20180821005330_foreman_jobs_service.rb index 31f8336a..93da59d9 100644 --- a/config/foreman.migrations/20180821005330_foreman_jobs_service.rb +++ b/config/foreman.migrations/20180821005330_foreman_jobs_service.rb @@ -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? diff --git a/config/foreman.migrations/20180829115142_change_rex_ssh_dir.rb b/config/foreman.migrations/20180829115142_change_rex_ssh_dir.rb index d9732ea5..5cfbfe55 100644 --- a/config/foreman.migrations/20180829115142_change_rex_ssh_dir.rb +++ b/config/foreman.migrations/20180829115142_change_rex_ssh_dir.rb @@ -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 diff --git a/config/foreman.migrations/20181015123542_migrate_seed_params.rb b/config/foreman.migrations/20181015123542_migrate_seed_params.rb index e3e89a05..681c4e49 100644 --- a/config/foreman.migrations/20181015123542_migrate_seed_params.rb +++ b/config/foreman.migrations/20181015123542_migrate_seed_params.rb @@ -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 diff --git a/config/foreman.migrations/20181113150224-add-cli-plugins.rb b/config/foreman.migrations/20181113150224-add-cli-plugins.rb index baa01dbc..5e180925 100644 --- a/config/foreman.migrations/20181113150224-add-cli-plugins.rb +++ b/config/foreman.migrations/20181113150224-add-cli-plugins.rb @@ -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') diff --git a/config/foreman.migrations/20181114569402_add_ansible_cli.rb b/config/foreman.migrations/20181114569402_add_ansible_cli.rb index 4329f54e..023f3f08 100644 --- a/config/foreman.migrations/20181114569402_add_ansible_cli.rb +++ b/config/foreman.migrations/20181114569402_add_ansible_cli.rb @@ -1 +1 @@ -answers['foreman::cli::ansible'] ||= false +add_module('foreman::cli::ansible') diff --git a/config/foreman.migrations/20190111180118_delete_removed_settings.rb b/config/foreman.migrations/20190111180118_delete_removed_settings.rb index 116cb2b6..d17b5d14 100644 --- a/config/foreman.migrations/20190111180118_delete_removed_settings.rb +++ b/config/foreman.migrations/20190111180118_delete_removed_settings.rb @@ -1,74 +1,10 @@ -DELETED = { - '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' end diff --git a/config/foreman.migrations/20190423154755_remove-docker-abrt-plugins.rb b/config/foreman.migrations/20190423154755_remove-docker-abrt-plugins.rb index f9816d23..a8a51c70 100644 --- a/config/foreman.migrations/20190423154755_remove-docker-abrt-plugins.rb +++ b/config/foreman.migrations/20190423154755_remove-docker-abrt-plugins.rb @@ -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') diff --git a/config/foreman.migrations/20190502234130_foreman_kubevirt.rb b/config/foreman.migrations/20190502234130_foreman_kubevirt.rb index 16090b78..d4cb6777 100644 --- a/config/foreman.migrations/20190502234130_foreman_kubevirt.rb +++ b/config/foreman.migrations/20190502234130_foreman_kubevirt.rb @@ -1 +1 @@ -answers['foreman::plugin::kubevirt'] ||= false +add_module('foreman::plugin::kubevirt') diff --git a/config/foreman.migrations/20190520122507_hammer_cli_kubevirt.rb b/config/foreman.migrations/20190520122507_hammer_cli_kubevirt.rb index f6337a3d..00cf085c 100644 --- a/config/foreman.migrations/20190520122507_hammer_cli_kubevirt.rb +++ b/config/foreman.migrations/20190520122507_hammer_cli_kubevirt.rb @@ -1 +1 @@ -answers['foreman::cli::kubevirt'] ||= false +add_module('foreman::cli::kubevirt') diff --git a/config/foreman.migrations/20190903120000_remove-cockpit-plugin.rb b/config/foreman.migrations/20190903120000_remove-cockpit-plugin.rb index 6fdc0a3f..b37feae8 100644 --- a/config/foreman.migrations/20190903120000_remove-cockpit-plugin.rb +++ b/config/foreman.migrations/20190903120000_remove-cockpit-plugin.rb @@ -1,3 +1 @@ -['foreman::plugin::cockpit'].each do |plugin| - answers.delete(plugin) if answers.include?(plugin) -end +delete_module('foreman::plugin::cockpit') diff --git a/config/foreman.migrations/20191029130301_add_rex-cockpit.rb b/config/foreman.migrations/20191029130301_add_rex-cockpit.rb index d38c85b5..17d9d43f 100644 --- a/config/foreman.migrations/20191029130301_add_rex-cockpit.rb +++ b/config/foreman.migrations/20191029130301_add_rex-cockpit.rb @@ -1 +1 @@ -answers['foreman::plugin::remote_execution::cockpit'] ||= false +add_module('foreman::plugin::remote_execution::cockpit') diff --git a/config/foreman.migrations/20191121124856_hammer_cli_azure.rb b/config/foreman.migrations/20191121124856_hammer_cli_azure.rb index e1ec8da0..c8ccadf7 100644 --- a/config/foreman.migrations/20191121124856_hammer_cli_azure.rb +++ b/config/foreman.migrations/20191121124856_hammer_cli_azure.rb @@ -1 +1 @@ -answers['foreman::cli::azure'] ||= false +add_module('foreman::cli::azure') diff --git a/config/foreman.migrations/20200113133837_reset_bind-host-foreman-proxy.rb b/config/foreman.migrations/20200113133837_reset_bind-host-foreman-proxy.rb index 61c34b0b..7c4ee418 100644 --- a/config/foreman.migrations/20200113133837_reset_bind-host-foreman-proxy.rb +++ b/config/foreman.migrations/20200113133837_reset_bind-host-foreman-proxy.rb @@ -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 diff --git a/config/foreman.migrations/20200305172758_enable_puma.rb b/config/foreman.migrations/20200305172758_enable_puma.rb index babb122e..4d994955 100644 --- a/config/foreman.migrations/20200305172758_enable_puma.rb +++ b/config/foreman.migrations/20200305172758_enable_puma.rb @@ -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 diff --git a/config/foreman.migrations/20200504073814_add_foreman_leapp.rb b/config/foreman.migrations/20200504073814_add_foreman_leapp.rb index 37c23d45..1c3ef2b2 100644 --- a/config/foreman.migrations/20200504073814_add_foreman_leapp.rb +++ b/config/foreman.migrations/20200504073814_add_foreman_leapp.rb @@ -1 +1 @@ -answers['foreman::plugin::leapp'] ||= false +add_module('foreman::plugin::leapp') diff --git a/config/foreman.migrations/20200803163936_add_statistics-plugin.rb b/config/foreman.migrations/20200803163936_add_statistics-plugin.rb index 3159f583..ef1c5891 100644 --- a/config/foreman.migrations/20200803163936_add_statistics-plugin.rb +++ b/config/foreman.migrations/20200803163936_add_statistics-plugin.rb @@ -1 +1 @@ -answers['foreman::plugin::statistics'] ||= false +add_module('foreman::plugin::statistics') diff --git a/config/foreman.migrations/20200803185054_add_column-view-plugin.rb b/config/foreman.migrations/20200803185054_add_column-view-plugin.rb index d4e5bcf0..7554d41e 100644 --- a/config/foreman.migrations/20200803185054_add_column-view-plugin.rb +++ b/config/foreman.migrations/20200803185054_add_column-view-plugin.rb @@ -1 +1 @@ -answers['foreman::plugin::column_view'] ||= false +add_module('foreman::plugin::column_view') diff --git a/config/foreman.migrations/20200805102253_change_logging_layout.rb b/config/foreman.migrations/20200805102253_change_logging_layout.rb index 15133111..1ad1832b 100644 --- a/config/foreman.migrations/20200805102253_change_logging_layout.rb +++ b/config/foreman.migrations/20200805102253_change_logging_layout.rb @@ -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 diff --git a/config/foreman.migrations/20200909151007_manage_acls_on_debian.rb b/config/foreman.migrations/20200909151007_manage_acls_on_debian.rb index 54f68e15..05180ca5 100644 --- a/config/foreman.migrations/20200909151007_manage_acls_on_debian.rb +++ b/config/foreman.migrations/20200909151007_manage_acls_on_debian.rb @@ -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 diff --git a/config/foreman.migrations/20201020000326_drop_rackspace.rb b/config/foreman.migrations/20201020000326_drop_rackspace.rb index 8caebb16..2ddfea88 100644 --- a/config/foreman.migrations/20201020000326_drop_rackspace.rb +++ b/config/foreman.migrations/20201020000326_drop_rackspace.rb @@ -1,3 +1 @@ -if answers.key?('foreman::compute::rackspace') - answers.delete('foreman::compute::rackspace') -end +remove_module('foreman::compute::rackspace') diff --git a/config/foreman.migrations/20201207225700_remove_digitalocean-plugin.rb b/config/foreman.migrations/20201207225700_remove_digitalocean-plugin.rb index 669b86c5..68f928ba 100644 --- a/config/foreman.migrations/20201207225700_remove_digitalocean-plugin.rb +++ b/config/foreman.migrations/20201207225700_remove_digitalocean-plugin.rb @@ -1,3 +1 @@ -if answers.key?('foreman::plugin::digitalocean') - answers.delete('foreman::plugin::digitalocean') -end +remove_module('foreman::plugin::digitalocean') diff --git a/config/foreman.migrations/20201224125100_ansible_ssh_args.rb b/config/foreman.migrations/20201224125100_ansible_ssh_args.rb index c1f73d14..37f70ea6 100644 --- a/config/foreman.migrations/20201224125100_ansible_ssh_args.rb +++ b/config/foreman.migrations/20201224125100_ansible_ssh_args.rb @@ -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 diff --git a/config/foreman.migrations/20210129165012_drop_foreman_proxy_plugin_pulp.rb b/config/foreman.migrations/20210129165012_drop_foreman_proxy_plugin_pulp.rb index 01134782..07ea0867 100644 --- a/config/foreman.migrations/20210129165012_drop_foreman_proxy_plugin_pulp.rb +++ b/config/foreman.migrations/20210129165012_drop_foreman_proxy_plugin_pulp.rb @@ -1 +1 @@ -answers.delete('foreman_proxy::plugin::pulp') +remove_module('foreman_proxy::plugin::pulp') diff --git a/config/foreman.migrations/20210304102210_add_webhooks_plugin.rb b/config/foreman.migrations/20210304102210_add_webhooks_plugin.rb index 4db21967..666b50cb 100644 --- a/config/foreman.migrations/20210304102210_add_webhooks_plugin.rb +++ b/config/foreman.migrations/20210304102210_add_webhooks_plugin.rb @@ -1 +1 @@ -answers['foreman::plugin::webhooks'] ||= false +add_module('foreman::plugin::webhooks') diff --git a/config/foreman.migrations/20210304102446_add_proxy_shellhooks_plugin.rb b/config/foreman.migrations/20210304102446_add_proxy_shellhooks_plugin.rb index 18d28c56..e20aa078 100644 --- a/config/foreman.migrations/20210304102446_add_proxy_shellhooks_plugin.rb +++ b/config/foreman.migrations/20210304102446_add_proxy_shellhooks_plugin.rb @@ -1 +1 @@ -answers['foreman_proxy::plugin::shellhooks'] ||= false +add_module('foreman_proxy::plugin::shellhooks') diff --git a/config/foreman.migrations/20210323145821_foreman_tasks-backup.rb b/config/foreman.migrations/20210323145821_foreman_tasks-backup.rb index 96328f1d..25063157 100644 --- a/config/foreman.migrations/20210323145821_foreman_tasks-backup.rb +++ b/config/foreman.migrations/20210323145821_foreman_tasks-backup.rb @@ -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 diff --git a/config/foreman.migrations/20210331121715_clear_puppetserver-nil-metrics.rb b/config/foreman.migrations/20210331121715_clear_puppetserver-nil-metrics.rb index 0c23b2c7..3772697f 100644 --- a/config/foreman.migrations/20210331121715_clear_puppetserver-nil-metrics.rb +++ b/config/foreman.migrations/20210331121715_clear_puppetserver-nil-metrics.rb @@ -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? diff --git a/config/foreman.migrations/20210625142707_dynamic_puppet_in_foreman_groups.rb b/config/foreman.migrations/20210625142707_dynamic_puppet_in_foreman_groups.rb index b2f0ecda..501bffff 100644 --- a/config/foreman.migrations/20210625142707_dynamic_puppet_in_foreman_groups.rb +++ b/config/foreman.migrations/20210625142707_dynamic_puppet_in_foreman_groups.rb @@ -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 diff --git a/config/foreman.migrations/20210708144320_add_foreman_puppet.rb b/config/foreman.migrations/20210708144320_add_foreman_puppet.rb index 749dc130..0e4ba449 100644 --- a/config/foreman.migrations/20210708144320_add_foreman_puppet.rb +++ b/config/foreman.migrations/20210708144320_add_foreman_puppet.rb @@ -1,3 +1 @@ -unless answers.key?('foreman::plugin::puppet') - answers['foreman::plugin::puppet'] = true -end +add_module('foreman::plugin::puppet', true)