From 7953fbe8c29d1628c6d4e12b79f99265af77bc00 Mon Sep 17 00:00:00 2001 From: Roger Luethi Date: Fri, 24 Jul 2020 22:38:15 +0200 Subject: [PATCH] Restart apache only where appropriate The current code tries to restart apache for every change to /etc/nova/nova.conf even on compute nodes that do not have apache installed. This changeset splits out the apache service resource into a separate recipe that (unlike nova-common) is not included by the compute recipe. Conflicts: recipes/placement_api.rb Added version bump. Change-Id: I87dda61dfabec460fe042b4cee21277382dd9487 (cherry picked from commit 5747451dcb905f56de155dabce94c89ae7ba9c01) --- metadata.rb | 2 +- recipes/_nova_apache.rb | 32 ++++++++++++++++++++++++++++++ recipes/api-metadata.rb | 2 +- recipes/api-os-compute.rb | 2 +- recipes/nova-common.rb | 11 ---------- recipes/placement_api.rb | 2 +- spec/_nova_apache_spec.rb | 22 ++++++++++++++++++++ spec/api-metadata-redhat_spec.rb | 2 +- spec/api-metadata_spec.rb | 2 +- spec/api-os-compute-redhat_spec.rb | 2 +- spec/api-os-compute_spec.rb | 2 +- spec/nova-common_spec.rb | 4 ---- spec/placement_api-redhat_spec.rb | 2 +- spec/placement_api_spec.rb | 4 +--- spec/spec_helper.rb | 6 ++++++ 15 files changed, 70 insertions(+), 27 deletions(-) create mode 100644 recipes/_nova_apache.rb create mode 100644 spec/_nova_apache_spec.rb diff --git a/metadata.rb b/metadata.rb index 0cd82df9..01bd167d 100644 --- a/metadata.rb +++ b/metadata.rb @@ -5,7 +5,7 @@ issues_url 'https://launchpad.net/openstack-chef' source_url 'https://opendev.org/openstack/cookbook-openstack-compute' license 'Apache-2.0' description 'The OpenStack Compute service Nova.' -version '19.1.0' +version '19.2.0' chef_version '>= 15.0' diff --git a/recipes/_nova_apache.rb b/recipes/_nova_apache.rb new file mode 100644 index 00000000..99ab95ec --- /dev/null +++ b/recipes/_nova_apache.rb @@ -0,0 +1,32 @@ +# encoding: UTF-8 +# +# Cookbook:: openstack-compute +# Recipe:: _nova_apache +# +# Copyright:: 2019-2020, Oregon State University +# Copyright:: 2020, x-ion GmbH +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +include_recipe 'openstack-compute::nova-common' + +# service['apache2'] is defined in the apache2_default_install resource +# but other resources are currently unable to reference it. To work +# around this issue, define the following helper in your cookbook: +service 'apache2' do + extend Apache2::Cookbook::Helpers + service_name lazy { apache_platform_service_name } + supports restart: true, status: true, reload: true + action :nothing + subscribes :restart, 'template[/etc/nova/nova.conf]' +end diff --git a/recipes/api-metadata.rb b/recipes/api-metadata.rb index e0b97152..5ce6d69b 100644 --- a/recipes/api-metadata.rb +++ b/recipes/api-metadata.rb @@ -28,7 +28,7 @@ class ::Chef::Recipe include Apache2::Cookbook::Helpers end -include_recipe 'openstack-compute::nova-common' +include_recipe 'openstack-compute::_nova_apache' platform_options = node['openstack']['compute']['platform'] diff --git a/recipes/api-os-compute.rb b/recipes/api-os-compute.rb index 91c27d87..7565ce9a 100644 --- a/recipes/api-os-compute.rb +++ b/recipes/api-os-compute.rb @@ -25,7 +25,7 @@ class ::Chef::Recipe include Apache2::Cookbook::Helpers end -include_recipe 'openstack-compute::nova-common' +include_recipe 'openstack-compute::_nova_apache' platform_options = node['openstack']['compute']['platform'] diff --git a/recipes/nova-common.rb b/recipes/nova-common.rb index 005e6288..839204aa 100644 --- a/recipes/nova-common.rb +++ b/recipes/nova-common.rb @@ -188,16 +188,6 @@ end # merge all config options and secrets to be used in nova.conf nova_conf_options = merge_config_options 'compute' -# service['apache2'] is defined in the apache2_default_install resource -# but other resources are currently unable to reference it. To work -# around this issue, define the following helper in your cookbook: -service 'apache2' do - extend Apache2::Cookbook::Helpers - service_name lazy { apache_platform_service_name } - supports restart: true, status: true, reload: true - action :nothing -end - template '/etc/nova/nova.conf' do source 'openstack-service.conf.erb' cookbook 'openstack-common' @@ -210,7 +200,6 @@ template '/etc/nova/nova.conf' do # with the glance_api_servers configuration option... service_config: nova_conf_options ) - notifies :restart, 'service[apache2]' end # delete all secrets saved in the attribute diff --git a/recipes/placement_api.rb b/recipes/placement_api.rb index 618a7e7a..57a59127 100644 --- a/recipes/placement_api.rb +++ b/recipes/placement_api.rb @@ -24,7 +24,7 @@ class ::Chef::Recipe include Apache2::Cookbook::Helpers end -include_recipe 'openstack-compute::nova-common' +include_recipe 'openstack-compute::_nova_apache' include_recipe 'openstack-compute::_nova_cell' # Create valid apache site configuration file before installing package diff --git a/spec/_nova_apache_spec.rb b/spec/_nova_apache_spec.rb new file mode 100644 index 00000000..c9e48cfa --- /dev/null +++ b/spec/_nova_apache_spec.rb @@ -0,0 +1,22 @@ +# encoding: UTF-8 + +require_relative 'spec_helper' + +describe 'openstack-compute::_nova_apache' do + describe 'ubuntu' do + let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } + let(:node) { runner.node } + cached(:chef_run) { runner.converge(described_recipe) } + + include_context 'compute_stubs' + + it do + expect(chef_run).to include_recipe('openstack-compute::nova-common') + end + + it do + expect(chef_run.service('apache2')).to \ + subscribe_to('template[/etc/nova/nova.conf]').on(:restart) + end + end +end diff --git a/spec/api-metadata-redhat_spec.rb b/spec/api-metadata-redhat_spec.rb index c8653baf..29e2a670 100644 --- a/spec/api-metadata-redhat_spec.rb +++ b/spec/api-metadata-redhat_spec.rb @@ -9,7 +9,7 @@ describe 'openstack-compute::api-metadata' do cached(:chef_run) { runner.converge(described_recipe) } include_context 'compute_stubs' - include_examples 'expect_runs_nova_common_recipe' + include_examples 'expect_runs_nova_apache_recipe' include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' diff --git a/spec/api-metadata_spec.rb b/spec/api-metadata_spec.rb index 76296482..6df15813 100644 --- a/spec/api-metadata_spec.rb +++ b/spec/api-metadata_spec.rb @@ -9,7 +9,7 @@ describe 'openstack-compute::api-metadata' do cached(:chef_run) { runner.converge(described_recipe) } include_context 'compute_stubs' - include_examples 'expect_runs_nova_common_recipe' + include_examples 'expect_runs_nova_apache_recipe' include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' include_examples 'expect_creates_api_paste_template' diff --git a/spec/api-os-compute-redhat_spec.rb b/spec/api-os-compute-redhat_spec.rb index eaeb0c6e..2db88013 100644 --- a/spec/api-os-compute-redhat_spec.rb +++ b/spec/api-os-compute-redhat_spec.rb @@ -9,7 +9,7 @@ describe 'openstack-compute::api-os-compute' do cached(:chef_run) { runner.converge(described_recipe) } include_context 'compute_stubs' - include_examples 'expect_runs_nova_common_recipe' + include_examples 'expect_runs_nova_apache_recipe' include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' diff --git a/spec/api-os-compute_spec.rb b/spec/api-os-compute_spec.rb index e98e693a..0b8625d5 100644 --- a/spec/api-os-compute_spec.rb +++ b/spec/api-os-compute_spec.rb @@ -9,7 +9,7 @@ describe 'openstack-compute::api-os-compute' do cached(:chef_run) { runner.converge(described_recipe) } include_context 'compute_stubs' - include_examples 'expect_runs_nova_common_recipe' + include_examples 'expect_runs_nova_apache_recipe' include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' include_examples 'expect_creates_api_paste_template' diff --git a/spec/nova-common_spec.rb b/spec/nova-common_spec.rb index 860304cd..216e43b7 100644 --- a/spec/nova-common_spec.rb +++ b/spec/nova-common_spec.rb @@ -72,10 +72,6 @@ describe 'openstack-compute::nova-common' do ) end - it do - expect(chef_run.template('/etc/nova/nova.conf')).to notify('service[apache2]').to(:restart) - end - it '[DEFAULT]' do [ %r{^log_dir = /var/log/nova$}, diff --git a/spec/placement_api-redhat_spec.rb b/spec/placement_api-redhat_spec.rb index 22785e69..a626936e 100644 --- a/spec/placement_api-redhat_spec.rb +++ b/spec/placement_api-redhat_spec.rb @@ -9,7 +9,7 @@ describe 'openstack-compute::placement_api' do cached(:chef_run) { runner.converge(described_recipe) } include_context 'compute_stubs' - include_examples 'expect_runs_nova_common_recipe' + include_examples 'expect_runs_nova_apache_recipe' include_examples 'expect_creates_nova_state_dir' include_examples 'expect_creates_nova_lock_dir' diff --git a/spec/placement_api_spec.rb b/spec/placement_api_spec.rb index 28e7055b..6bb51cdf 100644 --- a/spec/placement_api_spec.rb +++ b/spec/placement_api_spec.rb @@ -10,9 +10,7 @@ describe 'openstack-compute::placement_api' do include_context 'compute_stubs' - it 'includes nova-common recipe' do - expect(chef_run).to include_recipe 'openstack-compute::nova-common' - end + include_examples 'expect_runs_nova_apache_recipe' it do expect(chef_run).to upgrade_package %w(python3-nova libapache2-mod-wsgi-py3 nova-placement-api) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 71373052..11d31c94 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -140,6 +140,12 @@ shared_examples 'expect_volume_packages' do end end +shared_examples 'expect_runs_nova_apache_recipe' do + it 'includes _nova_apache' do + expect(chef_run).to include_recipe 'openstack-compute::_nova_apache' + end +end + shared_examples 'expect_runs_nova_common_recipe' do it 'includes nova-common' do expect(chef_run).to include_recipe 'openstack-compute::nova-common'