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. Some additional fixes include: - Add default['openstack']['common']['search_count_max'] attribute to allow speed ups during testing. - Improved a few tests - Adjusted some formatting - Remove deprecated ChefSpec::Coverage.start function - Show warnings - Use major version for redhat platform - Update to Ubuntu 18.04 Speed was improved from 4 minutes 16 seconds to 41.98 seconds. Change-Id: Icb9147036a01f92ec48a24c692dd022258e294c0
This commit is contained in:
parent
d5e2d175cd
commit
4000e8aa96
|
@ -321,6 +321,10 @@ end
|
|||
# The location of the OSC bash completion file
|
||||
default['openstack']['common']['bash_complete'] = '/etc/bash_completion.d/osc.bash_completion'
|
||||
|
||||
# Set maximum count for searches [1]
|
||||
# [1] https://review.opendev.org/60126
|
||||
default['openstack']['common']['search_count_max'] = 7
|
||||
|
||||
# The name of the Chef role that installs the Keystone Service API
|
||||
default['openstack']['identity_service_chef_role'] = 'os-identity'
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ module ::Openstack
|
|||
recipe_query = "(chef_environment:#{node.chef_environment} AND recipes:#{r})".sub('::', '\:\:')
|
||||
query = "#{role_query} OR #{recipe_query}"
|
||||
count = 1
|
||||
sum = 7
|
||||
sum = node['openstack']['common']['search_count_max']
|
||||
while count < sum
|
||||
resp = search(:node, query, &block)
|
||||
break unless resp.nil?
|
||||
|
|
|
@ -6,7 +6,7 @@ describe 'openstack-common::default' do
|
|||
describe 'Openstack CLI' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-common::client' do
|
||||
describe 'redhat' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'converges successfully' do
|
||||
expect { chef_run }.to_not raise_error
|
||||
end
|
||||
|
||||
it do
|
||||
expect(chef_run).to upgrade_package('python-openstackclient')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,10 +5,14 @@ describe 'openstack-common::client' do
|
|||
describe 'ubuntu' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'converges successfully' do
|
||||
expect { chef_run }.to_not raise_error
|
||||
end
|
||||
|
||||
it do
|
||||
expect(chef_run).to upgrade_package('python3-openstackclient')
|
||||
end
|
||||
|
|
|
@ -5,8 +5,18 @@ describe 'openstack-common::completions' do
|
|||
describe 'ubuntu' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'converges successfully' do
|
||||
expect { chef_run }.to_not raise_error
|
||||
end
|
||||
it do
|
||||
expect(chef_run).to run_execute('create OSC bash completions')
|
||||
.with(
|
||||
command: 'openstack complete > /etc/bash_completion.d/osc.bash_completion',
|
||||
creates: '/etc/bash_completion.d/osc.bash_completion'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ describe 'openstack-common::default' do
|
|||
describe 'module Openstack config_helpers' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
|
|
@ -4,13 +4,10 @@ require_relative 'spec_helper'
|
|||
|
||||
describe 'test-openstack-common-database::default' do
|
||||
let(:runner) do
|
||||
ChefSpec::SoloRunner.new(platform: 'ubuntu',
|
||||
version: '16.04',
|
||||
log_level: :fatal,
|
||||
step_into: ['openstack_common_database'])
|
||||
ChefSpec::SoloRunner.new(CHEFSPEC_OPTS.dup.merge(step_into: ['openstack_common_database']))
|
||||
end
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['use_databags'] = false
|
||||
node.override['openstack']['secret']['mysqlroot']['db'] = 'root_pass'
|
||||
node.override['openstack']['db']['service'] = { service_type: 'mysql', port: 3306, db_name: 'service_db' }
|
||||
|
@ -23,8 +20,12 @@ describe 'test-openstack-common-database::default' do
|
|||
end
|
||||
|
||||
context 'specific root user db endpoint' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['endpoints']['db']['host_for_db_root_user'] = 'localhost123'
|
||||
node.override['openstack']['use_databags'] = false
|
||||
node.override['openstack']['secret']['mysqlroot']['db'] = 'root_pass'
|
||||
node.override['openstack']['db']['service'] = { service_type: 'mysql', port: 3306, db_name: 'service_db' }
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'connects to the database via a specific endpoint for the root user' do
|
||||
expect(chef_run).to create_database('create database service_db')
|
||||
|
|
|
@ -5,12 +5,15 @@ describe 'openstack-common::default' do
|
|||
describe 'rhel-rdo' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(REDHAT_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'converges successfully' do
|
||||
expect { chef_run }.to_not raise_error
|
||||
end
|
||||
|
||||
it do
|
||||
expect(chef_run).to upgrade_package('centos-release-qemu-ev')
|
||||
end
|
||||
|
@ -22,9 +25,11 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'enabling RDO with gpgcheck enabled' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
node.override['openstack']['yum']['rdo_enabled'] = true
|
||||
node.override['openstack']['yum']['gpgcheck'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'adds RDO yum repository' do
|
||||
|
@ -40,9 +45,11 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'enabling RDO with gpgcheck disabled' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
node.override['openstack']['yum']['rdo_enabled'] = true
|
||||
node.override['openstack']['yum']['gpgcheck'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'adds RDO yum repository' do
|
||||
|
@ -56,8 +63,10 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'disabling RDO deps repo with is_release true' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
node.override['openstack']['is_release'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'does not add the RDO deps yum repository' do
|
||||
|
@ -66,8 +75,10 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'disabling RDO' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
node.override['openstack']['yum']['rdo_enabled'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'removes RDO yum repository' do
|
||||
|
@ -77,12 +88,6 @@ describe 'openstack-common::default' do
|
|||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to remove_yum_repository('RDO-testrelease')
|
||||
end
|
||||
|
||||
it 'does nothing when RDO yum repository does not exist' do
|
||||
repo = chef_run.find_resource('yum_repository', 'RDO-testrelease')
|
||||
expect(repo.performed_actions).to be_empty
|
||||
end
|
||||
|
||||
it 'does include yum-epel recipe' do
|
||||
expect(chef_run).to include_recipe('yum-epel')
|
||||
end
|
||||
|
@ -91,5 +96,17 @@ describe 'openstack-common::default' do
|
|||
expect(chef_run).to_not create_remote_file('/etc/yum.repos.d/rdo-manager-release.repo')
|
||||
end
|
||||
end
|
||||
|
||||
context 'disabling RDO and repo file does not exist' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['release'] = 'testrelease'
|
||||
node.override['openstack']['yum']['rdo_enabled'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'does nothing when RDO yum repository does not exist' do
|
||||
allow(FileTest).to receive(:exist?).with('/etc/yum.repos.d/RDO-testrelease.repo').and_return(false)
|
||||
expect(chef_run).to nothing_yum_repository('RDO-testrelease')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,60 +6,94 @@ describe 'openstack-common::default' do
|
|||
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
|
||||
let(:mq_services) { %w(bare_metal block_storage compute database image telemetry network orchestration) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'converges successfully' do
|
||||
expect { chef_run }.to_not raise_error
|
||||
end
|
||||
|
||||
it 'does not include apt for apt-get update' do
|
||||
expect(chef_run).to_not include_recipe 'apt'
|
||||
end
|
||||
|
||||
it 'updates apt cache before installing packages' do
|
||||
node.override['openstack']['apt']['update_apt_cache'] = true
|
||||
expect(chef_run).to update_apt_update 'default'
|
||||
context 'update_apt_cache true' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['apt']['update_apt_cache'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'updates apt cache before installing packages' do
|
||||
expect(chef_run).to update_apt_update 'default'
|
||||
end
|
||||
end
|
||||
|
||||
it do
|
||||
expect(chef_run).to create_file('/etc/apt/apt.conf.d/confdef')
|
||||
.with(
|
||||
owner: 'root',
|
||||
group: 'root',
|
||||
mode: 00644,
|
||||
content: "Dpkg::Options {\n \"--force-confdef\";\n \"--force-confold\";\n }"
|
||||
)
|
||||
end
|
||||
|
||||
it 'upgrades ubuntu-cloud-keyring package' do
|
||||
expect(chef_run).to upgrade_package 'ubuntu-cloud-keyring'
|
||||
end
|
||||
|
||||
it 'configures openstack repository' do
|
||||
# Using cookbook(apt) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
node.override['openstack']['apt']['live_updates_enabled'] = true
|
||||
expect(chef_run).to add_apt_repository('openstack-ppa').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'xenial-updates/rocky',
|
||||
components: ['main'],
|
||||
cache_rebuild: true
|
||||
)
|
||||
context 'live_updates_enabled true' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['apt']['live_updates_enabled'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'configures openstack repository' do
|
||||
# Using cookbook(apt) LWRP custom matcher
|
||||
# https://github.com/sethvargo/chefspec#packaging-custom-matchers
|
||||
expect(chef_run).to add_apt_repository('openstack-ppa').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'bionic-updates/rocky',
|
||||
components: ['main'],
|
||||
cache_rebuild: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it 'disables openstack live updates' do
|
||||
node.override['openstack']['apt']['live_updates_enabled'] = false
|
||||
expect(chef_run).to_not add_apt_repository('openstack-ppa').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'xenial-updates/rocky',
|
||||
components: ['main']
|
||||
)
|
||||
context 'live_updates_enabled false' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['apt']['live_updates_enabled'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'disables openstack live updates' do
|
||||
expect(chef_run).to_not add_apt_repository('openstack-ppa').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'bionic-updates/rocky',
|
||||
components: ['main']
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
it 'configures openstack proposed repository' do
|
||||
expect(chef_run).to add_apt_repository('openstack-ppa-proposed').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'xenial-proposed/rocky',
|
||||
distribution: 'bionic-proposed/rocky',
|
||||
components: ['main'],
|
||||
cache_rebuild: true
|
||||
)
|
||||
end
|
||||
|
||||
it 'disables openstack proposed repository' do
|
||||
node.override['openstack']['is_release'] = true
|
||||
expect(chef_run).to_not add_apt_repository('openstack-ppa-proposed').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'xenial-proposed/rocky',
|
||||
components: ['main']
|
||||
)
|
||||
context 'is_release true' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['is_release'] = true
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'disables openstack proposed repository' do
|
||||
expect(chef_run).to_not add_apt_repository('openstack-ppa-proposed').with(
|
||||
uri: 'http://ubuntu-cloud.archive.canonical.com/ubuntu',
|
||||
distribution: 'bionic-proposed/rocky',
|
||||
components: ['main']
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
pkgs = %w(python3 python3-dev python3-pip python3-setuptools python3-virtualenv python3-wheel virtualenv)
|
||||
|
@ -72,10 +106,14 @@ describe 'openstack-common::default' do
|
|||
expect(chef_run).to_not install_chef_gem('chef-vault')
|
||||
end
|
||||
|
||||
it 'installs the gem chef-vault if databag_type is vault' do
|
||||
node.override['openstack']['databag_type'] = 'vault'
|
||||
expect(chef_run).to install_chef_gem('chef-vault')
|
||||
.with(version: '~> 3.2')
|
||||
context 'databag_type vault' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['databag_type'] = 'vault'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'installs the gem chef-vault if databag_type is vault' do
|
||||
expect(chef_run).to install_chef_gem('chef-vault').with(version: '~> 3.2')
|
||||
end
|
||||
end
|
||||
|
||||
context 'rabbit mq' do
|
||||
|
@ -94,6 +132,12 @@ describe 'openstack-common::default' do
|
|||
'kombu_reconnect_delay' => 123.456,
|
||||
'kombu_reconnect_timeout' => 123,
|
||||
}
|
||||
cached(:chef_run) do
|
||||
rabbit_opts.each do |key, value|
|
||||
node.override['openstack']['mq']['rabbitmq'][key] = value
|
||||
end
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
rabbit_opts.each do |key, value|
|
||||
it "configures rabbit mq #{key}" do
|
||||
node.override['openstack']['mq']['rabbitmq'][key] = value
|
||||
|
|
|
@ -7,7 +7,9 @@ describe 'openstack-common::default' do
|
|||
describe 'Openstack endpoints' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
cached(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
%w(public internal).each do |ep_type|
|
||||
|
@ -109,19 +111,24 @@ describe 'openstack-common::default' do
|
|||
expect(subject.rabbit_transport_url('compute')).to eq(expected)
|
||||
end
|
||||
|
||||
it do
|
||||
node.override['openstack']['mq']['service_type'] = 'rabbit'
|
||||
node.override['openstack']['mq']['cluster'] = true
|
||||
node.override['openstack']['mq']['compute']['rabbit']['userid'] = 'rabbit2'
|
||||
node.override['openstack']['endpoints']['mq']['port'] = 1234
|
||||
node.override['openstack']['mq']['servers'] = %w(10.0.0.1 10.0.0.2 10.0.0.3)
|
||||
node.override['openstack']['mq']['vhost'] = '/anyhost'
|
||||
allow(subject).to receive(:node).and_return(chef_run.node)
|
||||
allow(subject).to receive(:get_password)
|
||||
.with('user', 'rabbit2')
|
||||
.and_return('mypass2')
|
||||
expected = 'rabbit://rabbit2:mypass2@10.0.0.1:1234,rabbit2:mypass2@10.0.0.2:1234,rabbit2:mypass2@10.0.0.3:1234/anyhost'
|
||||
expect(subject.rabbit_transport_url('compute')).to eq(expected)
|
||||
context 'non-default mq attributes' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['mq']['service_type'] = 'rabbit'
|
||||
node.override['openstack']['mq']['cluster'] = true
|
||||
node.override['openstack']['mq']['compute']['rabbit']['userid'] = 'rabbit2'
|
||||
node.override['openstack']['endpoints']['mq']['port'] = 1234
|
||||
node.override['openstack']['mq']['servers'] = %w(10.0.0.1 10.0.0.2 10.0.0.3)
|
||||
node.override['openstack']['mq']['vhost'] = '/anyhost'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it do
|
||||
allow(subject).to receive(:node).and_return(chef_run.node)
|
||||
allow(subject).to receive(:get_password)
|
||||
.with('user', 'rabbit2')
|
||||
.and_return('mypass2')
|
||||
expected = 'rabbit://rabbit2:mypass2@10.0.0.1:1234,rabbit2:mypass2@10.0.0.2:1234,rabbit2:mypass2@10.0.0.3:1234/anyhost'
|
||||
expect(subject.rabbit_transport_url('compute')).to eq(expected)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -164,15 +171,20 @@ describe 'openstack-common::default' do
|
|||
).to eq(expected)
|
||||
end
|
||||
|
||||
it 'returns network db info hash when service found for sqlite with options' do
|
||||
node.override['openstack']['db']['service_type'] = 'sqlite'
|
||||
node.override['openstack']['db']['options'] = { 'sqlite' => '?options' }
|
||||
node.override['openstack']['db']['network']['path'] = 'path'
|
||||
allow(subject).to receive(:node).and_return(chef_run.node)
|
||||
expected = 'sqlite:///path?options'
|
||||
expect(
|
||||
subject.db_uri('network', 'user', 'pass')
|
||||
).to eq(expected)
|
||||
context 'sqlite' do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['db']['service_type'] = 'sqlite'
|
||||
node.override['openstack']['db']['options'] = { 'sqlite' => '?options' }
|
||||
node.override['openstack']['db']['network']['path'] = 'path'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'returns network db info hash when service found for sqlite with options' do
|
||||
allow(subject).to receive(:node).and_return(chef_run.node)
|
||||
expected = 'sqlite:///path?options'
|
||||
expect(
|
||||
subject.db_uri('network', 'user', 'pass')
|
||||
).to eq(expected)
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns compute db info hash when service found for mariadb' do
|
||||
|
|
|
@ -5,7 +5,7 @@ describe 'openstack-common::logging' 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) }
|
||||
|
||||
describe '/etc/openstack' do
|
||||
let(:dir) { chef_run.directory('/etc/openstack') }
|
||||
|
|
|
@ -4,17 +4,48 @@ require ::File.join ::File.dirname(__FILE__), '..', 'libraries', 'network'
|
|||
|
||||
describe 'openstack-common::default' do
|
||||
describe 'Openstack address_for and bind_address' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
node.automatic['network']['interfaces'] = {
|
||||
'lo' => { 'addresses' => { '127.0.0.1' => { 'family' => 'inet', 'prefixlen' => '8', 'netmask' => '255.0.0.0', 'scope' => 'Node' },
|
||||
'::1' => { 'family' => 'inet6', 'prefixlen' => '128', 'scope' => 'Node' },
|
||||
'2001:db8::1' => { 'family' => 'inet6', 'prefixlen' => '64', 'scope' => 'Node' } } },
|
||||
'eth0' => { 'addresses' => { '10.0.0.2' => { 'family' => 'inet', 'prefixlen' => '32', 'netmask' => '255.255.255.255', 'scope' => 'Node' },
|
||||
'10.0.0.3' => { 'family' => 'inet', 'prefixlen' => '24', 'netmask' => '255.255.255.0', 'scope' => 'Node' } } },
|
||||
}
|
||||
|
||||
interfaces = {
|
||||
'lo' => {
|
||||
'addresses' => {
|
||||
'127.0.0.1' => {
|
||||
'family' => 'inet',
|
||||
'prefixlen' => '8',
|
||||
'netmask' => '255.0.0.0',
|
||||
'scope' => 'Node',
|
||||
},
|
||||
'::1' => {
|
||||
'family' => 'inet6',
|
||||
'prefixlen' => '128',
|
||||
'scope' => 'Node',
|
||||
},
|
||||
'2001:db8::1' => {
|
||||
'family' => 'inet6',
|
||||
'prefixlen' => '64',
|
||||
'scope' => 'Node',
|
||||
},
|
||||
},
|
||||
},
|
||||
'eth0' => {
|
||||
'addresses' => {
|
||||
'10.0.0.2' => {
|
||||
'family' => 'inet',
|
||||
'prefixlen' => '32',
|
||||
'netmask' => '255.255.255.255',
|
||||
'scope' => 'Node',
|
||||
},
|
||||
'10.0.0.3' => {
|
||||
'family' => 'inet',
|
||||
'prefixlen' => '24',
|
||||
'netmask' => '255.255.255.0',
|
||||
'scope' => 'Node',
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
cached(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
cached(:node) { runner.node }
|
||||
cached(:chef_run) do
|
||||
node.automatic['network']['interfaces'] = interfaces
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
|
@ -48,9 +79,14 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#address_for ipv6' do
|
||||
it 'returns ipv6 address' do
|
||||
context '#address_for ipv6' do
|
||||
cached(:chef_run) do
|
||||
node.automatic['network']['interfaces'] = interfaces
|
||||
node.override['openstack']['endpoints']['family'] = 'inet6'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'returns ipv6 address' do
|
||||
expect(
|
||||
subject.address_for('lo')
|
||||
).to eq('2001:db8::1')
|
||||
|
@ -81,9 +117,12 @@ describe 'openstack-common::default' do
|
|||
subject.bind_address(node['openstack']['bind_service']['mq'])
|
||||
).to eq('127.0.0.1')
|
||||
end
|
||||
describe 'mq interface set' do
|
||||
before do
|
||||
context 'mq interface set' do
|
||||
cached(:chef_run) do
|
||||
node.automatic['network']['interfaces'] = interfaces
|
||||
node.override['openstack']['endpoints']['family'] = 'inet'
|
||||
node.override['openstack']['bind_service']['mq']['interface'] = 'eth0'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'returns the interface address' do
|
||||
expect(
|
||||
|
@ -98,9 +137,12 @@ describe 'openstack-common::default' do
|
|||
subject.bind_address(node['openstack']['bind_service']['db'])
|
||||
).to eq('127.0.0.1')
|
||||
end
|
||||
describe 'interface set' do
|
||||
before do
|
||||
context 'interface set' do
|
||||
cached(:chef_run) do
|
||||
node.automatic['network']['interfaces'] = interfaces
|
||||
node.override['openstack']['endpoints']['family'] = 'inet'
|
||||
node.override['openstack']['bind_service']['db']['interface'] = 'eth0'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'returns the interface address' do
|
||||
expect(
|
||||
|
|
|
@ -7,7 +7,7 @@ describe 'openstack-common::default' do
|
|||
describe 'Passwords' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
cached(:chef_run) { runner.converge(described_recipe) }
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
include_context 'library-stubs'
|
||||
|
@ -25,8 +25,9 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'using chef-vault' do
|
||||
before do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['databag_type'] = 'vault'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
it 'returns the data from a chef vault item' do
|
||||
allow(ChefVault::Item).to receive(:load)
|
||||
|
@ -66,7 +67,10 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'stored in standard data bags' do
|
||||
before { node.override['openstack']['databag_type'] = 'standard' }
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['databag_type'] = 'standard'
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
describe '#secret' do
|
||||
it 'returns databag' do
|
||||
value = { 'nova' => 'this' }
|
||||
|
@ -101,7 +105,10 @@ describe 'openstack-common::default' do
|
|||
end
|
||||
|
||||
context 'stored in attributes as an alternative' do
|
||||
before { node.override['openstack']['use_databags'] = false }
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['use_databags'] = false
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
describe '#get_password' do
|
||||
%w(service db user token).each do |type|
|
||||
|
|
|
@ -6,13 +6,14 @@ describe 'openstack-common::default' do
|
|||
describe 'Openstack Search' do
|
||||
let(:runner) { ChefSpec::SoloRunner.new(CHEFSPEC_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['mq']['server_role'] = 'openstack-ops-mq'
|
||||
node.override['openstack']['endpoints']['mq']['port'] = 5672
|
||||
|
||||
# speed up tests
|
||||
node.override['openstack']['common']['search_count_max'] = 2
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
let(:subject) { Object.new.extend(Openstack) }
|
||||
cached(:subject) { Object.new.extend(Openstack) }
|
||||
|
||||
describe '#search_for' do
|
||||
it 'returns results' do
|
||||
|
|
|
@ -2,22 +2,22 @@
|
|||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
|
||||
ChefSpec::Coverage.start! { add_filter 'openstack-common' }
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.color = true
|
||||
config.formatter = :documentation
|
||||
config.log_level = :fatal
|
||||
config.log_level = :warn
|
||||
end
|
||||
|
||||
UBUNTU_OPTS = {
|
||||
platform: 'ubuntu',
|
||||
version: '16.04',
|
||||
version: '18.04',
|
||||
}.freeze
|
||||
|
||||
REDHAT_OPTS = {
|
||||
platform: 'redhat',
|
||||
version: '7.4',
|
||||
version: '7',
|
||||
}.freeze
|
||||
|
||||
# We set a default platform for non-platform specific test cases
|
||||
CHEFSPEC_OPTS = UBUNTU_OPTS
|
||||
|
||||
|
|
|
@ -3,9 +3,16 @@ require_relative 'spec_helper'
|
|||
|
||||
describe 'openstack-common::sysctl' do
|
||||
describe 'ubuntu' do
|
||||
sysctl_kv = {
|
||||
'systcl_key1' => 'sysctl_value1',
|
||||
'sysctl_key2' => 'sysctl_value2',
|
||||
}
|
||||
let(:runner) { ChefSpec::SoloRunner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) { runner.converge(described_recipe) }
|
||||
cached(:chef_run) do
|
||||
node.override['openstack']['sysctl'] = sysctl_kv
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
describe 'sysctl.d directory' do
|
||||
it 'should create /etc/systctl.d' do
|
||||
|
@ -25,9 +32,6 @@ describe 'openstack-common::sysctl' do
|
|||
end
|
||||
|
||||
it 'sets the sysctl attributes' do
|
||||
sysctl_kv = { 'systcl_key1' => 'sysctl_value1',
|
||||
'sysctl_key2' => 'sysctl_value2' }
|
||||
node.override['openstack']['sysctl'] = sysctl_kv
|
||||
sysctl_kv.each do |k, v|
|
||||
expect(chef_run).to render_file(file.name).with_content(/^#{k} = #{v}$/)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue