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 <lance@osuosl.org>
This commit is contained in:
Lance Albertson 2019-10-23 12:51:56 -07:00
parent f78fc972d0
commit 2fc511323f
10 changed files with 133 additions and 12 deletions

View File

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

View File

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

View File

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

View File

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

28
recipes/setup.rb Normal file
View File

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

View File

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

View File

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

View File

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

32
spec/setup_spec.rb Normal file
View File

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

View File

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