From df9900d25bb73c5576e5cf35e2947032d53d5176 Mon Sep 17 00:00:00 2001 From: Lance Albertson Date: Fri, 15 Oct 2021 15:08:36 -0700 Subject: [PATCH] CentOS 8 support - Add yum-centos cookbook to deps - Enable PowerTools and RabbitMQ repositories on EL8 - Update various packages for EL8 Depends-On: https://review.opendev.org/c/openstack/openstack-chef/+/814234 Change-Id: Ife3165204d9ffee132a0daacd4a6f30c7d31378b Signed-off-by: Lance Albertson --- README.rst | 1 + attributes/database.rb | 12 ++- attributes/default.rb | 40 +++++--- metadata.rb | 1 + recipes/default.rb | 18 +++- spec/client-redhat_spec.rb | 31 +++--- spec/default-redhat_spec.rb | 188 ++++++++++++++++++++---------------- spec/spec_helper.rb | 12 ++- 8 files changed, 192 insertions(+), 111 deletions(-) diff --git a/README.rst b/README.rst index 7d1af458..2bcedbc3 100644 --- a/README.rst +++ b/README.rst @@ -43,6 +43,7 @@ The following cookbooks are dependencies: - 'mariadb', '~> 5.0' - 'memcached', '~> 7.0' - 'selinux' +- 'yum-centos', '>= 3.2.0' - 'yum-epel' Attributes diff --git a/attributes/database.rb b/attributes/database.rb index 0bd95c20..fb83f609 100644 --- a/attributes/database.rb +++ b/attributes/database.rb @@ -122,9 +122,15 @@ default['openstack']['db']['python_packages'] = { case node['platform_family'] when 'rhel' default['openstack']['db']['service_type'] = 'mariadb' - default['openstack']['db']['python_packages']['mariadb'] = ['MySQL-python'] - default['openstack']['db']['python_packages']['percona-cluster'] = ['MySQL-python'] - default['openstack']['db']['python_packages']['galera'] = ['MySQL-python'] + if node['platform_version'].to_i >= 8 + default['openstack']['db']['python_packages']['mariadb'] = ['python3-PyMySQL'] + default['openstack']['db']['python_packages']['percona-cluster'] = ['python3-PyMySQL'] + default['openstack']['db']['python_packages']['galera'] = ['python3-PyMySQL'] + else + default['openstack']['db']['python_packages']['mariadb'] = ['MySQL-python'] + default['openstack']['db']['python_packages']['percona-cluster'] = ['MySQL-python'] + default['openstack']['db']['python_packages']['galera'] = ['MySQL-python'] + end when 'debian' default['openstack']['db']['service_type'] = 'mariadb' default['openstack']['db']['python_packages']['mariadb'] = ['python3-mysqldb'] diff --git a/attributes/default.rb b/attributes/default.rb index 94e1f9b6..3b1e7e39 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -292,18 +292,34 @@ default['openstack']['sysctl']['net.ipv4.conf.default.rp_filter'] = 0 case node['platform_family'] when 'rhel' - default['openstack']['common']['platform'] = { - 'common_client_packages' => ['python-openstackclient'], - 'python_packages' => %w( - python - python2-pip - python2-setuptools - python-devel - python-virtualenv - python-wheel - ), - 'package_overrides' => '', - } + default['openstack']['common']['platform'] = + if node['platform_version'].to_i >= 8 + { + 'common_client_packages' => ['python3-openstackclient'], + 'python_packages' => %w( + python3-pip + python3-setuptools + python3-virtualenv + python3-wheel + python36 + python36-devel + ), + 'package_overrides' => '', + } + else + { + 'common_client_packages' => ['python-openstackclient'], + 'python_packages' => %w( + python + python2-pip + python2-setuptools + python-devel + python-virtualenv + python-wheel + ), + 'package_overrides' => '', + } + end when 'debian' default['openstack']['common']['platform'] = { 'common_client_packages' => ['python3-openstackclient'], diff --git a/metadata.rb b/metadata.rb index adf96c59..1f852b3e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -13,6 +13,7 @@ depends 'etcd', '~> 7.0' depends 'mariadb', '~> 5.0' depends 'memcached', '~> 7.0' depends 'selinux' +depends 'yum-centos', '>= 3.2.0' depends 'yum-epel' issues_url 'https://launchpad.net/openstack-chef' diff --git a/recipes/default.rb b/recipes/default.rb index 90504471..8de30568 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -72,8 +72,20 @@ when 'debian' end when 'rhel' - # TODO(ramereth): These packages conflict with the RDO repo for Train - node.default['yum']['epel']['exclude'] = 'python2-qpid-proton python2-pyngus qpid-proton-c' + case node['platform_version'].to_i + when 7 + # TODO(ramereth): These packages conflict with the RDO repo for Train + node.default['yum']['epel']['exclude'] = 'python2-qpid-proton python2-pyngus qpid-proton-c' + when 8 + # Need PowerTools repo for some of the python deps + node.default['yum']['powertools']['enabled'] = true + node.default['yum']['powertools']['managed'] = true + # Need to use RabbitMQ repo on EL8 + node.default['yum']['centos-rabbitmq']['enabled'] = true + node.default['yum']['centos-rabbitmq']['managed'] = true + + include_recipe 'yum-centos' + end include_recipe 'yum-epel' @@ -111,7 +123,7 @@ when 'rhel' package 'centos-release-qemu-ev' do action :upgrade - end + end if node['platform_version'].to_i < 8 end # install a python diff --git a/spec/client-redhat_spec.rb b/spec/client-redhat_spec.rb index c7fa803c..61878ec2 100644 --- a/spec/client-redhat_spec.rb +++ b/spec/client-redhat_spec.rb @@ -1,19 +1,28 @@ require_relative 'spec_helper' describe 'openstack-common::client' do - describe 'redhat' do - let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } - let(:node) { runner.node } - cached(:chef_run) do - runner.converge(described_recipe) - end + ALL_RHEL.each do |p| + context "redhat #{p[:version]}" do + let(:runner) { ChefSpec::SoloRunner.new(p) } + let(:node) { runner.node } + cached(:chef_run) do + runner.converge(described_recipe) + end - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end + it 'converges successfully' do + expect { chef_run }.to_not raise_error + end - it do - expect(chef_run).to upgrade_package('python-openstackclient') + case p + when REDHAT_7 + it do + expect(chef_run).to upgrade_package('python-openstackclient') + end + when REDHAT_8 + it do + expect(chef_run).to upgrade_package('python3-openstackclient') + end + end end end end diff --git a/spec/default-redhat_spec.rb b/spec/default-redhat_spec.rb index 51b828ef..8d89c302 100644 --- a/spec/default-redhat_spec.rb +++ b/spec/default-redhat_spec.rb @@ -1,109 +1,135 @@ require_relative 'spec_helper' describe 'openstack-common::default' do - describe 'rhel-rdo' do - let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } - let(:node) { runner.node } - cached(:chef_run) do - node.override['openstack']['release'] = 'testrelease' - runner.converge(described_recipe) - end - - it 'converges successfully' do - expect { chef_run }.to_not raise_error - end - - it do - expect(chef_run).to upgrade_package('centos-release-qemu-ev') - end - - pkgs = %w(python python2-pip python2-setuptools python-devel python-virtualenv python-wheel) - - it 'installs python2 packages' do - expect(chef_run).to upgrade_package(pkgs) - end - - context 'enabling RDO with gpgcheck enabled' do + ALL_RHEL.each do |p| + context "redhat #{p[:version]}" do + let(:runner) { ChefSpec::SoloRunner.new(p) } + let(:node) { runner.node } cached(:chef_run) do node.override['openstack']['release'] = 'testrelease' - node.override['openstack']['yum']['rdo_enabled'] = true - node.override['openstack']['yum']['gpgcheck'] = true runner.converge(described_recipe) end - it 'adds RDO yum repository' do - # Using cookbook(yum) LWRP custom matcher - # https://github.com/sethvargo/chefspec#packaging-custom-matchers - expect(chef_run).to add_yum_repository('RDO-testrelease') - .with(gpgcheck: true) + it 'converges successfully' do + expect { chef_run }.to_not raise_error end - it 'does include yum-epel recipe' do - expect(chef_run).to include_recipe('yum-epel') - end - end + case p + when REDHAT_7 + pkgs = %w(python python2-pip python2-setuptools python-devel python-virtualenv python-wheel) - context 'enabling RDO with gpgcheck disabled' do - cached(:chef_run) do - node.override['openstack']['release'] = 'testrelease' - node.override['openstack']['yum']['rdo_enabled'] = true - node.override['openstack']['yum']['gpgcheck'] = false - runner.converge(described_recipe) + it do + expect(chef_run).to upgrade_package('centos-release-qemu-ev') + end + + it do + expect(chef_run).to include_recipe('yum-epel') + end + + it do + expect(chef_run).to_not include_recipe('yum-centos') + end + + it do + expect(chef_run).to create_yum_repository('epel').with( + exclude: 'python2-qpid-proton python2-pyngus qpid-proton-c' + ) + end + when REDHAT_8 + pkgs = %w(python3-pip python3-setuptools python3-virtualenv python3-wheel python36 python36-devel) + + it do + expect(chef_run).to_not upgrade_package('centos-release-qemu-ev') + end + + %w(yum-epel yum-centos).each do |r| + it do + expect(chef_run).to include_recipe(r) + end + end + + it do + expect(chef_run).to create_yum_repository('epel').with(exclude: nil) + end + + %w(powertools centos-rabbitmq).each do |repo| + it do + expect(chef_run).to create_yum_repository(repo).with(enabled: true) + end + end end - it 'adds RDO yum repository' do - expect(chef_run).to add_yum_repository('RDO-testrelease') - .with(gpgcheck: false) + it do + expect(chef_run).to upgrade_package(pkgs) end - it 'does include yum-epel recipe' do - expect(chef_run).to include_recipe('yum-epel') - end - end + context 'enabling RDO with gpgcheck enabled' do + cached(:chef_run) do + node.override['openstack']['release'] = 'testrelease' + node.override['openstack']['yum']['rdo_enabled'] = true + node.override['openstack']['yum']['gpgcheck'] = true + runner.converge(described_recipe) + end - context 'disabling RDO deps repo with is_release true' do - cached(:chef_run) do - node.override['openstack']['release'] = 'testrelease' - node.override['openstack']['is_release'] = true - runner.converge(described_recipe) + it do + expect(chef_run).to add_yum_repository('RDO-testrelease').with(gpgcheck: true) + end end - it 'does not add the RDO deps yum repository' do - expect(chef_run).to_not add_yum_repository('RDO-testrelease-deps') - end - end + context 'enabling RDO with gpgcheck disabled' do + cached(:chef_run) do + node.override['openstack']['release'] = 'testrelease' + node.override['openstack']['yum']['rdo_enabled'] = true + node.override['openstack']['yum']['gpgcheck'] = false + runner.converge(described_recipe) + end - context 'disabling RDO' do - cached(:chef_run) do - node.override['openstack']['release'] = 'testrelease' - node.override['openstack']['yum']['rdo_enabled'] = false - runner.converge(described_recipe) + it do + expect(chef_run).to add_yum_repository('RDO-testrelease').with(gpgcheck: false) + end end - it 'removes RDO yum repository' do - allow(FileTest).to receive(:exist?).and_call_original - allow(FileTest).to receive(:exist?).with('/etc/yum.repos.d/RDO-testrelease.repo').and_return(true) - expect(chef_run).to remove_yum_repository('RDO-testrelease') - end - it 'does include yum-epel recipe' do - expect(chef_run).to include_recipe('yum-epel') + context 'disabling RDO deps repo with is_release true' do + cached(:chef_run) do + node.override['openstack']['release'] = 'testrelease' + node.override['openstack']['is_release'] = true + runner.converge(described_recipe) + end + + it 'does not add the RDO deps yum repository' do + expect(chef_run).to_not add_yum_repository('RDO-testrelease-deps') + end end - it 'does not create RDO-Manager yum repositories' do - expect(chef_run).to_not create_remote_file('/etc/yum.repos.d/rdo-manager-release.repo') - end - end + context 'disabling RDO' do + cached(:chef_run) do + node.override['openstack']['release'] = 'testrelease' + node.override['openstack']['yum']['rdo_enabled'] = false + runner.converge(described_recipe) + end - context 'disabling RDO and repo file does not exist' do - cached(:chef_run) do - node.override['openstack']['release'] = 'testrelease' - node.override['openstack']['yum']['rdo_enabled'] = false - runner.converge(described_recipe) + it 'removes RDO yum repository' do + allow(FileTest).to receive(:exist?).and_call_original + allow(FileTest).to receive(:exist?).with('/etc/yum.repos.d/RDO-testrelease.repo').and_return(true) + expect(chef_run).to remove_yum_repository('RDO-testrelease') + end + + it 'does not create RDO-Manager yum repositories' do + expect(chef_run).to_not create_remote_file('/etc/yum.repos.d/rdo-manager-release.repo') + end end - it 'does nothing when RDO yum repository does not exist' do - allow(FileTest).to receive(:exist?).and_call_original - allow(FileTest).to receive(:exist?).with('/etc/yum.repos.d/RDO-testrelease.repo').and_return(false) - expect(chef_run).to nothing_yum_repository('RDO-testrelease') + + context 'disabling RDO and repo file does not exist' do + cached(:chef_run) do + node.override['openstack']['release'] = 'testrelease' + node.override['openstack']['yum']['rdo_enabled'] = false + runner.converge(described_recipe) + end + it 'does nothing when RDO yum repository does not exist' do + allow(FileTest).to receive(:exist?).and_call_original + allow(FileTest).to receive(:exist?).with('/etc/yum.repos.d/RDO-testrelease.repo').and_return(false) + expect(chef_run).to nothing_yum_repository('RDO-testrelease') + end end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 38ebf23f..a8d705e2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,11 +12,21 @@ UBUNTU_OPTS = { version: '18.04', }.freeze -REDHAT_OPTS = { +REDHAT_7 = { platform: 'redhat', version: '7', }.freeze +REDHAT_8 = { + platform: 'redhat', + version: '8', +}.freeze + +ALL_RHEL = [ + REDHAT_7, + REDHAT_8, +].freeze + # We set a default platform for non-platform specific test cases CHEFSPEC_OPTS = UBUNTU_OPTS