diff --git a/spec/agent-central-rhel_spec.rb b/spec/agent-central-rhel_spec.rb index 3ee1c12..7779c5b 100644 --- a/spec/agent-central-rhel_spec.rb +++ b/spec/agent-central-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-central' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' diff --git a/spec/agent-central_spec.rb b/spec/agent-central_spec.rb index ba05faa..217aa3e 100644 --- a/spec/agent-central_spec.rb +++ b/spec/agent-central_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-central' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' @@ -22,13 +22,16 @@ describe 'openstack-telemetry::agent-central' do describe 'ceilometer-agent-central' do it 'subscribes to its config file' do - expect(chef_run.service('ceilometer-agent-central')).to subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed + expect(chef_run.service('ceilometer-agent-central')).to \ + subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed end it 'subscribes to /etc/ceilometer/pipeline.yaml' do - expect(chef_run.service('ceilometer-agent-central')).to subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed + expect(chef_run.service('ceilometer-agent-central')).to \ + subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed end it 'subscribes to /etc/ceilometer/polling.yaml' do - expect(chef_run.service('ceilometer-agent-central')).to subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed + expect(chef_run.service('ceilometer-agent-central')).to \ + subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed end end end diff --git a/spec/agent-compute-rhel_spec.rb b/spec/agent-compute-rhel_spec.rb index 9660f7d..bcdfb6a 100644 --- a/spec/agent-compute-rhel_spec.rb +++ b/spec/agent-compute-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-compute' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' diff --git a/spec/agent-compute_spec.rb b/spec/agent-compute_spec.rb index 345bf70..1e4d9ec 100644 --- a/spec/agent-compute_spec.rb +++ b/spec/agent-compute_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-compute' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' @@ -22,13 +22,16 @@ describe 'openstack-telemetry::agent-compute' do describe 'ceilometer-agent-compute' do it 'subscribes to its config file' do - expect(chef_run.service('ceilometer-agent-compute')).to subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed + expect(chef_run.service('ceilometer-agent-compute')).to \ + subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed end it 'subscribes to /etc/ceilometer/pipeline.yaml' do - expect(chef_run.service('ceilometer-agent-compute')).to subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed + expect(chef_run.service('ceilometer-agent-compute')).to \ + subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed end it 'subscribes to /etc/ceilometer/polling.yaml' do - expect(chef_run.service('ceilometer-agent-compute')).to subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed + expect(chef_run.service('ceilometer-agent-compute')).to \ + subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed end end end diff --git a/spec/agent-notification-rhel_spec.rb b/spec/agent-notification-rhel_spec.rb index 744e1c2..a231ded 100644 --- a/spec/agent-notification-rhel_spec.rb +++ b/spec/agent-notification-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-notification' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' diff --git a/spec/agent-notification_spec.rb b/spec/agent-notification_spec.rb index 4da4a51..68b8ee5 100644 --- a/spec/agent-notification_spec.rb +++ b/spec/agent-notification_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::agent-notification' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' @@ -22,13 +22,16 @@ describe 'openstack-telemetry::agent-notification' do describe 'ceilometer-agent-notification' do it 'subscribes to its config file' do - expect(chef_run.service('ceilometer-agent-notification')).to subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed + expect(chef_run.service('ceilometer-agent-notification')).to \ + subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed end it 'subscribes to /etc/ceilometer/pipeline.yaml' do - expect(chef_run.service('ceilometer-agent-notification')).to subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed + expect(chef_run.service('ceilometer-agent-notification')).to \ + subscribe_to('template[/etc/ceilometer/pipeline.yaml]').delayed end it 'subscribes to /etc/ceilometer/polling.yaml' do - expect(chef_run.service('ceilometer-agent-notification')).to subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed + expect(chef_run.service('ceilometer-agent-notification')).to \ + subscribe_to('template[/etc/ceilometer/polling.yaml]').delayed end end end diff --git a/spec/collector-rhel_spec.rb b/spec/collector-rhel_spec.rb index 48d8fae..59424fd 100644 --- a/spec/collector-rhel_spec.rb +++ b/spec/collector-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::collector' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' diff --git a/spec/collector_spec.rb b/spec/collector_spec.rb index 24185aa..1d58b54 100644 --- a/spec/collector_spec.rb +++ b/spec/collector_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::collector' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' include_examples 'expect-runs-common-recipe' @@ -29,7 +29,8 @@ describe 'openstack-telemetry::collector' do describe 'ceilometer-collector' do it 'subscribes to its config file' do - expect(chef_run.service('ceilometer-collector')).to subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed + expect(chef_run.service('ceilometer-collector')).to \ + subscribe_to('template[/etc/ceilometer/ceilometer.conf]').delayed end end end diff --git a/spec/common-rhel_spec.rb b/spec/common-rhel_spec.rb index 22a5a26..b2e66a3 100644 --- a/spec/common-rhel_spec.rb +++ b/spec/common-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::common' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' diff --git a/spec/common_spec.rb b/spec/common_spec.rb index 7312f92..a403efc 100644 --- a/spec/common_spec.rb +++ b/spec/common_spec.rb @@ -6,13 +6,14 @@ describe 'openstack-telemetry::common' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' context 'with logging enabled' do - before do + cached(:chef_run) do node.override['openstack']['telemetry']['syslog']['use'] = true + runner.converge(described_recipe) end it 'runs logging recipe' do diff --git a/spec/gnocchi_configure-rhel_spec.rb b/spec/gnocchi_configure-rhel_spec.rb index 3044085..b45d203 100644 --- a/spec/gnocchi_configure-rhel_spec.rb +++ b/spec/gnocchi_configure-rhel_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::gnocchi_configure' do describe 'rhel' do let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' @@ -21,7 +21,8 @@ describe 'openstack-telemetry::gnocchi_configure' do end it do - expect(chef_run).to nothing_execute('restore-selinux-context-gnocchi').with(command: 'restorecon -Rv /etc/httpd /etc/pki || :') + 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 383df19..f2d9ab2 100644 --- a/spec/gnocchi_configure_spec.rb +++ b/spec/gnocchi_configure_spec.rb @@ -4,7 +4,7 @@ describe 'openstack-telemetry::gnocchi_configure' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' @@ -94,19 +94,18 @@ describe 'openstack-telemetry::gnocchi_configure' do %w(tmp measure cache).each do |dir| describe "gnocchi #{dir} dir" do - context 'file as storage backend' do - it do - expect(chef_run).to create_directory("/var/lib/gnocchi/#{dir}") - .with( - user: 'gnocchi', - group: 'gnocchi', - mode: 0o750 - ) - end + it 'file as storage backend' do + expect(chef_run).to create_directory("/var/lib/gnocchi/#{dir}") + .with( + user: 'gnocchi', + group: 'gnocchi', + mode: 0o750 + ) end context 'other storage backend' do - before do + cached(:chef_run) do node.override['openstack']['telemetry_metric']['conf']['storage']['driver'] = 'ceph' + runner.converge(described_recipe) end it do expect(chef_run).to_not create_directory("/var/lib/gnocchi/#{dir}") @@ -143,9 +142,14 @@ describe 'openstack-telemetry::gnocchi_configure' do expect(chef_run).not_to include_recipe('apache2::mod_ssl') end - it 'include apache recipes' do - node.override['openstack']['identity']['ssl']['enabled'] = true - expect(chef_run).to include_recipe('apache2::mod_ssl') + context 'include apache recipes' do + cached(:chef_run) do + node.override['openstack']['identity']['ssl']['enabled'] = true + runner.converge(described_recipe) + end + it do + expect(chef_run).to include_recipe('apache2::mod_ssl') + end end end @@ -175,65 +179,88 @@ describe 'openstack-telemetry::gnocchi_configure' do ) end - it "configures #{file} common lines" do - node.override['openstack']['telemetry_metric']['custom_template_banner'] = 'custom_template_banner_value' - [/user=gnocchi/, - /group=gnocchi/, - %r{^ ErrorLog /var/log/apache2/gnocchi-api_error.log$}, - %r{^ CustomLog /var/log/apache2/gnocchi-api_access.log combined$}].each do |line| - expect(chef_run).to render_file(file).with_content(line) + context "configures #{file} common lines" do + cached(:chef_run) do + node.override['openstack']['telemetry_metric']['custom_template_banner'] = 'custom_template_banner_value' + runner.converge(described_recipe) + end + [ + /user=gnocchi/, + /group=gnocchi/, + %r{^ ErrorLog /var/log/apache2/gnocchi-api_error.log$}, + %r{^ CustomLog /var/log/apache2/gnocchi-api_access.log combined$}, + ].each do |line| + it do + expect(chef_run).to render_file(file).with_content(line) + end end end it "does not configure #{file} triggered common lines" do - [/^ LogLevel/, - /^ SSL/].each do |line| + [ + /^ LogLevel/, + /^ SSL/, + ].each do |line| expect(chef_run).not_to render_file(file).with_content(line) end end context 'Enable SSL' do - before do + cached(:chef_run) do node.override['openstack']['telemetry_metric']['ssl']['enabled'] = true + runner.converge(described_recipe) end it "configures #{file} common ssl lines" do - [/^ SSLEngine On$/, - %r{^ SSLCertificateFile /etc/ceilometer/ssl/certs/sslcert.pem$}, - %r{^ SSLCertificateKeyFile /etc/ceilometer/ssl/private/sslkey.pem$}, - %r{^ SSLCACertificatePath /etc/ceilometer/ssl/certs/$}, - /^ SSLProtocol All -SSLv2 -SSLv3$/].each do |line| + [ + /^ SSLEngine On$/, + %r{^ SSLCertificateFile /etc/ceilometer/ssl/certs/sslcert.pem$}, + %r{^ SSLCertificateKeyFile /etc/ceilometer/ssl/private/sslkey.pem$}, + %r{^ SSLCACertificatePath /etc/ceilometer/ssl/certs/$}, + /^ SSLProtocol All -SSLv2 -SSLv3$/, + ].each do |line| expect(chef_run).to render_file(file).with_content(line) end end it "does not configure #{file} common ssl lines" do - [/^ SSLCertificateChainFile/, - /^ SSLCipherSuite/, - /^ SSLVerifyClient require/].each do |line| + [ + /^ SSLCertificateChainFile/, + /^ SSLCipherSuite/, + /^ SSLVerifyClient require/, + ].each do |line| expect(chef_run).not_to render_file(file).with_content(line) end end - it "configures #{file} chainfile when set" do - node.override['openstack']['telemetry_metric']['ssl']['chainfile'] = '/etc/ceilometer/ssl/certs/chainfile.pem' - expect(chef_run).to render_file(file) - .with_content(%r{^ SSLCertificateChainFile /etc/ceilometer/ssl/certs/chainfile.pem$}) - end - it "configures #{file} ciphers when set" do - node.override['openstack']['telemetry_metric']['ssl']['ciphers'] = 'ciphers_value' - expect(chef_run).to render_file(file) - .with_content(/^ SSLCipherSuite ciphers_value$/) - end - it "configures #{file} cert_required set" do - node.override['openstack']['telemetry_metric']['ssl']['cert_required'] = true - expect(chef_run).to render_file(file) - .with_content(/^ SSLVerifyClient require$/) + context 'Enable chainfile, ciphers, cert_required' do + cached(:chef_run) do + node.override['openstack']['telemetry_metric']['ssl']['enabled'] = true + node.override['openstack']['telemetry_metric']['ssl']['chainfile'] = + '/etc/ceilometer/ssl/certs/chainfile.pem' + node.override['openstack']['telemetry_metric']['ssl']['ciphers'] = 'ciphers_value' + node.override['openstack']['telemetry_metric']['ssl']['cert_required'] = true + runner.converge(described_recipe) + end + it "configures #{file} chainfile when set" do + expect(chef_run).to render_file(file) + .with_content(%r{^ SSLCertificateChainFile /etc/ceilometer/ssl/certs/chainfile.pem$}) + end + it "configures #{file} ciphers when set" do + expect(chef_run).to render_file(file) + .with_content(/^ SSLCipherSuite ciphers_value$/) + end + it "configures #{file} cert_required set" do + expect(chef_run).to render_file(file) + .with_content(/^ SSLVerifyClient require$/) + end end end describe 'gnocchi-api WSGI app' do it 'configures required lines' do - [/^$/, - /^ WSGIDaemonProcess gnocchi-api/, - /^ WSGIProcessGroup gnocchi-api$/, - %r{^ WSGIScriptAlias / /var/www/html/gnocchi/app$}].each do |line| + [ + /^$/, + /^ WSGIDaemonProcess gnocchi-api/, + /^ WSGIProcessGroup gnocchi-api$/, + %r{^ WSGIScriptAlias / /var/www/html/gnocchi/app$}, + ].each do |line| expect(chef_run).to render_file('/etc/apache2/sites-available/gnocchi-api.conf').with_content(line) end end @@ -262,10 +289,12 @@ describe 'openstack-telemetry::gnocchi_configure' do ) end it do - expect(chef_run.execute('gnocchi apache restart')).to notify('execute[restore-selinux-context-gnocchi]').to(:run).immediately + 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 + expect(chef_run.execute('gnocchi apache restart')).to \ + notify('service[apache2]').to(:restart).immediately end end end diff --git a/spec/gnocchi_install_spec.rb b/spec/gnocchi_install_spec.rb index 9dbaa6a..a3a7ebb 100644 --- a/spec/gnocchi_install_spec.rb +++ b/spec/gnocchi_install_spec.rb @@ -6,11 +6,17 @@ describe 'openstack-telemetry::gnocchi_install' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' - %w(python3-gnocchi gnocchi-common gnocchi-api gnocchi-metricd python3-gnocchiclient).each do |p| + %w( + gnocchi-api + gnocchi-common + gnocchi-metricd + python3-gnocchi + python3-gnocchiclient + ).each do |p| it do expect(chef_run).to upgrade_package p end diff --git a/spec/identity_registration_spec.rb b/spec/identity_registration_spec.rb index d0dd3bf..84de9e5 100644 --- a/spec/identity_registration_spec.rb +++ b/spec/identity_registration_spec.rb @@ -6,7 +6,7 @@ describe 'openstack-telemetry::identity_registration' do describe 'ubuntu' do let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) } let(:node) { runner.node } - let(:chef_run) { runner.converge(described_recipe) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' @@ -56,7 +56,7 @@ describe 'openstack-telemetry::identity_registration' do end unless telemetry_service == 'telemetry' - context "registers #{service_name} endpoint" do + describe "registers #{service_name} endpoint" do %w(internal public).each do |interface| it "#{interface} endpoint with default values" do expect(chef_run).to create_openstack_endpoint( diff --git a/spec/setup_spec.rb b/spec/setup_spec.rb index c0f761a..82a60e5 100644 --- a/spec/setup_spec.rb +++ b/spec/setup_spec.rb @@ -6,7 +6,7 @@ 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) } + cached(:chef_run) { runner.converge(described_recipe) } include_context 'telemetry-stubs' @@ -18,8 +18,9 @@ describe 'openstack-telemetry::setup' do end context 'Non-default upgrade_opts' do - before do + cached(:chef_run) do node.override['openstack']['telemetry']['upgrade_opts'] = '' + runner.converge(described_recipe) end it do expect(chef_run).to run_execute('ceilometer database migration') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f7f965f..a11ba73 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,25 +1,22 @@ # encoding: UTF-8 require 'chefspec' require 'chefspec/berkshelf' - -ChefSpec::Coverage.start! { add_filter 'openstack-telemetry' } - require 'chef/application' RSpec.configure do |config| config.color = true config.formatter = :documentation - config.log_level = :fatal + config.log_level = :warn config.file_cache_path = '/var/chef/cache' end REDHAT_OPTS = { platform: 'redhat', - version: '7.4', + version: '7', }.freeze UBUNTU_OPTS = { platform: 'ubuntu', - version: '16.04', + version: '18.04', }.freeze shared_context 'telemetry-stubs' do