Project

General

Profile

« Previous | Next » 

Revision bef5bd62

Added by Ewoud Kohl van Wijngaarden over 2 years ago

Rewrite migration spec

This refactors the migration spec to be more focused on the actual
testing by removing a lot of duplication.

In places where there is very little in the actual fixture, the test is
rewritten to test it inline or provide the answers inline. This makes it
easier to follow what's going on.

Care has been taken to get decent naming in the output:

$ bundle exec rspec --format documentation spec/migration_spec.rb
with all migrations
on the scenario
foreman
does not change the scenario config
does not change the scenario answers
foreman-proxy-content
does not change the scenario config
does not change the scenario answers
katello
does not change the scenario config
does not change the scenario answers
on katello
with fixture pulpcore-migration
matches the answers fixture
with fixture pulpcore-migration-rpm-only
matches the answers fixture
with fixture pulpcore-migration-dont-use-content-plugins-on-upgrades
matches the answers fixture
the migration 20210625142707_dynamic_puppet_in_foreman_groups
on foreman
removes puppet
on katello
removes puppet
the migration 200818160950-remove_tuning_fact on foreman-proxy-content
removes facts
the migration 20210929144850_disable_puppet_plugins_if_undesired
on foreman
keeps foreman::cli disabled
adds foreman::cli::puppet disabled
keeps foreman disabled
adds foreman::plugin::puppet disabled
on katello
keeps foreman::cli disabled
adds foreman::cli::puppet disabled
keeps foreman disabled
adds foreman::plugin::puppet disabled
the migration 181213211252-merged-installer
on foreman-proxy-content
matches the scenario fixture
on katello
matches the scenario fixture
Finished in 0.6798 seconds (files took 0.27722 seconds to load)
22 examples, 0 failures

This makes it possible to find out where it failed. Errors look like
this:

