Improve ChefSpec test speed by enabling caching

This updates all references of let(:chef_run) to cached(:chef_run) to
speed up tests. By doing this, we have to create a new cached(:chef_run)
block whenever we need to adjust node attributes for testing.

Speed was improved from 5 minutes 36 seconds to 48.07 seconds

Change-Id: I4e88431d863450b6f41d6711612bfb12d4024683
This commit is contained in:
Lance Albertson 2020-01-06 14:51:41 -08:00
parent 0b218495a9
commit 8b478fbe41
7 changed files with 21 additions and 18 deletions

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::api-cfn' do
describe 'redhat' 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 'orchestration_stubs'
include_examples 'expect runs openstack orchestration common recipe'

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::api' do
describe 'redhat' 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 'orchestration_stubs'
include_examples 'expect runs openstack orchestration common recipe'

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::common' do
describe 'redhat' 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 'orchestration_stubs'
include_examples 'logging'

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::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 'orchestration_stubs'
include_examples 'logging'

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::engine' do
describe 'redhat' 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 'orchestration_stubs'
include_examples 'expect runs openstack orchestration common recipe'

View File

@ -5,7 +5,7 @@ describe 'openstack-orchestration::identity_registration' do
describe 'redhat' 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 'orchestration_stubs'

View File

@ -1,24 +1,21 @@
# encoding: UTF-8
require 'chefspec'
require 'chefspec/berkshelf'
ChefSpec::Coverage.start! { add_filter 'openstack-orchestration' }
require 'chef/application'
RSpec.configure do |config|
config.color = true
config.formatter = :documentation
config.log_level = :fatal
config.log_level = :warn
end
REDHAT_OPTS = {
platform: 'redhat',
version: '7.4',
version: '7',
}.freeze
UBUNTU_OPTS = {
platform: 'ubuntu',
version: '16.04',
version: '18.04',
}.freeze
shared_context 'orchestration_stubs' do
@ -121,7 +118,8 @@ shared_examples 'expects to create heat conf' do
end
it 'sets auth_encryption_key' do
expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^auth_encryption_key = auth_encryption_key_secret$/)
expect(chef_run).to render_config_file(file.name)
.with_section_content('DEFAULT', /^auth_encryption_key = auth_encryption_key_secret$/)
end
describe 'default values' do
@ -140,7 +138,8 @@ shared_examples 'expects to create heat conf' do
[
/^driver = heat.openstack.common.notifier.rpc_notifier$/,
].each do |line|
expect(chef_run).to render_config_file(file.name).with_section_content('oslo_messaging_notifications', line)
expect(chef_run).to render_config_file(file.name)
.with_section_content('oslo_messaging_notifications', line)
end
end
@ -171,13 +170,15 @@ shared_examples 'expects to create heat conf' do
describe 'has ec2authtoken values' do
it 'has default ec2authtoken values' do
expect(chef_run).to render_config_file(file.name).with_section_content('ec2authtoken', %r{^auth_uri = http://127.0.0.1:5000/v3$})
expect(chef_run).to render_config_file(file.name)
.with_section_content('ec2authtoken', %r{^auth_uri = http://127.0.0.1:5000/v3$})
end
end
describe 'has clients_keystone values' do
it 'has default clients_keystone values' do
expect(chef_run).to render_config_file(file.name).with_section_content('clients_keystone', %r{^auth_uri = http://127.0.0.1:5000/$})
expect(chef_run).to render_config_file(file.name)
.with_section_content('clients_keystone', %r{^auth_uri = http://127.0.0.1:5000/$})
end
end
@ -239,8 +240,9 @@ end
shared_examples 'logging' do
context 'with logging enabled' do
before do
cached(:chef_run) do
node.override['openstack']['orchestration']['syslog']['use'] = true
runner.converge(described_recipe)
end
it 'runs logging recipe if node attributes say to' do
@ -249,8 +251,9 @@ shared_examples 'logging' do
end
context 'with logging disabled' do
before do
cached(:chef_run) do
node.override['openstack']['orchestration']['syslog']['use'] = false
runner.converge(described_recipe)
end
it "doesn't run logging recipe" do