From 0566bf9578ba49b4eb1782d3e015e8c3603812a2 Mon Sep 17 00:00:00 2001 From: Lance Albertson Date: Tue, 9 Jul 2019 12:56:37 -0700 Subject: [PATCH] Properly notify apache restarts on cinder configuration updates This uses edit_resource to add a notification in the block storage apache configuration when it gets updated. This is a workaround due to the fact we are using a version of the apache2 cookbook that is still using definitions and cannot add notifications with definitions. This will be removed in the Stein release when we migrate to the newer apache2 cookbook which uses proper resources. Change-Id: I7efddef83333ca0794ee3c298ca1a2488defe941 Signed-off-by: Lance Albertson --- recipes/api.rb | 16 ++++++++++++++++ recipes/cinder-common.rb | 11 +++-------- spec/api_spec.rb | 30 +++++++++++++++++++++++++++++- spec/spec_helper.rb | 1 + 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/recipes/api.rb b/recipes/api.rb index bfbc21d..3c825a7 100644 --- a/recipes/api.rb +++ b/recipes/api.rb @@ -82,3 +82,19 @@ web_app 'cinder-api' do protocol node['openstack']['block-storage']['ssl']['protocol'] ciphers node['openstack']['block-storage']['ssl']['ciphers'] end + +# Hack until Apache cookbook has lwrp's for proper use of notify restart +# apache2 after keystone if completely configured. Whenever a cinder +# config is updated, have it notify the resource which clears the lock +# so the service can be restarted. +# TODO(ramereth): This should be removed once this cookbook is updated +# to use the newer apache2 cookbook which uses proper resources. +edit_resource(:template, "#{node['apache']['dir']}/sites-available/cinder-api.conf") do + notifies :run, 'execute[Clear cinder-api apache restart]', :immediately +end + +execute 'cinder-api apache restart' do + command "touch #{Chef::Config[:file_cache_path]}/cinder-api-apache-restarted" + creates "#{Chef::Config[:file_cache_path]}/cinder-api-apache-restarted" + notifies :restart, 'service[apache2]', :immediately +end diff --git a/recipes/cinder-common.rb b/recipes/cinder-common.rb index b560b4d..94acd90 100644 --- a/recipes/cinder-common.rb +++ b/recipes/cinder-common.rb @@ -83,13 +83,8 @@ end # merge all config options and secrets to be used in the cinder.conf.erb cinder_conf_options = merge_config_options 'block-storage' -service 'cinder-apache2' do - case node['platform_family'] - when 'debian' - service_name 'apache2' - when 'rhel' - service_name 'httpd' - end +execute 'Clear cinder-api apache restart' do + command "rm -f #{Chef::Config[:file_cache_path]}/cinder-api-apache-restarted" action :nothing end @@ -102,7 +97,7 @@ template '/etc/cinder/cinder.conf' do variables( service_config: cinder_conf_options ) - notifies :restart, 'service[cinder-apache2]' + notifies :run, 'execute[Clear cinder-api apache restart]', :immediately end # delete all secrets saved in the attribute diff --git a/spec/api_spec.rb b/spec/api_spec.rb index 81a40d6..038d555 100644 --- a/spec/api_spec.rb +++ b/spec/api_spec.rb @@ -12,7 +12,35 @@ describe 'openstack-block-storage::api' do include_context 'block-storage-stubs' include_examples 'common-logging' - include_examples 'creates_cinder_conf', 'service[cinder-apache2]', 'cinder', 'cinder' + include_examples 'creates_cinder_conf', 'execute[Clear cinder-api apache restart]', 'cinder', 'cinder', 'run' + + it do + expect(chef_run).to nothing_execute('Clear cinder-api apache restart') + .with( + command: 'rm -f /var/chef/cache/cinder-api-apache-restarted' + ) + end + + %w( + /etc/cinder/cinder.conf + /etc/apache2/sites-available/cinder-api.conf + ).each do |f| + it "#{f} notifies execute[Clear cinder-api apache restart]" do + expect(chef_run.template(f)).to notify('execute[Clear cinder-api apache restart]').to(:run).immediately + end + end + + it do + expect(chef_run).to run_execute('cinder-api apache restart') + .with( + command: 'touch /var/chef/cache/cinder-api-apache-restarted', + creates: '/var/chef/cache/cinder-api-apache-restarted' + ) + end + + it do + expect(chef_run.execute('cinder-api apache restart')).to notify('service[apache2]').to(:restart).immediately + end it 'upgrades cinder api packages' do expect(chef_run).to upgrade_package('cinder-api') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 073be16..b418e50 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,6 +13,7 @@ RSpec.configure do |config| config.color = true config.formatter = :documentation config.log_level = :fatal + config.file_cache_path = '/var/chef/cache' end REDHAT_OPTS = {