Update specs to be rubocop compliant

- Add rubocop.yml in spec/
- Add spec rubocop test to Strainerfile
- Update specs to comply with rubocop

Change-Id: If38186e6ea9104ef658184812e328368f8b86cea
Addresses: blueprint rubocop-for-dashboard
This commit is contained in:
Christopher H. Laco 2014-01-15 14:26:54 -06:00
parent 2697810589
commit dd1aad5628
9 changed files with 264 additions and 242 deletions

View File

@ -2,6 +2,7 @@
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/Gemfile $SANDBOX/$COOKBOOK/metadata.rb --config $SANDBOX/$COOKBOOK/.rubocop.yml
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/attributes/ --config $SANDBOX/$COOKBOOK/attributes/.rubocop.yml
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/recipes/ --config $SANDBOX/$COOKBOOK/recipes/.rubocop.yml
rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK/spec/ --config $SANDBOX/$COOKBOOK/spec/.rubocop.yml
# rubocop: bundle exec rubocop $SANDBOX/$COOKBOOK
knife test: bundle exec knife cookbook test $COOKBOOK
foodcritic: bundle exec foodcritic -f any -t ~FC003 -t ~FC023 $SANDBOX/$COOKBOOK

View File

@ -134,7 +134,7 @@ cookbook_file "#{node["openstack"]["dashboard"]["ssl"]["dir"]}/private/#{node["o
end
directory "#{node['openstack']['dashboard']['dash_path']}/local" do
owner "root"
owner 'root'
group node['apache']['group']
mode 02770
action :create
@ -163,8 +163,8 @@ template node['openstack']['dashboard']['apache']['sites-path'] do
ssl_key_file: "#{node["openstack"]["dashboard"]["ssl"]["dir"]}/private/#{node["openstack"]["dashboard"]["ssl"]["key"]}"
)
notifies :run, "execute[restore-selinux-context]", :immediately
notifies :reload, "service[apache2]", :immediately
notifies :run, 'execute[restore-selinux-context]', :immediately
notifies :reload, 'service[apache2]', :immediately
end
file "#{node["apache"]["dir"]}/conf.d/openstack-dashboard.conf" do

7
spec/.rubocop.yml Normal file
View File

@ -0,0 +1,7 @@
# embedded attributes make for long lines
LineLength:
Enabled: false
# Allow small arrays before forcing %w or %W
WordArray:
MinSize: 3

View File

@ -1,4 +1,5 @@
require_relative "spec_helper"
# encoding: UTF-8
require_relative 'spec_helper'
describe "openstack-dashboard::default" do
describe 'openstack-dashboard::default' do
end

View File

@ -1,47 +1,48 @@
require_relative "spec_helper"
# encoding: UTF-8
require_relative 'spec_helper'
describe "openstack-dashboard::server" do
describe 'openstack-dashboard::server' do
before { dashboard_stubs }
describe "fedora" do
describe 'fedora' do
before do
non_redhat_stubs
@chef_run = ::ChefSpec::Runner.new ::FEDORA_OPTS
@chef_run.converge "openstack-dashboard::server"
@chef_run.converge 'openstack-dashboard::server'
end
it "deletes openstack-dashboard.conf" do
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
it 'deletes openstack-dashboard.conf' do
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
expect(@chef_run).to delete_file file
end
it "doesn't remove the default ubuntu virtualhost" do
it 'does not remove the default ubuntu virtualhost' do
resource = @chef_run.find_resource(
"execute",
"a2dissite 000-default"
'execute',
'a2dissite 000-default'
)
expect(resource).to be_nil
end
it "removes default virtualhost" do
it 'removes default virtualhost' do
resource = @chef_run.find_resource(
"execute",
"a2dissite default"
'execute',
'a2dissite default'
).to_hash
expect(resource[:params]).to include(
:enable => false
enable: false
)
end
it "notifies restore-selinux-context" do
it 'notifies restore-selinux-context' do
pending "TODO: how to test this occured on apache_site 'default'"
end
it "executes restore-selinux-context" do
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
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)
end

View File

