Files
cookbook-openstack-compute/spec/spec_helper.rb
Lance Albertson 82c5b9a243 Properly notify apache restarts on configuration updates
This uses edit_resource to add a notification in the nova-api,
nova-api-metadata and nova-placement-api apache configurations when one
of them gets updated. This is a workaround due to the fact we are using
a version of the apache2 cookbook that is still using definitions and
cannot add notifications with definitions.

This is intended to ensure we only restart apache when the configuration
is updated. Otherwise, the old behaviour was to restart apache on every
run which is problematic in production environments. I have been using
this in our production wrapper cookbook for the past year or so without
any issue.

This will be removed in the Stein release when we migrate to the newer
apache2 cookbook which uses proper resources.

Also amend the Berksfile to point to the new opendev.org location.

Change-Id: I55e6ea4124017e0f44f92f6a2fb01baad5a27555
Signed-off-by: Lance Albertson <lance@osuosl.org>
2019-08-20 12:47:08 +00:00

170 lines
6.0 KiB
Ruby

# encoding: UTF-8
require 'chefspec'
require 'chefspec/berkshelf'
ChefSpec::Coverage.start! { add_filter 'openstack-compute' }
require 'chef/application'
require 'securerandom'
RSpec.configure do |config|
config.color = true
config.formatter = :documentation
config.log_level = :fatal
config.file_cache_path = '/var/chef/cache'
end
REDHAT_OPTS = {
platform: 'redhat',
version: '7.4',
}.freeze
UBUNTU_OPTS = {
platform: 'ubuntu',
version: '16.04',
}.freeze
shared_context 'compute_stubs' do
before do
allow_any_instance_of(Chef::Recipe).to receive(:rabbit_servers)
.and_return '1.1.1.1:5672,2.2.2.2:5672'
allow_any_instance_of(Chef::Recipe).to receive(:address_for)
.with('lo')
.and_return '127.0.1.1'
allow_any_instance_of(Chef::Recipe).to receive(:search_for)
.with('os-identity').and_return(
[{
'openstack' => {
'identity' => {
'admin_tenant_name' => 'admin',
'admin_user' => 'admin',
},
},
}]
)
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('token', 'openstack_identity_bootstrap_token')
.and_return('bootstrap-token')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('token', 'neutron_metadata_secret')
.and_return('metadata-secret')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('token', 'openstack_vmware_secret_name')
.and_return 'vmware_secret_name'
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('db', 'nova')
.and_return('nova_db_pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('db', 'nova_api')
.and_return('nova_api_db_pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('db', 'nova_cell0')
.and_return('nova_cell0_db_pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('user', 'guest')
.and_return('mq-pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('user', 'admin')
.and_return('admin')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('service', 'openstack-compute')
.and_return('nova-pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('service', 'openstack-network')
.and_return('neutron-pass')
allow_any_instance_of(Chef::Recipe).to receive(:get_password)
.with('service', 'openstack-placement')
.and_return('placement-pass')
allow_any_instance_of(Chef::Recipe).to receive(:rabbit_transport_url)
.with('compute')
.and_return('rabbit://guest:mypass@127.0.0.1:5672')
allow_any_instance_of(Chef::Recipe).to receive(:memcached_servers).and_return []
allow(Chef::Application).to receive(:fatal!)
allow(SecureRandom).to receive(:hex).and_return('ad3313264ea51d8c6a3d1c5b140b9883')
# stub_command('nova-manage network list | grep 192.168.100.0/24').and_return(false)
# stub_command('nova-manage network list | grep 192.168.200.0/24').and_return(false)
# stub_command("nova-manage floating list |grep -E '.*([0-9]{1,3}[.]){3}[0-9]{1,3}*'").and_return(false)
stub_command('/usr/sbin/apache2 -t').and_return(true)
stub_command('/usr/sbin/httpd -t').and_return(true)
stub_command('virsh net-list | grep -q default').and_return(true)
stub_command('ovs-vsctl br-exists br-int').and_return(true)
stub_command('ovs-vsctl br-exists br-tun').and_return(true)
stub_command('nova-manage api_db sync').and_return(true)
stub_command('nova-manage cell_v2 map_cell0 --database_connection mysql+pymysql://nova_cell0:mypass@127.0.0.1/nova_cell0?charset=utf8').and_return(true)
stub_command('nova-manage cell_v2 create_cell --verbose --name cell1').and_return(true)
stub_command('nova-manage cell_v2 list_cells | grep -q cell0').and_return(false)
stub_command('nova-manage cell_v2 list_cells | grep -q cell1').and_return(false)
stub_command('nova-manage cell_v2 discover_hosts').and_return(true)
stub_command("[ ! -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*enforcing') -eq 1 ]").and_return(true)
end
end
shared_examples 'expect_volume_packages' do
it 'upgrades volume utils packages' do
%w(sysfsutils sg3_utils device-mapper-multipath).each do |pkg|
expect(chef_run).to upgrade_package(pkg)
end
end
end
shared_examples 'expect_runs_nova_common_recipe' do
it 'includes nova-common' do
expect(chef_run).to include_recipe 'openstack-compute::nova-common'
end
end
shared_examples 'expect_runs_nova_cell_recipe' do
it 'includes _nova_cell' do
expect(chef_run).to include_recipe 'openstack-compute::_nova_cell'
end
end
shared_examples 'expect_creates_nova_state_dir' do
it 'creates the /var/lib/nova/lock directory' do
expect(chef_run).to create_directory('/var/lib/nova').with(
user: 'nova',
group: 'nova',
mode: 0o755
)
end
end
shared_examples 'expect_creates_nova_lock_dir' do
it 'creates the /var/lib/nova/lock directory' do
expect(chef_run).to create_directory('/var/lib/nova/lock').with(
user: 'nova',
group: 'nova',
mode: 0o755
)
end
end
shared_examples 'expect_creates_nova_instances_dir' do
it 'creates the /var/lib/nova/instances directory' do
expect(chef_run).to create_directory('/var/lib/nova/instances').with(
user: 'nova',
group: 'nova',
mode: 0o755
)
end
end
shared_examples 'expect_creates_api_paste_template' do
let(:file) { chef_run.template('/etc/nova/api-paste.ini') }
it 'creates api-paste.ini' do
expect(chef_run).to create_template('/etc/nova/api-paste.ini').with(
user: 'nova',
group: 'nova',
mode: 0o644
)
end
context 'template contents' do
it 'pastes the misc attributes' do
node.override['openstack']['compute']['misc_paste'] = %w(paste1 paste2)
expect(chef_run).to render_file(file.name)
.with_content(/^paste1$/).with_content(/^paste2$/)
end
end
end