diff --git a/config/foreman.migrations/20210625142707_dynamic_puppet-in-foreman-groups.rb b/config/foreman.migrations/20210625142707_dynamic_puppet-in-foreman-groups.rb new file mode 100644 index 000000000..b2f0ecdad --- /dev/null +++ b/config/foreman.migrations/20210625142707_dynamic_puppet-in-foreman-groups.rb @@ -0,0 +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') + end +end diff --git a/config/katello-answers.yaml b/config/katello-answers.yaml index b817e1c38..72d56b747 100644 --- a/config/katello-answers.yaml +++ b/config/katello-answers.yaml @@ -23,7 +23,6 @@ foreman: server_ssl_chain: /etc/pki/katello/certs/katello-server-ca.crt server_ssl_crl: "" server_ssl_key: /etc/pki/katello/private/katello-apache.key - user_groups: [] websockets_ssl_cert: /etc/pki/katello/certs/katello-apache.crt websockets_ssl_key: /etc/pki/katello/private/katello-apache.key foreman::cli: true diff --git a/config/katello.migrations/190314163941-remove-foreman-user-groups.rb b/config/katello.migrations/190314163941-remove-foreman-user-groups.rb index 347a84a5e..026c350f9 100644 --- a/config/katello.migrations/190314163941-remove-foreman-user-groups.rb +++ b/config/katello.migrations/190314163941-remove-foreman-user-groups.rb @@ -1,5 +1,3 @@ -if answers['foreman'].is_a?(Hash) +if answers['foreman'].is_a?(Hash) && answers['foreman'].key?('user_groups') answers['foreman']['user_groups'] = [] -elsif answers['foreman'] - answers['foreman'] = { 'user_groups' => [] } end diff --git a/config/katello.migrations/210625142712-dynamic-puppet-in-foreman-groups.rb b/config/katello.migrations/210625142712-dynamic-puppet-in-foreman-groups.rb new file mode 100644 index 000000000..b2f0ecdad --- /dev/null +++ b/config/katello.migrations/210625142712-dynamic-puppet-in-foreman-groups.rb @@ -0,0 +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') + end +end diff --git a/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-after.yaml b/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-after.yaml new file mode 100644 index 000000000..47b069871 --- /dev/null +++ b/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-after.yaml @@ -0,0 +1,2 @@ +foreman: + user_groups: [] diff --git a/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-before.yaml b/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-before.yaml new file mode 100644 index 000000000..c1aa55925 --- /dev/null +++ b/spec/fixtures/cleanup-foreman-user-groups/foreman-answers-before.yaml @@ -0,0 +1,2 @@ +foreman: + user_groups: ['puppet'] diff --git a/spec/fixtures/cleanup-foreman-user-groups/katello-answers-after.yaml b/spec/fixtures/cleanup-foreman-user-groups/katello-answers-after.yaml new file mode 100644 index 000000000..47b069871 --- /dev/null +++ b/spec/fixtures/cleanup-foreman-user-groups/katello-answers-after.yaml @@ -0,0 +1,2 @@ +foreman: + user_groups: [] diff --git a/spec/fixtures/cleanup-foreman-user-groups/katello-answers-before.yaml b/spec/fixtures/cleanup-foreman-user-groups/katello-answers-before.yaml new file mode 100644 index 000000000..c1aa55925 --- /dev/null +++ b/spec/fixtures/cleanup-foreman-user-groups/katello-answers-before.yaml @@ -0,0 +1,2 @@ +foreman: + user_groups: ['puppet'] diff --git a/spec/migration_spec.rb b/spec/migration_spec.rb index 7cb193699..ac42b68f1 100644 --- a/spec/migration_spec.rb +++ b/spec/migration_spec.rb @@ -122,4 +122,24 @@ end 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 + end + end end