@ -1,56 +1,60 @@
require_relative "spec_helper"
# encoding: UTF-8
require_relative 'spec_helper'
describe "openstack-dashboard::server" do
describe 'openstack-dashboard::server' do
before { dashboard_stubs }
describe "opensuse" do
context "mysql backend" do
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(
{"db_type" => "mysql", "db_name" => "flying_dolphin"})
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
'db_type' => 'mysql', 'db_name' => 'flying_dolphin'
)
@chef_run.converge "openstack-dashboard::server"
@chef_run.converge 'openstack-dashboard::server'
end
it "installs mysql packages when mysql backend is configured" do
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(
{"db_type" => "mysql", "db_name" => "flying_dolphin"})
@chef_run.converge "openstack-dashboard::server"
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
'db_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
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(
{"db_type" => "postgresql", "db_name" => "flying_elephant"})
@chef_run.converge "openstack-dashboard::server"
::Chef::Recipe.any_instance.stub(:db).with('dashboard').and_return(
'db_type' => 'postgresql', 'db_name' => 'flying_elephant'
)
@chef_run.converge 'openstack-dashboard::server'
end
it "installs packages" do
expect(@chef_run).to upgrade_package "openstack-dashboard"
it 'installs packages' do
expect(@chef_run).to upgrade_package 'openstack-dashboard'
end
it "installs postgresql packages" do
expect(@chef_run).to upgrade_package "python-psycopg2"
it 'installs postgresql packages' do
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"
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"
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

View File

@ -1,131 +1,132 @@
require_relative "spec_helper"
# encoding: UTF-8
require_relative 'spec_helper'
describe "openstack-dashboard::server" do
describe 'openstack-dashboard::server' do
before { dashboard_stubs }
describe "redhat" do
describe 'redhat' do
before do
redhat_stubs
@chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS
@chef_run.converge "openstack-dashboard::server"
@chef_run.converge 'openstack-dashboard::server'
end
it "executes set-selinux-permissive" do
cmd = "/sbin/setenforce Permissive"
it 'executes set-selinux-permissive' do
cmd = '/sbin/setenforce Permissive'
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"
it 'installs packages' do
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
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"]["db_type"] = "db2"
chef_run.converge "openstack-dashboard::server"
["db2-odbc", "python-ibm-db", "python-ibm-db-django", "python-ibm-db-sa"].each do |pkg|
node.set['openstack']['db']['dashboard']['db_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
end
end
it "executes set-selinux-enforcing" do
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
it 'executes set-selinux-enforcing' do
cmd = '/sbin/setenforce Enforcing ; restorecon -R /etc/httpd'
expect(@chef_run).to run_execute(cmd)
end
describe "local_settings" do
describe 'local_settings' do
before do
@file = @chef_run.template "/etc/openstack-dashboard/local_settings"
@file = @chef_run.template '/etc/openstack-dashboard/local_settings'
end
it "has proper owner" do
expect(@file.owner).to eq("root")
expect(@file.group).to eq("root")
it 'has proper owner' do
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"
it 'has proper modes' do
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")
it 'rh specific template' do
expect(@chef_run).to render_file(@file.name).with_content('WEBROOT')
end
end
describe "certs" do
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"
@crt = @chef_run.cookbook_file '/etc/pki/tls/certs/horizon.pem'
@key = @chef_run.cookbook_file '/etc/pki/tls/private/horizon.key'
end
it "has proper owner" do
it 'has proper owner' do
[@crt, @key].each do |file|
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
end
it "has proper modes" do
expect(sprintf("%o", @crt.mode)).to eq "644"
expect(sprintf("%o", @key.mode)).to eq "640"
it 'has proper modes' do
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)
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)
end
end
describe "openstack-dashboard virtual host" do
describe 'openstack-dashboard virtual host' do
before do
f = "/etc/httpd/conf.d/openstack-dashboard"
f = '/etc/httpd/conf.d/openstack-dashboard'
@file = @chef_run.template f
end
it "has proper owner" do
expect(@file.owner).to eq("root")
expect(@file.group).to eq("root")
it 'has proper owner' do
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"
it 'has proper modes' do
expect(sprintf('%o', @file.mode)).to eq '644'
end
it "sets the ServerName directive " do
it 'sets the ServerName directive ' do
chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS do |n|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
n.set['openstack']['dashboard']['server_hostname'] = 'spec-test-host'
end
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
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 "notifies restore-selinux-context" do
expect(@file).to notify("execute[restore-selinux-context]").to(:run)
it 'notifies restore-selinux-context' do
expect(@file).to notify('execute[restore-selinux-context]').to(:run)
end
end
it "deletes openstack-dashboard.conf" do
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
it 'deletes openstack-dashboard.conf' do
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
expect(@chef_run).to delete_file file
end
it "does not remove openstack-dashboard-ubuntu-theme package" do
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 "doesn't remove default apache site" do
pending "TODO: how to properly test this"
it 'does not remove default apache site' do
pending 'TODO: how to properly test this'
end
it "doesn't execute restore-selinux-context" do
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
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)
end

