From 2fc511323f2c8ddf7d80e2ff931f33e7e0835165 Mon Sep 17 00:00:00 2001 From: Lance Albertson Date: Wed, 23 Oct 2019 12:51:56 -0700 Subject: [PATCH] Create attribute for setting options passed to ceilometer-upgrade I ran into a problem similar to this one [1] where testing gnocchi commands did not work properly. The key problem is the fact that `--skip-gnocchi-resource-types` was included in the ceilometer-upgrade command. To allow an easy work around, I figure we can just create an attribute which can add any option to ceilometer-upgrade so you can set it to '' if you don't want it. It might be debatable on whether to just default to run it with out ceilometer-upgrade instead. Some additional fixes include: - Move the ceilometer-upgrade command to a new setup recipe where it makes more sense since it needs to be run after Ceilometer and Gnocchi are setup. - Fix name of gnocchi-metricd_service for RHEL - Add same apache restart fixes that we implemented in other cookbooks. This is needed so that you can properly run ceilometer-upgrade with gnocchi enabled. [1] https://bugs.launchpad.net/openstack-ansible/+bug/1737096 Change-Id: I619ef044b8cb254b23e0c7bc674c46d5dd7e0076 Signed-off-by: Lance Albertson --- README.md | 3 +++ attributes/default.rb | 3 ++- recipes/collector.rb | 5 ----- recipes/gnocchi_configure.rb | 33 +++++++++++++++++++++++++++++ recipes/setup.rb | 28 ++++++++++++++++++++++++ spec/collector_spec.rb | 6 ------ spec/gnocchi_configure-rhel_spec.rb | 4 ++++ spec/gnocchi_configure_spec.rb | 30 ++++++++++++++++++++++++++ spec/setup_spec.rb | 32 ++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 10 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 recipes/setup.rb create mode 100644 spec/setup_spec.rb diff --git a/README.md b/README.md index 132a22a..5c610bc 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,9 @@ Recipes ## common - Common metering configuration. +## setup +- Run database migrations + ## identity_registration - Registers the endpoints, tenant and user for metering and metric service with Keystone. diff --git a/attributes/default.rb b/attributes/default.rb index c977496..9650dab 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -51,6 +51,7 @@ default['openstack']['telemetry_metric']['conf_dir'] = '/etc/gnocchi' default['openstack']['telemetry_metric']['conf_file'] = ::File.join(node['openstack']['telemetry_metric']['conf_dir'], 'gnocchi.conf') default['openstack']['telemetry']['syslog']['use'] = false +default['openstack']['telemetry']['upgrade_opts'] = '--skip-gnocchi-resource-types' default['openstack']['aodh']['conf_dir'] = '/etc/aodh' default['openstack']['aodh']['conf_file'] = @@ -102,7 +103,7 @@ when 'rhel' 'common_packages' => ['openstack-ceilometer-common'], 'gnocchi_packages' => ['openstack-gnocchi-api', 'openstack-gnocchi-metricd'], 'gnocchi-api_service' => 'openstack-gnocchi-api', - 'gnocchi-metricd_service' => 'openstack-gnocchi-metricd', + 'gnocchi-metricd_service' => 'gnocchi-metricd', 'agent_central_packages' => ['openstack-ceilometer-central'], 'agent_central_service' => 'openstack-ceilometer-central', 'agent_compute_packages' => ['openstack-ceilometer-compute'], diff --git a/recipes/collector.rb b/recipes/collector.rb index a0524c9..7548474 100644 --- a/recipes/collector.rb +++ b/recipes/collector.rb @@ -30,11 +30,6 @@ platform['collector_packages'].each do |pkg| end end -conf_switch = "--config-file #{node['openstack']['telemetry']['conf_file']}" -execute 'database migration' do - command "ceilometer-upgrade --skip-gnocchi-resource-types #{conf_switch}" -end - service 'ceilometer-collector' do service_name platform['collector_service'] subscribes :restart, "template[#{node['openstack']['telemetry']['conf_file']}]" diff --git a/recipes/gnocchi_configure.rb b/recipes/gnocchi_configure.rb index affe210..db8712d 100644 --- a/recipes/gnocchi_configure.rb +++ b/recipes/gnocchi_configure.rb @@ -43,6 +43,12 @@ node.default['openstack']['telemetry_metric']['conf'].tap do |conf| conf['keystone_authtoken']['auth_url'] = auth_url end +# Clear lock file when notified +execute 'Clear gnocchi apache restart' do + command "rm -f #{Chef::Config[:file_cache_path]}/gnocchi-apache-restarted" + action :nothing +end + # merge all config options and secrets to be used in the gnocchi.conf gnocchi_conf_options = merge_config_options 'telemetry_metric' template node['openstack']['telemetry_metric']['conf_file'] do @@ -54,6 +60,7 @@ template node['openstack']['telemetry_metric']['conf_file'] do variables( service_config: gnocchi_conf_options ) + notifies :run, 'execute[Clear gnocchi apache restart]', :immediately end # drop gnocchi_resources.yaml to ceilometer folder (current workaround since not @@ -160,6 +167,32 @@ web_app 'gnocchi-api' do ciphers node['openstack']['telemetry_metric']['ssl']['ciphers'] end +# Hack until Apache cookbook has lwrp's for proper use of notify restart +# apache2 after gnocchi-api if completely configured. Whenever a gnocchi +# 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/gnocchi-api.conf") do + notifies :run, 'execute[Clear gnocchi apache restart]', :immediately +end + +# Only restart gnocchi apache during the initial install. This causes +# monitoring and service issues while the service is restarted so we +# should minimize the amount of times we restart apache. +execute 'gnocchi apache restart' do + command "touch #{Chef::Config[:file_cache_path]}/gnocchi-apache-restarted" + creates "#{Chef::Config[:file_cache_path]}/gnocchi-apache-restarted" + notifies :run, 'execute[restore-selinux-context-gnocchi]', :immediately + notifies :restart, 'service[apache2]', :immediately +end + +execute 'restore-selinux-context-gnocchi' do + command 'restorecon -Rv /etc/httpd /etc/pki || :' + action :nothing + only_if { platform_family?('rhel') } +end + service 'gnocchi-metricd' do service_name platform['gnocchi-metricd_service'] subscribes :restart, "template[#{node['openstack']['telemetry_metric']['conf_file']}]" diff --git a/recipes/setup.rb b/recipes/setup.rb new file mode 100644 index 0000000..2f4190b --- /dev/null +++ b/recipes/setup.rb @@ -0,0 +1,28 @@ +# encoding: UTF-8 +# +# Cookbook Name:: openstack-telemetry +# Recipe:: common +# +# Copyright 2019, Oregon State University +# +# 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. +# + +class ::Chef::Recipe + include ::Openstack +end + +conf_switch = "--config-file #{node['openstack']['telemetry']['conf_file']}" +execute 'ceilometer database migration' do + command "ceilometer-upgrade #{node['openstack']['telemetry']['upgrade_opts']} #{conf_switch}" +end diff --git a/spec/collector_spec.rb b/spec/collector_spec.rb index 2123660..ba777bc 100644 --- a/spec/collector_spec.rb +++ b/spec/collector_spec.rb @@ -15,12 +15,6 @@ describe 'openstack-telemetry::collector' do expect(chef_run).to upgrade_package 'ceilometer-collector' end - it do - expect(chef_run).to run_execute( - 'ceilometer-upgrade --skip-gnocchi-resource-types --config-file /etc/ceilometer/ceilometer.conf' - ) - end - it do expect(chef_run).to upgrade_package('python-mysqldb') end diff --git a/spec/gnocchi_configure-rhel_spec.rb b/spec/gnocchi_configure-rhel_spec.rb index 5a35172..3044085 100644 --- a/spec/gnocchi_configure-rhel_spec.rb +++ b/spec/gnocchi_configure-rhel_spec.rb @@ -19,5 +19,9 @@ describe 'openstack-telemetry::gnocchi_configure' do mode: 0o0640 ) end + + it do + expect(chef_run).to nothing_execute('restore-selinux-context-gnocchi').with(command: 'restorecon -Rv /etc/httpd /etc/pki || :') + end end end diff --git a/spec/gnocchi_configure_spec.rb b/spec/gnocchi_configure_spec.rb index 94942c0..383df19 100644 --- a/spec/gnocchi_configure_spec.rb +++ b/spec/gnocchi_configure_spec.rb @@ -238,6 +238,36 @@ describe 'openstack-telemetry::gnocchi_configure' do end end end + + describe 'restart apache' do + it do + expect(chef_run).to nothing_execute('Clear gnocchi apache restart') + .with( + command: 'rm -f /var/chef/cache/gnocchi-apache-restarted' + ) + end + %w( + /etc/gnocchi/gnocchi.conf + /etc/apache2/sites-available/gnocchi-api.conf + ).each do |f| + it "#{f} notifies execute[Clear gnocchi apache restart]" do + expect(chef_run.template(f)).to notify('execute[Clear gnocchi apache restart]').to(:run).immediately + end + end + it do + expect(chef_run).to run_execute('gnocchi apache restart') + .with( + command: 'touch /var/chef/cache/gnocchi-apache-restarted', + creates: '/var/chef/cache/gnocchi-apache-restarted' + ) + end + it do + expect(chef_run.execute('gnocchi apache restart')).to notify('execute[restore-selinux-context-gnocchi]').to(:run).immediately + end + it do + expect(chef_run.execute('gnocchi apache restart')).to notify('service[apache2]').to(:restart).immediately + end + end end end end diff --git a/spec/setup_spec.rb b/spec/setup_spec.rb new file mode 100644 index 0000000..c0f761a --- /dev/null +++ b/spec/setup_spec.rb @@ -0,0 +1,32 @@ +# encoding: UTF-8 + +require_relative 'spec_helper' + +describe 'openstack-telemetry::setup' do + describe 'ubuntu' do + let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } + let(:node) { runner.node } + let(:chef_run) { runner.converge(described_recipe) } + + include_context 'telemetry-stubs' + + it do + expect(chef_run).to run_execute('ceilometer database migration') + .with( + command: 'ceilometer-upgrade --skip-gnocchi-resource-types --config-file /etc/ceilometer/ceilometer.conf' + ) + end + + context 'Non-default upgrade_opts' do + before do + node.override['openstack']['telemetry']['upgrade_opts'] = '' + end + it do + expect(chef_run).to run_execute('ceilometer database migration') + .with( + command: 'ceilometer-upgrade --config-file /etc/ceilometer/ceilometer.conf' + ) + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ed8add1..f7f965f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,6 +10,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 = {