xiaodongwang 0e1a88bb87 update snippet to support 14.04 version
Change-Id: I81b9ae9d51ad1930256110c31a70cf756e4f6f8a
2014-05-29 13:43:20 -07:00

239 lines
8.0 KiB
Ruby

require_relative "spec_helper"
describe "openstack-dashboard::server" do
before { dashboard_stubs }
describe "ubuntu" do
before do
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-dashboard::server"
end
it "doesn't execute set-selinux-permissive" do
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Permissive"
expect(chef_run).not_to execute_command 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"
end
it "doesn't execute set-selinux-enforcing" do
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
expect(chef_run).not_to execute_command cmd
end
it "installs packages" do
expect(@chef_run).to upgrade_package "node-less"
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
it "has proper owner" do
expect(@file).to be_owned_by "root", "root"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "644"
end
it "has the customer banner" do
expect(@chef_run).to create_file_with_content @file.name, "autogenerated"
end
it "has the memcached servers" do
expect(@chef_run).to create_file_with_content @file.name, "hostA"
end
it "does not configure caching when backend == memcache and no servers provided" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
::Chef::Recipe.any_instance.stub(:memcached_servers).
and_return nil
chef_run.converge "openstack-dashboard::server"
expect(chef_run).not_to create_file_with_content @file.name,
"django.core.cache.backends.memcached.MemcachedCache"
end
it "does not configure caching when memcache_servers is empty" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
::Chef::Recipe.any_instance.stub(:memcached_servers).
and_return []
chef_run.converge "openstack-dashboard::server"
expect(chef_run).not_to create_file_with_content @file.name,
"django.core.cache.backends.memcached.MemcachedCache"
end
it "has some plugins enabled" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to create_file_with_content @file.name, "testPlugin1"
end
it "notifies apache2 restart" do
expect(@file).to notify "service[apache2]", :restart
end
it "does not configure ssl proxy when ssl_offload is false" do
expect(@chef_run).not_to(
create_file_with_content @file.name, "SECURE_PROXY_SSL_HEADER")
end
it "configures ssl proxy when ssl_offload is set to true" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["ssl_offload"] = true
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to(
create_file_with_content @file.name, "SECURE_PROXY_SSL_HEADER")
end
end
it "executes openstack-dashboard syncdb" do
cmd = "python manage.py syncdb --noinput"
expect(@chef_run).to execute_command(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
it "has proper owner" do
expect(@crt).to be_owned_by "root", "root"
expect(@key).to be_owned_by "root", "ssl-cert"
end
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]", :run
expect(@key).to notify "execute[restore-selinux-context]", :run
end
end
it "creates .blackhole dir with proper owner" do
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
expect(@chef_run.directory(dir)).to be_owned_by "root"
end
describe "openstack-dashboard virtual host" do
before do
f = "/etc/apache2/sites-available/openstack-dashboard.conf"
@file = @chef_run.template f
end
it "has proper owner" do
expect(@file).to be_owned_by "root", "root"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "644"
end
it "has the default banner" do
expect(@chef_run).to create_file_with_content @file.name, "autogenerated"
end
it "has the default DocRoot" do
expect(@chef_run).to create_file_with_content @file.name,
"DocumentRoot /usr/share/openstack-dashboard/openstack_dashboard/.blackhole/"
end
it "sets the ServerName directive " do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
end
chef_run.converge "openstack-dashboard::server"
expect(chef_run).to create_file_with_content @file.name, "spec-test-host"
end
it "notifies restore-selinux-context" do
expect(@file).to notify "execute[restore-selinux-context]", :run
end
end
it "does not delete openstack-dashboard.conf" do
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
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"
end
it "removes default virtualhost" do
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.converge "openstack-dashboard::server"
cmd = "/usr/sbin/a2dissite 000-default"
expect(chef_run).to execute_command cmd
end
it "enables virtualhost" do
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.converge "openstack-dashboard::server"
cmd = "/usr/sbin/a2ensite openstack-dashboard"
expect(chef_run).to execute_command cmd
end
it "notifies apache2 restart" do
pending "TODO: how to test when tied to an LWRP"
end
it "doesn't execute restore-selinux-context" do
opts = ::UBUNTU_OPTS.merge(:evaluate_guards => true)
chef_run = ::ChefSpec::ChefRunner.new opts
chef_run.stub_command(/.*/, false)
chef_run.converge "openstack-dashboard::server"
cmd = "restorecon -Rv /etc/httpd /etc/pki; chcon -R -t httpd_sys_content_t /usr/share/openstack-dashboard || :"
expect(chef_run).not_to execute_command cmd
end
end
end