View File

@ -1,188 +1,189 @@
require_relative "spec_helper"
# encoding: UTF-8
require_relative 'spec_helper'
describe "openstack-dashboard::server" do
describe 'openstack-dashboard::server' do
before { dashboard_stubs }
describe "ubuntu" do
describe 'ubuntu' do
before do
non_redhat_stubs
@chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-dashboard::server"
@chef_run.converge 'openstack-dashboard::server'
end
it "doesn't execute set-selinux-permissive" do
cmd = "/sbin/setenforce Permissive"
it 'does nt 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"
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'
end
it "doesn't execute set-selinux-enforcing" do
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
it 'does not execute set-selinux-enforcing' do
cmd = '/sbin/setenforce Enforcing ; restorecon -R /etc/httpd'
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"
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'
end
describe "local_settings.py" do
describe 'local_settings.py' do
before do
@file = @chef_run.template "/etc/openstack-dashboard/local_settings.py"
@file = @chef_run.template '/etc/openstack-dashboard/local_settings.py'
end
it "has proper owner" do
expect(@file.owner).to eq("root")
expect(@file.group).to eq("root")
it 'has proper owner' do
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"
it 'has proper modes' do
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")
it 'has the customer banner' do
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")
it 'has the memcached servers' do
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
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).
and_return nil
chef_run.converge "openstack-dashboard::server"
::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
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).
and_return []
chef_run.converge "openstack-dashboard::server"
::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
it 'has some plugins enabled' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
n.set['openstack']['dashboard']['plugins'] = ['testPlugin1']
end
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
expect(chef_run).to render_file(@file.name).with_content("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)
it 'notifies apache2 restart' do
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")
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')
end
it "configures ssl proxy when ssl_offload is set to true" do
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
n.set['openstack']['dashboard']['ssl_offload'] = true
end
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
expect(chef_run).to render_file(@file.name).with_content("SECURE_PROXY_SSL_HEADER")
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")
it 'has a help_url' do
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")
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')
end
end
it "executes openstack-dashboard syncdb" do
cmd = "python manage.py syncdb --noinput"
it 'executes openstack-dashboard syncdb' do
cmd = 'python manage.py syncdb --noinput'
expect(@chef_run).to run_execute(cmd).with(
:cwd => "/usr/share/openstack-dashboard",
:environment => {
"PYTHONPATH" => "/etc/openstack-dashboard:" \
"/usr/share/openstack-dashboard:" \
"$PYTHONPATH"
cwd: '/usr/share/openstack-dashboard',
environment: {
'PYTHONPATH' => '/etc/openstack-dashboard:' \
'/usr/share/openstack-dashboard:' \
'$PYTHONPATH'
}
)
end
describe "certs" do
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"
@crt = @chef_run.cookbook_file '/etc/ssl/certs/horizon.pem'
@key = @chef_run.cookbook_file '/etc/ssl/private/horizon.key'
end
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")
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')
end
it "has proper modes" do
expect(sprintf("%o", @crt.mode)).to eq "644"
expect(sprintf("%o", @key.mode)).to eq "640"
it 'has proper modes' do
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)
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)
end
end
it "creates .blackhole dir with proper owner" do
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
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
describe 'openstack-dashboard virtual host' do
before do
f = "/etc/apache2/sites-available/openstack-dashboard"
f = '/etc/apache2/sites-available/openstack-dashboard'
@file = @chef_run.template f
end
it "has proper owner" do
expect(@file.owner).to eq("root")
expect(@file.group).to eq("root")
it 'has proper owner' do
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"
it 'has proper modes' do
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")
it 'has the default banner' do
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/")
it 'has the default DocRoot' do
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
it 'sets the ServerName directive ' do
chef_run = ::ChefSpec::Runner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
n.set['openstack']['dashboard']['server_hostname'] = 'spec-test-host'
end
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
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
@ -229,64 +230,69 @@ describe "openstack-dashboard::server" do
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)
it 'notifies restore-selinux-context' do
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"
it 'does not delete openstack-dashboard.conf' do
file = '/etc/httpd/conf.d/openstack-dashboard.conf'
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"
it 'removes openstack-dashboard-ubuntu-theme package' do
expect(@chef_run).to purge_package 'openstack-dashboard-ubuntu-theme'
end
it "calls apache_site to disable 000-default virtualhost" do
it 'calls apache_site to disable 000-default virtualhost' do
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS)
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
resource = chef_run.find_resource("execute",
"a2dissite 000-default").to_hash
resource = chef_run.find_resource('execute',
'a2dissite 000-default').to_hash
expect(resource).to include(
:action => "run",
:params => {:enable => false, :name => "000-default"}
action: 'run',
params: {
enable: false,
name: '000-default'
}
)
end
it "calls apache_site to enable openstack-dashboard virtualhost" do
it 'calls apache_site to enable openstack-dashboard virtualhost' do
chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS)
chef_run.converge "openstack-dashboard::server"
chef_run.converge 'openstack-dashboard::server'
resource = chef_run.find_resource("execute",
"a2ensite openstack-dashboard").to_hash
resource = chef_run.find_resource('execute',
'a2ensite openstack-dashboard').to_hash
expect(resource).to include(
:action => "run",
:params => {:enable => true,
:notifies => [:reload, "service[apache2]", :immediately],
:name => "openstack-dashboard"}
action: 'run',
params: {
enable: true,
notifies: [:reload, 'service[apache2]', :immediately],
name: 'openstack-dashboard'
}
)
end
it "notifies apache2 restart" do
pending "TODO: how to test when tied to an LWRP"
it 'notifies apache2 restart' do
pending 'TODO: how to test when tied to an LWRP'
end
it "doesn't execute restore-selinux-context" do
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
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)
end
it "has group write mode on path" do
it 'has group write mode on path' do
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'])
end
it "has group write mode on file" do
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'])

