Merge "refactor chefspec tests to be faster and more efficient"
This commit is contained in:
commit
64c77447ec
|
@ -1,5 +0,0 @@
|
|||
# encoding: UTF-8
|
||||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-dashboard::default' do
|
||||
end
|
|
@ -2,23 +2,26 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-dashboard::server' do
|
||||
before { dashboard_stubs }
|
||||
|
||||
describe 'fedora' do
|
||||
before do
|
||||
non_redhat_stubs
|
||||
@chef_run = ::ChefSpec::Runner.new ::FEDORA_OPTS
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
let(:runner) { ChefSpec::Runner.new(FEDORA_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
include_context 'non_redhat_stubs'
|
||||
include_context 'dashboard_stubs'
|
||||
|
||||
it 'deletes openstack-dashboard.conf' do
|
||||
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
|
||||
|
||||
expect(@chef_run).to delete_file file
|
||||
expect(chef_run).to delete_file(file)
|
||||
end
|
||||
|
||||
it 'does not remove the default ubuntu virtualhost' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'execute',
|
||||
'a2dissite 000-default'
|
||||
)
|
||||
|
@ -27,7 +30,7 @@ describe 'openstack-dashboard::server' do
|
|||
end
|
||||
|
||||
it 'removes default virtualhost' do
|
||||
resource = @chef_run.find_resource(
|
||||
resource = chef_run.find_resource(
|
||||
'execute',
|
||||
'a2dissite default'
|
||||
).to_hash
|
||||
|
@ -44,7 +47,7 @@ describe 'openstack-dashboard::server' do
|
|||
it 'executes restore-selinux-context' do
|
||||
cmd = 'restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :'
|
||||
|
||||
expect(@chef_run).not_to run_execute(cmd)
|
||||
expect(chef_run).not_to run_execute(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,59 +2,47 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-dashboard::server' do
|
||||
before { dashboard_stubs }
|
||||
|
||||
describe 'opensuse' do
|
||||
context 'mysql backend' do
|
||||
before do
|
||||
non_redhat_stubs
|
||||
@chef_run = ::ChefSpec::Runner.new ::OPENSUSE_OPTS
|
||||
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
|
||||
'service_type' => 'mysql', 'db_name' => 'flying_dolphin'
|
||||
)
|
||||
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
end
|
||||
let(:runner) { ChefSpec::Runner.new(OPENSUSE_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
include_context 'non_redhat_stubs'
|
||||
include_context 'dashboard_stubs'
|
||||
|
||||
context 'mysql backend' do
|
||||
|
||||
include_context 'mysql_backend'
|
||||
|
||||
it 'installs mysql packages when mysql backend is configured' do
|
||||
@chef_run = ::ChefSpec::Runner.new ::OPENSUSE_OPTS
|
||||
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
|
||||
'service_type' => 'mysql', 'db_name' => 'flying_dolphin'
|
||||
)
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
expect(@chef_run).to upgrade_package 'python-mysql'
|
||||
expect(chef_run).to upgrade_package('python-mysql')
|
||||
end
|
||||
end
|
||||
|
||||
context 'postgresql backend' do
|
||||
before do
|
||||
non_redhat_stubs
|
||||
@chef_run = ::ChefSpec::Runner.new ::OPENSUSE_OPTS
|
||||
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
|
||||
'service_type' => 'postgresql', 'db_name' => 'flying_elephant'
|
||||
)
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
end
|
||||
|
||||
include_context 'postgresql_backend'
|
||||
let(:file) { chef_run.template('/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py') }
|
||||
|
||||
it 'installs packages' do
|
||||
expect(@chef_run).to upgrade_package 'openstack-dashboard'
|
||||
expect(chef_run).to upgrade_package('openstack-dashboard')
|
||||
end
|
||||
|
||||
it 'installs postgresql packages' do
|
||||
expect(@chef_run).to upgrade_package 'python-psycopg2'
|
||||
expect(chef_run).to upgrade_package('python-psycopg2')
|
||||
end
|
||||
|
||||
it 'creates local_settings.py' do
|
||||
file = @chef_run.template '/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py'
|
||||
|
||||
expect(@chef_run).to render_file(file.name).with_content('autogenerated')
|
||||
expect(chef_run).to render_file(file.name).with_content('autogenerated')
|
||||
end
|
||||
|
||||
it 'creates .blackhole dir with proper owner' do
|
||||
dir = '/usr/share/openstack-dashboard/openstack_dashboard/.blackhole'
|
||||
|
||||
expect(@chef_run.directory(dir).owner).to eq('root')
|
||||
expect(chef_run.directory(dir).owner).to eq('root')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,100 +2,96 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-dashboard::server' do
|
||||
before { dashboard_stubs }
|
||||
|
||||
describe 'redhat' do
|
||||
before do
|
||||
redhat_stubs
|
||||
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
let(:runner) { ChefSpec::Runner.new(REDHAT_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
include_context 'dashboard_stubs'
|
||||
include_context 'redhat_stubs'
|
||||
|
||||
it 'executes set-selinux-permissive' do
|
||||
cmd = '/sbin/setenforce Permissive'
|
||||
|
||||
expect(@chef_run).to run_execute(cmd)
|
||||
expect(chef_run).to run_execute(cmd)
|
||||
end
|
||||
|
||||
it 'installs packages' do
|
||||
expect(@chef_run).to upgrade_package 'openstack-dashboard'
|
||||
expect(@chef_run).to upgrade_package 'MySQL-python'
|
||||
expect(chef_run).to upgrade_package('openstack-dashboard')
|
||||
expect(chef_run).to upgrade_package('MySQL-python')
|
||||
end
|
||||
|
||||
it 'installs db2 python packages if explicitly told' do
|
||||
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
|
||||
node = chef_run.node
|
||||
node.set['openstack']['db']['dashboard']['service_type'] = 'db2'
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
%w{db2-odbc python-ibm-db python-ibm-db-django python-ibm-db-sa}.each do |pkg|
|
||||
expect(chef_run).to upgrade_package pkg
|
||||
expect(chef_run).to upgrade_package(pkg)
|
||||
end
|
||||
end
|
||||
|
||||
it 'executes set-selinux-enforcing' do
|
||||
cmd = '/sbin/setenforce Enforcing ; restorecon -R /etc/httpd'
|
||||
|
||||
expect(@chef_run).to run_execute(cmd)
|
||||
expect(chef_run).to run_execute(cmd)
|
||||
end
|
||||
|
||||
describe 'local_settings' do
|
||||
before do
|
||||
@file = @chef_run.template '/etc/openstack-dashboard/local_settings'
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/openstack-dashboard/local_settings') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@file.owner).to eq('root')
|
||||
expect(@file.group).to eq('root')
|
||||
expect(file.owner).to eq('root')
|
||||
expect(file.group).to eq('root')
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @file.mode)).to eq '644'
|
||||
expect(sprintf('%o', file.mode)).to eq('644')
|
||||
end
|
||||
|
||||
it 'rh specific template' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('WEBROOT')
|
||||
expect(chef_run).to render_file(file.name).with_content('WEBROOT')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'certs' do
|
||||
before do
|
||||
@crt = @chef_run.cookbook_file '/etc/pki/tls/certs/horizon.pem'
|
||||
@key = @chef_run.cookbook_file '/etc/pki/tls/private/horizon.key'
|
||||
end
|
||||
let(:crt) { chef_run.cookbook_file('/etc/pki/tls/certs/horizon.pem') }
|
||||
let(:key) { chef_run.cookbook_file('/etc/pki/tls/private/horizon.key') }
|
||||
|
||||
it 'has proper owner' do
|
||||
[@crt, @key].each do |file|
|
||||
[crt, key].each do |file|
|
||||
expect(file.owner).to eq('root')
|
||||
expect(file.group).to eq('root')
|
||||
end
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @crt.mode)).to eq '644'
|
||||
expect(sprintf('%o', @key.mode)).to eq '640'
|
||||
expect(sprintf('%o', crt.mode)).to eq('644')
|
||||
expect(sprintf('%o', key.mode)).to eq('640')
|
||||
end
|
||||
|
||||
it 'notifies restore-selinux-context' do
|
||||
expect(@crt).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(@key).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(crt).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(key).to notify('execute[restore-selinux-context]').to(:run)
|
||||
end
|
||||
end
|
||||
|
||||
it 'deletes openstack-dashboard.conf' do
|
||||
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
|
||||
|
||||
expect(@chef_run).to delete_file file
|
||||
expect(chef_run).to delete_file(file)
|
||||
end
|
||||
|
||||
it 'does not remove openstack-dashboard-ubuntu-theme package' do
|
||||
|
||||
expect(@chef_run).not_to purge_package 'openstack-dashboard-ubuntu-theme'
|
||||
expect(chef_run).not_to purge_package('openstack-dashboard-ubuntu-theme')
|
||||
end
|
||||
|
||||
it 'does not execute restore-selinux-context' do
|
||||
cmd = 'restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :'
|
||||
|
||||
expect(@chef_run).not_to run_execute(cmd)
|
||||
expect(chef_run).not_to run_execute(cmd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,252 +2,220 @@
|
|||
require_relative 'spec_helper'
|
||||
|
||||
describe 'openstack-dashboard::server' do
|
||||
before { dashboard_stubs }
|
||||
|
||||
describe 'ubuntu' do
|
||||
before do
|
||||
non_redhat_stubs
|
||||
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
@chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
let(:runner) { ChefSpec::Runner.new(UBUNTU_OPTS) }
|
||||
let(:node) { runner.node }
|
||||
let(:chef_run) do
|
||||
runner.converge(described_recipe)
|
||||
end
|
||||
|
||||
it 'does nt execute set-selinux-permissive' do
|
||||
cmd = '/sbin/setenforce Permissive'
|
||||
include_context 'non_redhat_stubs'
|
||||
include_context 'dashboard_stubs'
|
||||
|
||||
expect(@chef_run).not_to run_execute(cmd)
|
||||
it 'does not execute set-selinux-permissive' do
|
||||
cmd = '/sbin/setenforce Permissive'
|
||||
expect(chef_run).not_to run_execute(cmd)
|
||||
end
|
||||
|
||||
it 'installs apache packages' do
|
||||
expect(@chef_run).to include_recipe 'apache2'
|
||||
expect(@chef_run).to include_recipe 'apache2::mod_wsgi'
|
||||
expect(@chef_run).to include_recipe 'apache2::mod_rewrite'
|
||||
expect(@chef_run).to include_recipe 'apache2::mod_ssl'
|
||||
expect(chef_run).to include_recipe('apache2')
|
||||
expect(chef_run).to include_recipe('apache2::mod_wsgi')
|
||||
expect(chef_run).to include_recipe('apache2::mod_rewrite')
|
||||
expect(chef_run).to include_recipe('apache2::mod_ssl')
|
||||
end
|
||||
|
||||
it 'does not execute set-selinux-enforcing' do
|
||||
cmd = '/sbin/setenforce Enforcing ; restorecon -R /etc/httpd'
|
||||
|
||||
expect(@chef_run).not_to run_execute(cmd)
|
||||
expect(chef_run).not_to run_execute(cmd)
|
||||
end
|
||||
|
||||
it 'installs packages' do
|
||||
expect(@chef_run).to upgrade_package 'lessc'
|
||||
expect(@chef_run).to upgrade_package 'openstack-dashboard'
|
||||
expect(@chef_run).to upgrade_package 'python-mysqldb'
|
||||
expect(chef_run).to upgrade_package('lessc')
|
||||
expect(chef_run).to upgrade_package('openstack-dashboard')
|
||||
expect(chef_run).to upgrade_package('python-mysqldb')
|
||||
end
|
||||
|
||||
describe 'local_settings.py' do
|
||||
before do
|
||||
@file = @chef_run.template '/etc/openstack-dashboard/local_settings.py'
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/openstack-dashboard/local_settings.py') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@file.owner).to eq('root')
|
||||
expect(@file.group).to eq('root')
|
||||
expect(file.owner).to eq('root')
|
||||
expect(file.group).to eq('root')
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @file.mode)).to eq '644'
|
||||
expect(sprintf('%o', file.mode)).to eq('644')
|
||||
end
|
||||
|
||||
it 'has the customer banner' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('autogenerated')
|
||||
expect(chef_run).to render_file(file.name).with_content('autogenerated')
|
||||
end
|
||||
|
||||
it 'has the memcached servers' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('hostA')
|
||||
expect(chef_run).to render_file(file.name).with_content('hostA')
|
||||
end
|
||||
|
||||
it 'does not configure caching when backend == memcache and no servers provided' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
::Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
.and_return(nil)
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('django.core.cache.backends.memcached.MemcachedCache')
|
||||
expect(chef_run).not_to render_file(file.name)
|
||||
.with_content('django.core.cache.backends.memcached.MemcachedCache')
|
||||
end
|
||||
|
||||
it 'does not configure caching when memcache_servers is empty' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
|
||||
::Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
.and_return([])
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('django.core.cache.backends.memcached.MemcachedCache')
|
||||
expect(chef_run).not_to render_file(file.name)
|
||||
.with_content('django.core.cache.backends.memcached.MemcachedCache')
|
||||
end
|
||||
|
||||
it 'has some plugins enabled' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['plugins'] = ['testPlugin1']
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
expect(chef_run).to render_file(@file.name).with_content('testPlugin1')
|
||||
node.set['openstack']['dashboard']['plugins'] = ['testPlugin1']
|
||||
expect(chef_run).to render_file(file.name).with_content('testPlugin1')
|
||||
end
|
||||
|
||||
it 'notifies apache2 restart' do
|
||||
expect(@file).to notify('service[apache2]').to(:restart)
|
||||
expect(file).to notify('service[apache2]').to(:restart)
|
||||
end
|
||||
|
||||
it 'does not configure ssl proxy when ssl_offload is false' do
|
||||
expect(@chef_run).not_to render_file(@file.name).with_content('SECURE_PROXY_SSL_HEADER')
|
||||
expect(chef_run).not_to render_file(file.name).with_content('SECURE_PROXY_SSL_HEADER')
|
||||
end
|
||||
|
||||
it 'configures ssl proxy when ssl_offload is set to true' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['ssl_offload'] = true
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
expect(chef_run).to render_file(@file.name).with_content('SECURE_PROXY_SSL_HEADER')
|
||||
node.set['openstack']['dashboard']['ssl_offload'] = true
|
||||
expect(chef_run).to render_file(file.name).with_content('SECURE_PROXY_SSL_HEADER')
|
||||
end
|
||||
|
||||
it 'has a help_url' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('docs.openstack.org')
|
||||
expect(chef_run).to render_file(file.name).with_content('docs.openstack.org')
|
||||
end
|
||||
|
||||
it 'configures CSRF_COOKIE_SECURE & SESSION_COOKIE_SECURE when use_ssl is true' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('CSRF_COOKIE_SECURE = True')
|
||||
expect(@chef_run).to render_file(@file.name).with_content('SESSION_COOKIE_SECURE = True')
|
||||
expect(chef_run).to render_file(file.name).with_content('CSRF_COOKIE_SECURE = True')
|
||||
expect(chef_run).to render_file(file.name).with_content('SESSION_COOKIE_SECURE = True')
|
||||
end
|
||||
end
|
||||
|
||||
it 'executes openstack-dashboard syncdb' do
|
||||
cmd = 'python manage.py syncdb --noinput'
|
||||
expect(@chef_run).to run_execute(cmd).with(
|
||||
expect(chef_run).to run_execute(cmd).with(
|
||||
cwd: '/usr/share/openstack-dashboard',
|
||||
environment: {
|
||||
'PYTHONPATH' => '/etc/openstack-dashboard:' \
|
||||
'/usr/share/openstack-dashboard:' \
|
||||
'$PYTHONPATH'
|
||||
}
|
||||
},
|
||||
)
|
||||
end
|
||||
|
||||
describe 'certs' do
|
||||
before do
|
||||
@crt = @chef_run.cookbook_file '/etc/ssl/certs/horizon.pem'
|
||||
@key = @chef_run.cookbook_file '/etc/ssl/private/horizon.key'
|
||||
end
|
||||
let(:crt) { chef_run.cookbook_file('/etc/ssl/certs/horizon.pem') }
|
||||
let(:key) { chef_run.cookbook_file('/etc/ssl/private/horizon.key') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@crt.owner).to eq('root')
|
||||
expect(@crt.group).to eq('root')
|
||||
expect(@key.owner).to eq('root')
|
||||
expect(@key.group).to eq('ssl-cert')
|
||||
expect(crt.owner).to eq('root')
|
||||
expect(crt.group).to eq('root')
|
||||
expect(key.owner).to eq('root')
|
||||
expect(key.group).to eq('ssl-cert')
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @crt.mode)).to eq '644'
|
||||
expect(sprintf('%o', @key.mode)).to eq '640'
|
||||
expect(sprintf('%o', crt.mode)).to eq('644')
|
||||
expect(sprintf('%o', key.mode)).to eq('640')
|
||||
end
|
||||
|
||||
it 'notifies restore-selinux-context' do
|
||||
expect(@crt).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(@key).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(crt).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(key).to notify('execute[restore-selinux-context]').to(:run)
|
||||
end
|
||||
end
|
||||
|
||||
it 'creates .blackhole dir with proper owner' do
|
||||
dir = '/usr/share/openstack-dashboard/openstack_dashboard/.blackhole'
|
||||
|
||||
expect(@chef_run.directory(dir).owner).to eq('root')
|
||||
expect(chef_run.directory(dir).owner).to eq('root')
|
||||
end
|
||||
|
||||
describe 'openstack-dashboard virtual host' do
|
||||
before do
|
||||
f = '/etc/apache2/sites-available/openstack-dashboard'
|
||||
@file = @chef_run.template f
|
||||
end
|
||||
let(:file) { chef_run.template('/etc/apache2/sites-available/openstack-dashboard') }
|
||||
|
||||
it 'has proper owner' do
|
||||
expect(@file.owner).to eq('root')
|
||||
expect(@file.group).to eq('root')
|
||||
expect(file.owner).to eq('root')
|
||||
expect(file.group).to eq('root')
|
||||
end
|
||||
|
||||
it 'has proper modes' do
|
||||
expect(sprintf('%o', @file.mode)).to eq '644'
|
||||
expect(sprintf('%o', file.mode)).to eq('644')
|
||||
end
|
||||
|
||||
it 'has the default banner' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('autogenerated')
|
||||
expect(chef_run).to render_file(file.name).with_content('autogenerated')
|
||||
end
|
||||
|
||||
it 'has the default DocRoot' do
|
||||
expect(@chef_run).to render_file(@file.name).with_content('DocumentRoot /usr/share/openstack-dashboard/openstack_dashboard/.blackhole/')
|
||||
expect(chef_run).to render_file(file.name)
|
||||
.with_content('DocumentRoot /usr/share/openstack-dashboard/openstack_dashboard/.blackhole/')
|
||||
end
|
||||
|
||||
it 'sets the ServerName directive ' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['server_hostname'] = 'spec-test-host'
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
node.set['openstack']['dashboard']['server_hostname'] = 'spec-test-host'
|
||||
|
||||
expect(chef_run).to render_file(@file.name).with_content('spec-test-host')
|
||||
expect(chef_run).to render_file(file.name).with_content('spec-test-host')
|
||||
end
|
||||
|
||||
it 'uses the apache default http port' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['http_port'] = 80
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
node.set['openstack']['dashboard']['http_port'] = 80
|
||||
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('Listen *:80')
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('NameVirtualHost *:80')
|
||||
expect(chef_run).to render_file(@file.name).with_content('<VirtualHost *:80>')
|
||||
expect(chef_run).not_to render_file(file.name).with_content('Listen *:80')
|
||||
expect(chef_run).not_to render_file(file.name).with_content('NameVirtualHost *:80')
|
||||
expect(chef_run).to render_file(file.name).with_content('<VirtualHost *:80>')
|
||||
end
|
||||
|
||||
it 'uses the apache default https port' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['https_port'] = 443
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
node.set['openstack']['dashboard']['https_port'] = 443
|
||||
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('Listen *:443')
|
||||
expect(chef_run).not_to render_file(@file.name).with_content('NameVirtualHost *:443')
|
||||
expect(chef_run).to render_file(@file.name).with_content('<VirtualHost *:443>')
|
||||
expect(chef_run).not_to render_file(file.name).with_content('Listen *:443')
|
||||
expect(chef_run).not_to render_file(file.name).with_content('NameVirtualHost *:443')
|
||||
expect(chef_run).to render_file(file.name).with_content('<VirtualHost *:443>')
|
||||
end
|
||||
|
||||
it 'sets the http port' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['http_port'] = 8080
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
node.set['openstack']['dashboard']['http_port'] = 8080
|
||||
|
||||
expect(chef_run).to render_file(@file.name).with_content('Listen *:8080')
|
||||
expect(chef_run).to render_file(@file.name).with_content('NameVirtualHost *:8080')
|
||||
expect(chef_run).to render_file(@file.name).with_content('<VirtualHost *:8080>')
|
||||
expect(chef_run).to render_file(file.name).with_content('Listen *:8080')
|
||||
expect(chef_run).to render_file(file.name).with_content('NameVirtualHost *:8080')
|
||||
expect(chef_run).to render_file(file.name).with_content('<VirtualHost *:8080>')
|
||||
end
|
||||
|
||||
it 'sets the https port' do
|
||||
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
|
||||
n.set['openstack']['dashboard']['https_port'] = 4430
|
||||
end
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
node.set['openstack']['dashboard']['https_port'] = 4430
|
||||
|
||||
expect(chef_run).to render_file(@file.name).with_content('Listen *:4430')
|
||||
expect(chef_run).to render_file(@file.name).with_content('NameVirtualHost *:4430')
|
||||
expect(chef_run).to render_file(@file.name).with_content('<VirtualHost *:4430>')
|
||||
expect(chef_run).to render_file(file.name).with_content('Listen *:4430')
|
||||
expect(chef_run).to render_file(file.name).with_content('NameVirtualHost *:4430')
|
||||
expect(chef_run).to render_file(file.name).with_content('<VirtualHost *:4430>')
|
||||
end
|
||||
|
||||
it 'notifies restore-selinux-context' do
|
||||
expect(@file).to notify('execute[restore-selinux-context]').to(:run)
|
||||
expect(file).to notify('execute[restore-selinux-context]').to(:run)
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not delete openstack-dashboard.conf' do
|
||||
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
|
||||
|
||||
expect(@chef_run).not_to delete_file file
|
||||
expect(chef_run).not_to delete_file(file)
|
||||
end
|
||||
|
||||
it 'removes openstack-dashboard-ubuntu-theme package' do
|
||||
expect(@chef_run).to purge_package 'openstack-dashboard-ubuntu-theme'
|
||||
expect(chef_run).to purge_package('openstack-dashboard-ubuntu-theme')
|
||||
end
|
||||
|
||||
it 'calls apache_site to disable 000-default virtualhost' do
|
||||
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS)
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
resource = chef_run.find_resource('execute',
|
||||
'a2dissite 000-default').to_hash
|
||||
|
@ -261,8 +229,6 @@ describe 'openstack-dashboard::server' do
|
|||
end
|
||||
|
||||
it 'calls apache_site to enable openstack-dashboard virtualhost' do
|
||||
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS)
|
||||
chef_run.converge 'openstack-dashboard::server'
|
||||
|
||||
resource = chef_run.find_resource('execute',
|
||||
'a2ensite openstack-dashboard').to_hash
|
||||
|
@ -283,19 +249,19 @@ describe 'openstack-dashboard::server' do
|
|||
it 'does not execute restore-selinux-context' do
|
||||
cmd = 'restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :'
|
||||
|
||||
expect(@chef_run).not_to run_execute(cmd)
|
||||
expect(chef_run).not_to run_execute(cmd)
|
||||
end
|
||||
|
||||
it 'has group write mode on path' do
|
||||
path = @chef_run.directory("#{@chef_run.node['openstack']['dashboard']['dash_path']}/local")
|
||||
path = chef_run.directory("#{chef_run.node['openstack']['dashboard']['dash_path']}/local")
|
||||
expect(path.mode).to eq(02770)
|
||||
expect(path.group).to eq(@chef_run.node['apache']['group'])
|
||||
expect(path.group).to eq(chef_run.node['apache']['group'])
|
||||
end
|
||||
|
||||
it 'has group write mode on file' do
|
||||
file = @chef_run.file("#{@chef_run.node['openstack']['dashboard']['dash_path']}/local/.secret_key_store")
|
||||
expect(file.owner).to eq(@chef_run.node['apache']['user'])
|
||||
expect(file.group).to eq(@chef_run.node['apache']['group'])
|
||||
file = chef_run.file("#{chef_run.node['openstack']['dashboard']['dash_path']}/local/.secret_key_store")
|
||||
expect(file.owner).to eq(chef_run.node['apache']['user'])
|
||||
expect(file.group).to eq(chef_run.node['apache']['group'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,42 +2,64 @@
|
|||
require 'chefspec'
|
||||
require 'chefspec/berkshelf'
|
||||
|
||||
::LOG_LEVEL = :fatal
|
||||
::FEDORA_OPTS = {
|
||||
LOG_LEVEL = :fatal
|
||||
FEDORA_OPTS = {
|
||||
platform: 'fedora',
|
||||
version: '18',
|
||||
log_level: ::LOG_LEVEL
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
::REDHAT_OPTS = {
|
||||
REDHAT_OPTS = {
|
||||
platform: 'redhat',
|
||||
version: '6.3',
|
||||
log_level: ::LOG_LEVEL
|
||||
version: '6.5',
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
::UBUNTU_OPTS = {
|
||||
UBUNTU_OPTS = {
|
||||
platform: 'ubuntu',
|
||||
version: '12.04',
|
||||
log_level: ::LOG_LEVEL
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
::OPENSUSE_OPTS = {
|
||||
OPENSUSE_OPTS = {
|
||||
platform: 'opensuse',
|
||||
version: '12.3',
|
||||
log_level: ::LOG_LEVEL
|
||||
log_level: LOG_LEVEL
|
||||
}
|
||||
|
||||
def dashboard_stubs
|
||||
::Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
shared_context 'dashboard_stubs' do
|
||||
before do
|
||||
Chef::Recipe.any_instance.stub(:memcached_servers)
|
||||
.and_return ['hostA:port', 'hostB:port']
|
||||
::Chef::Recipe.any_instance.stub(:get_password)
|
||||
Chef::Recipe.any_instance.stub(:get_password)
|
||||
.with('db', 'horizon')
|
||||
.and_return 'test-passes'
|
||||
.and_return('test-passes')
|
||||
end
|
||||
end
|
||||
|
||||
def redhat_stubs
|
||||
stub_command("[ ! -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*enforcing') -eq 1 ]").and_return(true)
|
||||
stub_command("[ -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*permissive') -eq 1 ] && [ $(/sbin/sestatus | grep -c '^Mode from config file:.*enforcing') -eq 1 ]").and_return(true)
|
||||
shared_context 'redhat_stubs' do
|
||||
before do
|
||||
stub_command("[ ! -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*enforcing') -eq 1 ]").and_return(true)
|
||||
stub_command("[ -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*permissive') -eq 1 ] && [ $(/sbin/sestatus | grep -c '^Mode from config file:.*enforcing') -eq 1 ]").and_return(true)
|
||||
end
|
||||
end
|
||||
|
||||
def non_redhat_stubs
|
||||
stub_command("[ ! -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*enforcing') -eq 1 ]").and_return(false)
|
||||
stub_command("[ -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*permissive') -eq 1 ] && [ $(/sbin/sestatus | grep -c '^Mode from config file:.*enforcing') -eq 1 ]").and_return(false)
|
||||
shared_context 'non_redhat_stubs' do
|
||||
before do
|
||||
stub_command("[ ! -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*enforcing') -eq 1 ]").and_return(false)
|
||||
stub_command("[ -e /etc/httpd/conf/httpd.conf ] && [ -e /etc/redhat-release ] && [ $(/sbin/sestatus | grep -c '^Current mode:.*permissive') -eq 1 ] && [ $(/sbin/sestatus | grep -c '^Mode from config file:.*enforcing') -eq 1 ]").and_return(false)
|
||||
end
|
||||
end
|
||||
|
||||
shared_context 'postgresql_backend' do
|
||||
before do
|
||||
Chef::Recipe.any_instance.stub(:db)
|
||||
.with('dashboard')
|
||||
.and_return('service_type' => 'postgresql', 'db_name' => 'flying_elephant')
|
||||
end
|
||||
end
|
||||
|
||||
shared_context 'mysql_backend' do
|
||||
before do
|
||||
Chef::Recipe.any_instance.stub(:db)
|
||||
.with('dashboard')
|
||||
.and_return('service_type' => 'mysql', 'db_name' => 'flying_dolphin')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue