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. - Remove unused default recipe ChefSpec - Formatting cleanup Speed was improved from 3 minutes 9.1 seconds to 38.21 seconds Change-Id: I470991c600bca0ad2b6a389923a2fe8c954b7008
This commit is contained in:
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::api' 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 'block-storage-stubs'
|
||||
include_examples 'common-logging'
|
||||
@@ -60,8 +60,11 @@ describe 'openstack-block-storage::api' do
|
||||
it 'does not manage policy file unless specified' do
|
||||
expect(chef_run).not_to create_remote_file('/etc/cinder/policy.json')
|
||||
end
|
||||
describe 'policy file specified' do
|
||||
before { node.override['openstack']['block-storage']['policyfile_url'] = 'http://server/mypolicy.json' }
|
||||
context 'policy file specified' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['block-storage']['policyfile_url'] = 'http://server/mypolicy.json'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:remote_policy) { chef_run.remote_file('/etc/cinder/policy.json') }
|
||||
|
||||
it 'manages policy file when remote file is specified' do
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::backup' 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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::backup' 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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::cinder-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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,13 +8,21 @@ describe 'openstack-block-storage::cinder-common' do
|
||||
describe 'ubuntu' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
let(:test_pass) { 'test_pass' }
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['mq']['host'] = '127.0.0.1'
|
||||
node.override['openstack']['mq']['block-storage']['rabbit']['notification_topic'] = 'rabbit_topic'
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
before do
|
||||
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
|
||||
.with('user', anything)
|
||||
.and_return(test_pass)
|
||||
allow_any_instance_of(Chef::Recipe).to receive(:db_uri)
|
||||
.and_return('sql_connection_value')
|
||||
end
|
||||
|
||||
include_context 'block-storage-stubs'
|
||||
|
||||
it 'upgrades the cinder-common package' do
|
||||
@@ -35,12 +43,6 @@ describe 'openstack-block-storage::cinder-common' do
|
||||
|
||||
describe 'cinder.conf' do
|
||||
let(:file) { chef_run.template('/etc/cinder/cinder.conf') }
|
||||
let(:test_pass) { 'test_pass' }
|
||||
before do
|
||||
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
|
||||
.with('user', anything)
|
||||
.and_return(test_pass)
|
||||
end
|
||||
|
||||
it 'should create the cinder.conf template' do
|
||||
expect(chef_run).to create_template(file.name).with(
|
||||
@@ -50,7 +52,7 @@ describe 'openstack-block-storage::cinder-common' do
|
||||
)
|
||||
end
|
||||
|
||||
context 'keystone authtoken attributes with default values' do
|
||||
describe 'keystone authtoken attributes with default values' do
|
||||
it 'does not set memcached server(s)' do
|
||||
expect(chef_run).not_to render_file(file.name).with_content(/^memcached_servers = $/)
|
||||
end
|
||||
@@ -68,20 +70,22 @@ describe 'openstack-block-storage::cinder-common' do
|
||||
end
|
||||
end
|
||||
|
||||
context 'keystone authtoken attributes' do
|
||||
describe 'keystone authtoken attributes' do
|
||||
it do
|
||||
expect(chef_run).not_to render_file(file.name).with_content(/^auth_version = v2.0$/)
|
||||
end
|
||||
|
||||
it 'has an admin password' do
|
||||
# (fgimenez) the get_password mocking is set in spec/spec_helper.rb
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('keystone_authtoken', /^password = cinder-pass$/)
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('keystone_authtoken', /^password = cinder-pass$/)
|
||||
end
|
||||
end
|
||||
|
||||
context 'template contents' do
|
||||
describe 'template contents' do
|
||||
it 'has a lock_path attribute' do
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('oslo_concurrency', %r{^lock_path = /var/lib/cinder/tmp})
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('oslo_concurrency', %r{^lock_path = /var/lib/cinder/tmp})
|
||||
end
|
||||
|
||||
it 'does not have unique host id by default' do
|
||||
@@ -93,73 +97,67 @@ describe 'openstack-block-storage::cinder-common' do
|
||||
end
|
||||
|
||||
context 'syslog use' do
|
||||
it 'sets the log_config value when syslog is in use' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['block-storage']['syslog']['use'] = true
|
||||
|
||||
expect(chef_run).to render_file(file.name)
|
||||
.with_content(%r{^log_config = /etc/openstack/logging.conf$})
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'sets the log_config value when syslog is in use' do
|
||||
expect(chef_run).to render_file(file.name).with_content(%r{^log_config = /etc/openstack/logging.conf$})
|
||||
end
|
||||
end
|
||||
|
||||
it 'has a db connection attribute' do
|
||||
allow_any_instance_of(Chef::Recipe).to receive(:db_uri)
|
||||
.and_return('sql_connection_value')
|
||||
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('database', /^connection = sql_connection_value$/)
|
||||
end
|
||||
|
||||
it 'has a glance_api_servers attribute' do
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', %r{^glance_api_servers = http://127.0.0.1:9292$})
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('DEFAULT', %r{^glance_api_servers = http://127.0.0.1:9292$})
|
||||
end
|
||||
|
||||
context 'cinder endpoint' do
|
||||
describe 'cinder endpoint' do
|
||||
it 'has osapi_volume_listen set' do
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^osapi_volume_listen = 127.0.0.1$/)
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('DEFAULT', /^osapi_volume_listen = 127.0.0.1$/)
|
||||
end
|
||||
|
||||
it 'has osapi_volume_listen_port set' do
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', /^osapi_volume_listen_port = 8776$/)
|
||||
expect(chef_run).to render_config_file(file.name)
|
||||
.with_section_content('DEFAULT', /^osapi_volume_listen_port = 8776$/)
|
||||
end
|
||||
end
|
||||
it 'has default transport_url/AMQP options set' do
|
||||
[%r{^transport_url = rabbit://guest:mypass@127.0.0.1:5672$}].each do |line|
|
||||
[
|
||||
%r{^transport_url = rabbit://guest:mypass@127.0.0.1:5672$},
|
||||
].each do |line|
|
||||
expect(chef_run).to render_config_file(file.name).with_section_content('DEFAULT', line)
|
||||
end
|
||||
end
|
||||
|
||||
context 'rabbitmq as mq service' do
|
||||
context 'non ha attributes' do
|
||||
before do
|
||||
node.override['openstack']['mq']['block-storage']['rabbit']['ha'] = false
|
||||
end
|
||||
|
||||
describe 'rabbitmq as mq service' do
|
||||
describe 'non ha attributes' do
|
||||
it 'does not have a rabbit_hosts attribute' do
|
||||
expect(chef_run).not_to render_config_file(file.name).with_section_content('oslo_messaging_rabbit', /^rabbit_hosts = /)
|
||||
expect(chef_run).not_to render_config_file(file.name)
|
||||
.with_section_content('oslo_messaging_rabbit', /^rabbit_hosts = /)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'lvm settings' do
|
||||
before do
|
||||
node.override['openstack']['block-storage']['volume']['driver'] = 'cinder.volume.drivers.lvm.LVMVolumeDriver'
|
||||
end
|
||||
end
|
||||
|
||||
context 'commonly named volume attributes' do
|
||||
%w(iscsi_ip_address iscsi_port iscsi_helper volumes_dir).each do |attr|
|
||||
it "has volume related #{attr} attribute" do
|
||||
vol_attrs = %w(iscsi_ip_address iscsi_port iscsi_helper volumes_dir)
|
||||
cached(:chef_run) do
|
||||
vol_attrs.each do |attr|
|
||||
node.override['openstack']['block-storage']['conf']['DEFAULT'][attr] = "common_volume_#{attr}_value"
|
||||
end
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
vol_attrs.each do |attr|
|
||||
it "has volume related #{attr} attribute" do
|
||||
expect(chef_run).to render_file(file.name).with_content(/^#{attr} = common_volume_#{attr}_value$/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'netapp ISCSI settings' do
|
||||
before do
|
||||
node.override['openstack']['block-storage']['conf']['DEFAULT']['volume_driver'] = 'cinder.volume.drivers.netapp.NetAppISCSIDriver'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -1,8 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
#
|
||||
# Cookbook Name:: openstack-block-storage
|
||||
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-block-storage::default' do
|
||||
end
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::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 'block-storage-stubs'
|
||||
|
||||
@@ -83,11 +83,16 @@ describe 'openstack-block-storage::identity_registration' do
|
||||
end
|
||||
end
|
||||
|
||||
it 'with custom region override' do
|
||||
node.override['openstack']['block-storage']['region'] = 'volumeRegion'
|
||||
expect(chef_run).to create_openstack_endpoint(
|
||||
service_type
|
||||
).with(region: 'volumeRegion')
|
||||
context 'with custom region override' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['block-storage']['region'] = 'volumeRegion'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it do
|
||||
expect(chef_run).to create_openstack_endpoint(
|
||||
service_type
|
||||
).with(region: 'volumeRegion')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::scheduler' 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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::scheduler' 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 'block-storage-stubs'
|
||||
include_examples 'common-logging'
|
||||
|
@@ -4,25 +4,22 @@
|
||||
|
||||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
|
||||
ChefSpec::Coverage.start! { add_filter 'openstack-block-storage' }
|
||||
|
||||
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 'block-storage-stubs' do
|
||||
@@ -64,8 +61,9 @@ end
|
||||
|
||||
shared_examples 'common-logging' do
|
||||
context 'when syslog.use is true' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['block-storage']['syslog']['use'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'runs logging recipe if node attributes say to' do
|
||||
@@ -74,8 +72,9 @@ shared_examples 'common-logging' do
|
||||
end
|
||||
|
||||
context 'when syslog.use is false' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['block-storage']['syslog']['use'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'runs logging recipe if node attributes say to' do
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::volume' 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 'block-storage-stubs'
|
||||
|
||||
|
@@ -8,7 +8,7 @@ describe 'openstack-block-storage::volume' 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 'block-storage-stubs'
|
||||
include_examples 'common-logging'
|
||||
|
Reference in New Issue
Block a user