View File

@ -1,33 +1,34 @@
require "chefspec"
require "chefspec/berkshelf"
# encoding: UTF-8
require 'chefspec'
require 'chefspec/berkshelf'
::LOG_LEVEL = :fatal
::FEDORA_OPTS = {
:platform => "fedora",
:version => "18",
:log_level => ::LOG_LEVEL
platform: 'fedora',
version: '18',
log_level: ::LOG_LEVEL
}
::REDHAT_OPTS = {
:platform => "redhat",
:version => "6.3",
:log_level => ::LOG_LEVEL
platform: 'redhat',
version: '6.3',
log_level: ::LOG_LEVEL
}
::UBUNTU_OPTS = {
:platform => "ubuntu",
:version => "12.04",
:log_level => ::LOG_LEVEL
platform: 'ubuntu',
version: '12.04',
log_level: ::LOG_LEVEL
}
::OPENSUSE_OPTS = {
:platform => "opensuse",
:version => "12.3",
:log_level => ::LOG_LEVEL
platform: 'opensuse',
version: '12.3',
log_level: ::LOG_LEVEL
}
def dashboard_stubs
::Chef::Recipe.any_instance.stub(:memcached_servers).
and_return ["hostA:port", "hostB:port"]
::Chef::Recipe.any_instance.stub(:db_password).with("horizon").
and_return "test-pass"
::Chef::Recipe.any_instance.stub(:memcached_servers)
.and_return ['hostA:port', 'hostB:port']
::Chef::Recipe.any_instance.stub(:db_password).with('horizon')
.and_return 'test-pass'
end
def redhat_stubs