Test cleanups for chefspec 1.3.0
ChefSpec 1.3.0 allows tests to evaluate guards. Wired in this cookbook to use that functionality. Made tests a bit clearer. Change-Id: If6fae7b255de42ace75ecc507e99bb6bdd1be7e6
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -3,6 +3,6 @@ source "https://rubygems.org"
|
|||||||
gem "chef", "~> 11.4.4"
|
gem "chef", "~> 11.4.4"
|
||||||
gem "json", "<= 1.7.7" # chef 11 dependency
|
gem "json", "<= 1.7.7" # chef 11 dependency
|
||||||
gem "berkshelf", "~> 1.4.5"
|
gem "berkshelf", "~> 1.4.5"
|
||||||
gem "chefspec", "~> 1.2.0"
|
gem "chefspec", "~> 1.3.0"
|
||||||
gem "foodcritic"
|
gem "foodcritic"
|
||||||
gem "strainer"
|
gem "strainer"
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ GEM
|
|||||||
ohai (>= 0.6.0)
|
ohai (>= 0.6.0)
|
||||||
rest-client (>= 1.0.4, < 1.7.0)
|
rest-client (>= 1.0.4, < 1.7.0)
|
||||||
yajl-ruby (~> 1.1)
|
yajl-ruby (~> 1.1)
|
||||||
chefspec (1.2.0)
|
chefspec (1.3.0)
|
||||||
chef (>= 10.0)
|
chef (>= 10.0)
|
||||||
erubis
|
erubis
|
||||||
fauxhai (>= 0.1.1, < 2.0)
|
fauxhai (>= 0.1.1, < 2.0)
|
||||||
@@ -113,7 +113,7 @@ GEM
|
|||||||
net-ssh-multi (1.1)
|
net-ssh-multi (1.1)
|
||||||
net-ssh (>= 2.1.4)
|
net-ssh (>= 2.1.4)
|
||||||
net-ssh-gateway (>= 0.99.0)
|
net-ssh-gateway (>= 0.99.0)
|
||||||
nokogiri (1.5.9)
|
nokogiri (1.5.10)
|
||||||
nori (1.1.5)
|
nori (1.1.5)
|
||||||
ohai (6.16.0)
|
ohai (6.16.0)
|
||||||
ipaddress
|
ipaddress
|
||||||
@@ -191,7 +191,7 @@ PLATFORMS
|
|||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
berkshelf (~> 1.4.5)
|
berkshelf (~> 1.4.5)
|
||||||
chef (~> 11.4.4)
|
chef (~> 11.4.4)
|
||||||
chefspec (~> 1.2.0)
|
chefspec (~> 1.3.0)
|
||||||
foodcritic
|
foodcritic
|
||||||
json (<= 1.7.7)
|
json (<= 1.7.7)
|
||||||
strainer
|
strainer
|
||||||
|
|||||||
@@ -166,16 +166,17 @@ package "openstack-dashboard-ubuntu-theme" do
|
|||||||
only_if { platform?("ubuntu")}
|
only_if { platform?("ubuntu")}
|
||||||
end
|
end
|
||||||
|
|
||||||
if platform?("debian","ubuntu") then
|
apache_site "000-default" do
|
||||||
apache_site "000-default" do
|
|
||||||
enable false
|
enable false
|
||||||
end
|
|
||||||
elsif platform?("fedora") then
|
only_if { platform?("debian","ubuntu") }
|
||||||
apache_site "default" do
|
end
|
||||||
|
|
||||||
|
apache_site "default" do
|
||||||
enable false
|
enable false
|
||||||
|
|
||||||
notifies :run, "execute[restore-selinux-context]", :immediately
|
notifies :run, "execute[restore-selinux-context]", :immediately
|
||||||
end
|
only_if { platform?("fedora") }
|
||||||
end
|
end
|
||||||
|
|
||||||
apache_site "openstack-dashboard" do
|
apache_site "openstack-dashboard" do
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ describe "openstack-dashboard::server" do
|
|||||||
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
|
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
|
||||||
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
|
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
|
||||||
{"db_type" => "mysql", "db_name" => "flying_dolphin"})
|
{"db_type" => "mysql", "db_name" => "flying_dolphin"})
|
||||||
|
|
||||||
@chef_run.converge "openstack-dashboard::server"
|
@chef_run.converge "openstack-dashboard::server"
|
||||||
|
|
||||||
expect(@chef_run).to upgrade_package "python-mysql"
|
expect(@chef_run).to upgrade_package "python-mysql"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -33,7 +33,6 @@ describe "openstack-dashboard::server" do
|
|||||||
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
|
@chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS
|
||||||
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
|
::Chef::Recipe.any_instance.stub(:db).with("dashboard").and_return(
|
||||||
{"db_type" => "postgresql", "db_name" => "flying_elephant"})
|
{"db_type" => "postgresql", "db_name" => "flying_elephant"})
|
||||||
|
|
||||||
@chef_run.converge "openstack-dashboard::server"
|
@chef_run.converge "openstack-dashboard::server"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,11 +46,13 @@ describe "openstack-dashboard::server" do
|
|||||||
|
|
||||||
it "creates local_settings.py" do
|
it "creates local_settings.py" do
|
||||||
file = @chef_run.template "/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py"
|
file = @chef_run.template "/usr/share/openstack-dashboard/openstack_dashboard/local/local_settings.py"
|
||||||
|
|
||||||
expect(@chef_run).to create_file_with_content(file.name, "autogenerated")
|
expect(@chef_run).to create_file_with_content(file.name, "autogenerated")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "creates .blackhole dir with proper owner" do
|
it "creates .blackhole dir with proper owner" do
|
||||||
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
|
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
|
||||||
|
|
||||||
expect(@chef_run.directory(dir)).to be_owned_by "root"
|
expect(@chef_run.directory(dir)).to be_owned_by "root"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "executes set-selinux-permissive" do
|
it "executes set-selinux-permissive" do
|
||||||
pending "TODO: how to properly test this"
|
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
|
||||||
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
|
chef_run.stub_command(/.*/, true)
|
||||||
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
cmd = "/sbin/setenforce Permissive"
|
||||||
|
|
||||||
|
expect(chef_run).to execute_command cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
it "installs packages" do
|
it "installs packages" do
|
||||||
@@ -24,7 +30,13 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "executes set-selinux-enforcing" do
|
it "executes set-selinux-enforcing" do
|
||||||
pending "TODO: how to properly test this"
|
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
|
||||||
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
|
chef_run.stub_command(/.*/, true)
|
||||||
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd"
|
||||||
|
|
||||||
|
expect(chef_run).to execute_command cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "local_settings" do
|
describe "local_settings" do
|
||||||
@@ -82,9 +94,9 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "sets the ServerName directive " do
|
it "sets the ServerName directive " do
|
||||||
chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS
|
chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS do |n|
|
||||||
node = chef_run.node
|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
|
||||||
node.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 create_file_with_content @file.name, "spec-test-host"
|
expect(chef_run).to create_file_with_content @file.name, "spec-test-host"
|
||||||
@@ -96,20 +108,36 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "deletes openstack-dashboard.conf" do
|
it "deletes openstack-dashboard.conf" do
|
||||||
|
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
|
||||||
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
|
chef_run.stub_command(/.*/, true)
|
||||||
|
chef_run.converge "openstack-dashboard::server"
|
||||||
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
|
file = "/etc/httpd/conf.d/openstack-dashboard.conf"
|
||||||
expect(@chef_run).to delete_file file
|
|
||||||
|
expect(chef_run).to delete_file file
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not remove openstack-dashboard-ubuntu-theme package" do
|
it "does not remove openstack-dashboard-ubuntu-theme package" do
|
||||||
pending "TODO: how to properly test this will not run"
|
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
|
||||||
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
|
chef_run.stub_command(/.*/, false)
|
||||||
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
|
||||||
|
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"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't execute restore-selinux-context" do
|
it "doesn't execute restore-selinux-context" do
|
||||||
pending "TODO: how to properly test this will not run"
|
opts = ::REDHAT_OPTS.merge(:evaluate_guards => true)
|
||||||
end
|
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 || :"
|
||||||
|
|
||||||
it "doesn't remove default virtualhost" do
|
expect(chef_run).not_to execute_command cmd
|
||||||
pending "TODO: how to properly test this will not run"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,13 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't execute set-selinux-permissive" do
|
it "doesn't execute set-selinux-permissive" do
|
||||||
pending "TODO: how to properly test this will not run"
|
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
|
end
|
||||||
|
|
||||||
it "installs apache packages" do
|
it "installs apache packages" do
|
||||||
@@ -26,7 +32,13 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't execute set-selinux-enforcing" do
|
it "doesn't execute set-selinux-enforcing" do
|
||||||
pending "TODO: how to properly test this will not run"
|
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
|
end
|
||||||
|
|
||||||
it "installs packages" do
|
it "installs packages" do
|
||||||
@@ -61,6 +73,7 @@ describe "openstack-dashboard::server" do
|
|||||||
::Chef::Recipe.any_instance.stub(:memcached_servers).
|
::Chef::Recipe.any_instance.stub(:memcached_servers).
|
||||||
and_return nil
|
and_return nil
|
||||||
chef_run.converge "openstack-dashboard::server"
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
|
||||||
expect(chef_run).not_to create_file_with_content @file.name,
|
expect(chef_run).not_to create_file_with_content @file.name,
|
||||||
"django.core.cache.backends.memcached.MemcachedCache"
|
"django.core.cache.backends.memcached.MemcachedCache"
|
||||||
end
|
end
|
||||||
@@ -70,14 +83,15 @@ describe "openstack-dashboard::server" do
|
|||||||
::Chef::Recipe.any_instance.stub(:memcached_servers).
|
::Chef::Recipe.any_instance.stub(:memcached_servers).
|
||||||
and_return []
|
and_return []
|
||||||
chef_run.converge "openstack-dashboard::server"
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
|
||||||
expect(chef_run).not_to create_file_with_content @file.name,
|
expect(chef_run).not_to create_file_with_content @file.name,
|
||||||
"django.core.cache.backends.memcached.MemcachedCache"
|
"django.core.cache.backends.memcached.MemcachedCache"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "has some plugins enabled" do
|
it "has some plugins enabled" do
|
||||||
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
|
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
|
||||||
node = chef_run.node
|
n.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
|
||||||
node.set["openstack"]["dashboard"]["plugins"] = ["testPlugin1" ]
|
end
|
||||||
chef_run.converge "openstack-dashboard::server"
|
chef_run.converge "openstack-dashboard::server"
|
||||||
|
|
||||||
expect(chef_run).to create_file_with_content @file.name, "testPlugin1"
|
expect(chef_run).to create_file_with_content @file.name, "testPlugin1"
|
||||||
@@ -124,6 +138,7 @@ describe "openstack-dashboard::server" do
|
|||||||
|
|
||||||
it "creates .blackhole dir with proper owner" do
|
it "creates .blackhole dir with proper owner" do
|
||||||
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
|
dir = "/usr/share/openstack-dashboard/openstack_dashboard/.blackhole"
|
||||||
|
|
||||||
expect(@chef_run.directory(dir)).to be_owned_by "root"
|
expect(@chef_run.directory(dir)).to be_owned_by "root"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -151,22 +166,27 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "sets the ServerName directive " do
|
it "sets the ServerName directive " do
|
||||||
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
|
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS do |n|
|
||||||
node = chef_run.node
|
n.set["openstack"]["dashboard"]["server_hostname"] = "spec-test-host"
|
||||||
node.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 create_file_with_content @file.name, "spec-test-host"
|
expect(chef_run).to create_file_with_content @file.name, "spec-test-host"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
it "notifies restore-selinux-context" do
|
it "notifies restore-selinux-context" do
|
||||||
expect(@file).to notify "execute[restore-selinux-context]", :run
|
expect(@file).to notify "execute[restore-selinux-context]", :run
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not delete openstack-dashboard.conf" do
|
it "does not delete openstack-dashboard.conf" do
|
||||||
pending "TODO: how to properly test this will not run"
|
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
|
end
|
||||||
|
|
||||||
it "removes openstack-dashboard-ubuntu-theme package" do
|
it "removes openstack-dashboard-ubuntu-theme package" do
|
||||||
@@ -174,26 +194,20 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "removes default virtualhost" do
|
it "removes default virtualhost" do
|
||||||
chef_run = ::ChefSpec::ChefRunner.new(
|
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
|
||||||
:platform => "ubuntu",
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
:version => "12.04",
|
chef_run.converge "openstack-dashboard::server"
|
||||||
:step_into => ["apache_site"],
|
|
||||||
:log_level => :fatal
|
|
||||||
).converge "openstack-dashboard::server"
|
|
||||||
|
|
||||||
cmd = "/usr/sbin/a2dissite 000-default"
|
cmd = "/usr/sbin/a2dissite 000-default"
|
||||||
|
|
||||||
expect(chef_run).to execute_command cmd
|
expect(chef_run).to execute_command cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
it "enables virtualhost" do
|
it "enables virtualhost" do
|
||||||
chef_run = ::ChefSpec::ChefRunner.new(
|
opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"])
|
||||||
:platform => "ubuntu",
|
chef_run = ::ChefSpec::ChefRunner.new opts
|
||||||
:version => "12.04",
|
chef_run.converge "openstack-dashboard::server"
|
||||||
:step_into => ["apache_site"],
|
|
||||||
:log_level => :fatal
|
|
||||||
).converge "openstack-dashboard::server"
|
|
||||||
|
|
||||||
cmd = "/usr/sbin/a2ensite openstack-dashboard"
|
cmd = "/usr/sbin/a2ensite openstack-dashboard"
|
||||||
|
|
||||||
expect(chef_run).to execute_command cmd
|
expect(chef_run).to execute_command cmd
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -202,7 +216,13 @@ describe "openstack-dashboard::server" do
|
|||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't execute restore-selinux-context" do
|
it "doesn't execute restore-selinux-context" do
|
||||||
pending "TODO: how to properly test this will not run"
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user