Failures:
1) with all migrations the migration 20210625142707_dynamic_puppet_in_foreman_groups on foreman removes puppet
Failure/Error: expect(migrated_answers['foreman']['user_groups']).to eq ['a']
expected: ["a"]
got: []
  1. ./spec/migration_spec.rb:57:in `block (5 levels) in <top (required)>'
  2. /usr/share/gems/gems/bundler-2.2.22/libexec/bundle:49:in `block in <top (required)>'
  3. /usr/share/gems/gems/bundler-2.2.22/libexec/bundle:37:in `<top (required)>'
(compared using ==)

Technically the migration has a different name on Foreman and Katello,
but that's somewhat easy to figure out and painful to solve so it has to
be taken for granted now.

View differences:

spec/fixtures/cleanup-foreman-user-groups/foreman-answers-after.yaml
foreman:
user_groups: []
spec/fixtures/cleanup-foreman-user-groups/foreman-answers-before.yaml
foreman:
user_groups: ['puppet']
spec/fixtures/cleanup-foreman-user-groups/katello-answers-after.yaml
foreman:
user_groups: []
spec/fixtures/cleanup-foreman-user-groups/katello-answers-before.yaml
foreman:
user_groups: ['puppet']
spec/fixtures/foreman-proxy-content-remove-tuning-fact/foreman-proxy-content-after.yaml
---
:name: Foreman Proxy Content
:description: Install a stand-alone Foreman Content Proxy.
:log_dir: './_build/'
:log_name: 'foreman-proxy-content.log'
:log_level: DEBUG
:answer_file: ./config/foreman-proxy-content-answers.yaml
:installer_dir: .
:module_dirs: ./_build/modules
:hook_dirs: ['./katello/hooks']
:parser_cache_path: ./_build/parser_cache/foreman-proxy-content.yaml
:hiera_config: ./config/foreman-hiera.yaml
:verbose: true
:verbose_log_level: 'notice'
:order:
- certs
- foreman_proxy
- foreman_proxy::plugin::pulp
- foreman_proxy_content
- puppet
spec/fixtures/foreman-proxy-content-remove-tuning-fact/foreman-proxy-content-before.yaml
---
:name: Foreman Proxy Content
:description: Install a stand-alone Foreman Content Proxy.
:log_dir: './_build/'
:log_name: 'foreman-proxy-content.log'
:log_level: DEBUG
:answer_file: ./config/foreman-proxy-content-answers.yaml
:installer_dir: .
:module_dirs: ./_build/modules
:hook_dirs: ['./katello/hooks']
:parser_cache_path: ./_build/parser_cache/foreman-proxy-content.yaml
:hiera_config: ./config/foreman-hiera.yaml
:facts:
tuning: 'default'
:order:
- certs
- foreman_proxy
- foreman_proxy::plugin::pulp
- foreman_proxy_content
- puppet
spec/migration_spec.rb
require 'spec_helper'
describe 'migrations' do
%w[foreman foreman-proxy-content katello].each do |scenario_name|
context "on #{scenario_name}" do
let(:answers) { load_config_yaml("#{scenario_name}-answers.yaml") }
let(:config) { load_config_yaml("#{scenario_name}.yaml") }
let(:scenario) do
{
:answers => load_config_yaml("#{scenario_name}-answers.yaml"),
:config => load_config_yaml("#{scenario_name}.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
describe 'with all migrations' do
let(:config) { load_config_yaml("#{scenario_name}.yaml") }
let(:answers) { load_config_yaml("#{scenario_name}-answers.yaml") }
let(:migrations) { config_path("#{scenario_name}.migrations") }
let(:migrator) { Kafo::Migrations.new(migrations).run(config, answers) }
subject(:migrated_config) { migrator[0] }
subject(:migrated_answers) { migrator[1] }
context 'on the scenario' do
%w[foreman foreman-proxy-content katello].each do |scenario_name|
context scenario_name do
let(:scenario_name) { scenario_name }
it 'does not change scenario config' do
after, = migrator
expect(config).to eq after
end
it 'does not change the scenario config' do
expect(migrated_config).to eq load_config_yaml("#{scenario_name}.yaml")
end
it 'does not change scenario answers' do
_, after = migrator
expect(answers).to eq after
it 'does not change the scenario answers' do
expect(migrated_answers).to eq load_config_yaml("#{scenario_name}-answers.yaml")
end
end
end
end
%w[foreman-proxy-content katello].each do |scenario_name|
context "migrates #{scenario_name} split installer" do
let(:config_after) { load_fixture_yaml('merged-installer', "#{scenario_name}-after.yaml") }
let(:scenario) do
{
:answers => load_config_yaml("#{scenario_name}-answers.yaml"),
:config => load_fixture_yaml('merged-installer', "#{scenario_name}-before.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
context 'on katello' do
let(:scenario_name) { 'katello' }
let(:answers) { load_fixture_yaml(fixture, "#{scenario_name}-answers-before.yaml") }
let(:expected_answers) { load_fixture_yaml(fixture, "#{scenario_name}-answers-after.yaml") }
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
['pulpcore-migration', 'pulpcore-migration-rpm-only', 'pulpcore-migration-dont-use-content-plugins-on-upgrades'].each do |fixture_name|
context "with fixture #{fixture_name}" do
let(:fixture) { fixture_name }
it 'does not change scenario config' do
after, = migrator
expect(after).to eq config_after
it 'matches the answers fixture' do
expect(migrated_answers).to eq expected_answers
end
end
end
end
%w[katello].each do |scenario_name|
context "pulpcore migration" do
let(:answers_after) { load_fixture_yaml('pulpcore-migration', "#{scenario_name}-answers-after.yaml") }
let(:scenario) do
{
:answers => load_fixture_yaml('pulpcore-migration', "#{scenario_name}-answers-before.yaml"),
:config => load_config_yaml("#{scenario_name}.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
it 'changes scenario answers' do
_, after = migrator
expect(answers_after).to eq after
end
end
context "pulpcore migration rpm plugin only" do
let(:answers_after) { load_fixture_yaml('pulpcore-migration-rpm-only', "#{scenario_name}-answers-after.yaml") }
let(:scenario) do
{
:answers => load_fixture_yaml('pulpcore-migration-rpm-only', "#{scenario_name}-answers-before.yaml"),
:config => load_config_yaml("#{scenario_name}.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
it 'changes scenario answers' do
_, after = migrator
expect(answers_after).to eq after
end
context 'the migration 20210625142707_dynamic_puppet_in_foreman_groups' do
let(:answers) do
{
'foreman' => {
'user_groups' => ['puppet'],
},
}
end
context "pulpcore migration dont use content plugins on upgrades" do
let(:answers_after) { load_fixture_yaml('pulpcore-migration-dont-use-content-plugins-on-upgrades', "#{scenario_name}-answers-after.yaml") }
let(:scenario) do
{
:answers => load_fixture_yaml('pulpcore-migration-dont-use-content-plugins-on-upgrades', "#{scenario_name}-answers-before.yaml"),
:config => load_config_yaml("#{scenario_name}.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
%w[foreman katello].each do |scenario_name|
context "on #{scenario_name}" do
let(:scenario_name) { scenario_name }
it 'changes scenario answers' do
_, after = migrator
expect(answers_after).to eq after
it 'removes puppet' do
expect(migrated_answers['foreman']['user_groups']).to eq []
end
end
end
end
%w[foreman-proxy-content].each do |scenario_name|
context "foreman-proxy-content remove tuning fact" do
let(:config_after) { load_fixture_yaml('foreman-proxy-content-remove-tuning-fact', "#{scenario_name}-after.yaml") }
let(:scenario) do
{
:answers => load_config_yaml("#{scenario_name}-answers.yaml"),
:config => load_fixture_yaml('foreman-proxy-content-remove-tuning-fact', "#{scenario_name}-before.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
context 'the migration 200818160950-remove_tuning_fact on foreman-proxy-content' do
let(:scenario_name) { 'foreman-proxy-content' }
let(:config) { super().merge(:facts => { 'tuning' => 'default' }) }
it 'changes scenario config' do
after, = migrator
expect(config_after).to eq after
end
it 'removes facts' do
expect(migrated_config).not_to include(:facts)
end
end
%w[foreman katello].each do |scenario_name|
context "foreman drop puppet from user_groups" do
let(:answers_after) { load_fixture_yaml('cleanup-foreman-user-groups', "#{scenario_name}-answers-after.yaml") }
let(:scenario) do
{
:answers => load_fixture_yaml('cleanup-foreman-user-groups', "#{scenario_name}-answers-before.yaml"),
:config => load_config_yaml("#{scenario_name}.yaml"),
:migrations => config_path("#{scenario_name}.migrations"),
}
end
let(:migrator) { Kafo::Migrations.new(scenario[:migrations]).run(scenario[:config], scenario[:answers]) }
it 'changes scenario answers' do
_, after = migrator
expect(after).to include answers_after
end
context 'the migration 20210929144850_disable_puppet_plugins_if_undesired' do
let(:answers) do
{
'foreman' => false,
'foreman::cli' => false,
}
end
end
context 'disable puppet if needed' do
%w[foreman katello].each do |scenario_name|
context "on #{scenario_name}" do
let(:answers) do
{
'foreman' => false,
'foreman::cli' => false,
}
end
let(:scenario_name) { scenario_name }
let(:config) { load_config_yaml("#{scenario_name}.yaml") }
let(:migrations) { config_path("#{scenario_name}.migrations") }
let(:migrator) { Kafo::Migrations.new(migrations).run(config, answers) }
subject(:migrated_answers) { migrator[1] }
it 'keeps foreman::cli disabled' do
expect(migrated_answers['foreman::cli']).to be false
......
end
end
end
context 'the migration 181213211252-merged-installer' do
let(:config) { load_fixture_yaml('merged-installer', "#{scenario_name}-before.yaml") }
%w[foreman-proxy-content katello].each do |scenario_name|
context "on #{scenario_name}" do
let(:scenario_name) { scenario_name }
it 'matches the scenario fixture' do
expect(migrated_config).to eq load_fixture_yaml('merged-installer', "#{scenario_name}-after.yaml")
end
end
end
end
end

Also available in: Unified diff