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.

backport: stein

Change-Id: I87dda61dfabec460fe042b4cee21277382dd9487
This commit is contained in:
Roger Luethi 2020-07-24 22:38:15 +02:00 committed by Jens Harbott
parent 6c69ce58b1
commit 5747451dcb
14 changed files with 69 additions and 26 deletions

32
recipes/_nova_apache.rb Normal file
View File

@ -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

View File

@ -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']

View File

@ -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']

View File

@ -181,16 +181,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'
@ -203,7 +193,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

View File

@ -24,7 +24,7 @@ class ::Chef::Recipe
include Apache2::Cookbook::Helpers
end
include_recipe 'openstack-compute::nova-common'
include_recipe 'openstack-compute::_nova_apache'
bind_service = node['openstack']['bind_service']['all']['placement-api']
placement_user = node['openstack']['placement']['user']

22
spec/_nova_apache_spec.rb Normal file
View File

@ -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

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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$},

View File

@ -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'

View File

@ -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-placement libapache2-mod-wsgi-py3)

View File

@ -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'