From 41d142d3098b8111ffe64749b521ec492fbeb735 Mon Sep 17 00:00:00 2001 From: Chen Zhiwei Date: Wed, 11 Dec 2013 20:24:17 -0500 Subject: [PATCH] Upgrade to Havana release Also upgrade gems: - berkshelf, ~> 2.0.10 - chefspec, ~> 3.0.2 - foodcritic, ~> 3.0.3 And update the DEPRECATION keywords Change-Id: Id37bcb0a751e60581864b196e2e72b8eb37dca6c --- CHANGELOG.md | 7 ++ Gemfile | 6 +- Gemfile.lock | 166 ++++++++++++++++++----------------- README.md | 2 + metadata.rb | 4 +- spec/server-fedora_spec.rb | 15 +--- spec/server-opensuse_spec.rb | 22 ++--- spec/server-redhat_spec.rb | 57 +++++------- spec/server_spec.rb | 120 ++++++++++++------------- spec/spec_helper.rb | 10 +++ 10 files changed, 197 insertions(+), 212 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b7bd89a --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +openstack-dashboard Cookbook CHANGELOG +============================== +This file is used to list changes made in each version of the openstack-dashboard cookbook. + +## 8.0.0 +### New version +* Upgrade to upstream Havana release diff --git a/Gemfile b/Gemfile index ffbff4a..3491dfb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" gem "chef", "~> 11.4.4" gem "json", "<= 1.7.7" # chef 11 dependency -gem "berkshelf", "~> 1.4.5" -gem "chefspec", "~> 1.3.0" -gem "foodcritic" +gem "berkshelf", "~> 2.0.10" +gem "chefspec", "~> 3.0.2" +gem "foodcritic", "~> 3.0.3" gem "strainer" gem "tailor" diff --git a/Gemfile.lock b/Gemfile.lock index fb9593e..6afd4ee 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,33 +1,41 @@ GEM remote: https://rubygems.org/ specs: - activesupport (3.2.13) - i18n (= 0.6.1) + activesupport (3.2.16) + i18n (~> 0.6, >= 0.6.4) multi_json (~> 1.0) - addressable (2.3.4) + addressable (2.3.5) akami (1.2.0) gyoku (>= 0.4.0) nokogiri (>= 1.4.0) - berkshelf (1.4.5) - activesupport (>= 3.2.0) - addressable - celluloid (>= 0.14.0) + berkshelf (2.0.10) + activesupport (~> 3.2.0) + addressable (~> 2.3.4) + buff-shell_out (~> 0.1) chozo (>= 0.6.1) faraday (>= 0.8.5) hashie (>= 2.0.2) - json (>= 1.5.0) - minitar - mixlib-config (~> 1.1) - mixlib-shellout (~> 1.1) - multi_json (~> 1.5) - retryable - ridley (~> 0.12.4) - solve (>= 0.4.2) + minitar (~> 0.5.4) + rbzip2 (~> 0.2.0) + retryable (~> 1.3.3) + ridley (~> 1.5.0) + solve (>= 0.5.0) thor (~> 0.18.0) - yajl-ruby + buff-config (0.4.0) + buff-extensions (~> 0.3) + varia_model (~> 0.1) + buff-extensions (0.5.0) + buff-ignore (1.1.1) + buff-platform (0.1.0) + buff-ruby_engine (0.1.0) + buff-shell_out (0.1.1) + buff-ruby_engine (~> 0.1.0) builder (3.2.2) celluloid (0.14.1) timers (>= 1.0.0) + celluloid-io (0.14.1) + celluloid (>= 0.14.1) + nio4r (>= 0.4.5) chef (11.4.4) erubis highline (>= 1.6.9) @@ -42,118 +50,111 @@ GEM ohai (>= 0.6.0) rest-client (>= 1.0.4, < 1.7.0) yajl-ruby (~> 1.1) - chefspec (1.3.0) - chef (>= 10.0) - erubis - fauxhai (>= 0.1.1, < 2.0) - minitest-chef-handler (>= 0.6.0) - rspec (~> 2.0) + chefspec (3.0.2) + chef (~> 11.0) + fauxhai (~> 2.0) + rspec (~> 2.14) chozo (0.6.1) activesupport (>= 3.2.0) hashie (>= 2.0.2) multi_json (>= 1.3.0) - ci_reporter (1.8.4) - builder (>= 2.1.2) - diff-lcs (1.2.4) + diff-lcs (1.2.5) erubis (2.7.0) - faraday (0.8.7) - multipart-post (~> 1.1) - fauxhai (1.1.1) - httparty + faraday (0.8.8) + multipart-post (~> 1.2.0) + fauxhai (2.0.1) net-ssh ohai - ffi (1.8.1) - foodcritic (2.1.0) + ffi (1.9.3) + foodcritic (3.0.3) erubis gherkin (~> 2.11.7) nokogiri (~> 1.5.4) - rak (~> 1.4) + rake treetop (~> 1.4.10) yajl-ruby (~> 1.1.0) gherkin (2.11.8) multi_json (~> 1.3) gssapi (1.0.3) ffi (>= 1.0.1) - gyoku (1.0.0) + gyoku (1.1.0) builder (>= 2.1.2) hashie (2.0.5) - highline (1.6.19) - httparty (0.11.0) - multi_json (~> 1.0) - multi_xml (>= 0.5.2) - httpclient (2.2.0.2) + highline (1.6.20) + httpclient (2.3.4.1) httpi (0.9.7) rack - i18n (0.6.1) + i18n (0.6.9) ipaddress (0.8.0) json (1.7.7) little-plugger (1.1.3) log_switch (0.4.0) - logging (1.6.2) + logging (1.8.1) little-plugger (>= 1.1.3) - mime-types (1.23) + multi_json (>= 1.3.6) + mime-types (2.0) minitar (0.5.4) - minitest (4.7.4) - minitest-chef-handler (1.0.1) - chef - ci_reporter - minitest (~> 4.7.3) mixlib-authentication (1.3.0) mixlib-log mixlib-cli (1.3.0) - mixlib-config (1.1.2) + mixlib-config (2.1.0) mixlib-log (1.6.0) - mixlib-shellout (1.1.0) - multi_json (1.7.6) - multi_xml (0.5.4) + mixlib-shellout (1.3.0) + multi_json (1.8.2) multipart-post (1.2.0) - net-http-persistent (2.8) - net-ssh (2.6.7) + net-http-persistent (2.9) + net-ssh (2.7.0) net-ssh-gateway (1.2.0) net-ssh (>= 2.6.5) net-ssh-multi (1.1) net-ssh (>= 2.1.4) net-ssh-gateway (>= 0.99.0) + nio4r (0.5.0) nokogiri (1.5.10) nori (1.1.5) - ohai (6.16.0) + ohai (6.20.0) ipaddress mixlib-cli mixlib-config mixlib-log mixlib-shellout - systemu + systemu (~> 2.5.2) yajl-ruby polyglot (0.3.3) rack (1.5.2) - rak (1.4) + rake (10.1.0) + rbzip2 (0.2.0) rest-client (1.6.7) mime-types (>= 1.16) retryable (1.3.3) - ridley (0.12.4) + ridley (1.5.3) addressable + buff-config (~> 0.2) + buff-extensions (~> 0.3) + buff-ignore (~> 1.1) + buff-shell_out (~> 0.1) celluloid (~> 0.14.0) - chozo (>= 0.6.0) + celluloid-io (~> 0.14.0) erubis faraday (>= 0.8.4) hashie (>= 2.0.2) + json (>= 1.7.7) mixlib-authentication (>= 1.3.0) - mixlib-config (>= 1.1.0) - mixlib-log (>= 1.3.0) - mixlib-shellout (>= 1.1.0) net-http-persistent (>= 2.8) net-ssh + nio4r (>= 0.5.0) retryable solve (>= 0.4.4) + varia_model (~> 0.1) winrm (~> 1.1.0) - rspec (2.13.0) - rspec-core (~> 2.13.0) - rspec-expectations (~> 2.13.0) - rspec-mocks (~> 2.13.0) - rspec-core (2.13.1) - rspec-expectations (2.13.0) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.7) + rspec-expectations (2.14.4) diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.13.1) + rspec-mocks (2.14.4) rubyntlm (0.1.1) savon (0.9.5) akami (~> 1.0) @@ -163,12 +164,12 @@ GEM nokogiri (>= 1.4.0) nori (~> 1.0) wasabi (~> 1.0) - solve (0.4.4) - json - strainer (2.1.0) - berkshelf (~> 1.3) + solve (0.8.2) + strainer (3.3.0) + berkshelf (~> 2.0) + buff-platform (~> 0.1) systemu (2.5.2) - tailor (1.2.1) + tailor (1.3.1) log_switch (>= 0.3.0) term-ansicolor (>= 1.0.5) text-table (>= 1.2.2) @@ -177,18 +178,21 @@ GEM text-table (1.2.3) thor (0.18.1) timers (1.1.0) - tins (0.8.0) - treetop (1.4.14) + tins (0.13.1) + treetop (1.4.15) polyglot polyglot (>= 0.3.1) uuidtools (2.1.4) + varia_model (0.2.0) + buff-extensions (~> 0.2) + hashie (>= 2.0.2) wasabi (1.0.0) nokogiri (>= 1.4.0) - winrm (1.1.2) + winrm (1.1.3) gssapi (~> 1.0.0) - httpclient (~> 2.2.0.2) - logging (~> 1.6.1) - nokogiri (~> 1.5.0) + httpclient (~> 2.2, >= 2.2.0.2) + logging (~> 1.6, >= 1.6.1) + nokogiri (~> 1.5) rubyntlm (~> 0.1.1) savon (= 0.9.5) uuidtools (~> 2.1.2) @@ -198,10 +202,10 @@ PLATFORMS ruby DEPENDENCIES - berkshelf (~> 1.4.5) + berkshelf (~> 2.0.10) chef (~> 11.4.4) - chefspec (~> 1.3.0) - foodcritic + chefspec (~> 3.0.2) + foodcritic (~> 3.0.3) json (<= 1.7.7) strainer tailor diff --git a/README.md b/README.md index 5144dd5..2f9682e 100644 --- a/README.md +++ b/README.md @@ -75,10 +75,12 @@ License and Author | **Author** | John Dewey () | | **Author** | Matt Ray () | | **Author** | Sean Gallagher () | +| **Author** | Chen Zhiwei () | | | | | **Copyright** | Copyright (c) 2012, Rackspace US, Inc. | | **Copyright** | Copyright (c) 2012-2013, AT&T Services, Inc. | | **Copyright** | Copyright (c) 2013, Opscode, Inc. | +| **Copyright** | Copyright (c) 2013, IBM, Corp. | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/metadata.rb b/metadata.rb index 2965ea1..4c46a7f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ maintainer_email "cookbooks@lists.tfoundry.com" license "Apache 2.0" description "Installs/Configures the OpenStack Dasboard (Horizon)" long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version "7.0.0" +version "8.0.0" recipe "openstack-dashboard::server", "Sets up the Horizon dashboard within an Apache `mod_wsgi` container." @@ -13,4 +13,4 @@ recipe "openstack-dashboard::server", "Sets up the Horizon dashboard w end depends "apache2" -depends "openstack-common", "~> 0.4.0" +depends "openstack-common", "~> 8.0" diff --git a/spec/server-fedora_spec.rb b/spec/server-fedora_spec.rb index b299da9..81f23eb 100644 --- a/spec/server-fedora_spec.rb +++ b/spec/server-fedora_spec.rb @@ -5,18 +5,15 @@ describe "openstack-dashboard::server" do describe "fedora" do before do - @chef_run = ::ChefSpec::ChefRunner.new ::FEDORA_OPTS + non_redhat_stubs + @chef_run = ::ChefSpec::Runner.new ::FEDORA_OPTS @chef_run.converge "openstack-dashboard::server" end it "deletes openstack-dashboard.conf" do - opts = ::FEDORA_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" - expect(chef_run).to delete_file file + expect(@chef_run).to delete_file file end it "doesn't remove the default ubuntu virtualhost" do @@ -44,13 +41,9 @@ describe "openstack-dashboard::server" do end it "executes restore-selinux-context" do - opts = ::FEDORA_OPTS.merge(:evaluate_guards => true) - chef_run = ::ChefSpec::ChefRunner.new opts - chef_run.stub_command(/.*/, true) - 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).to execute_command cmd + expect(@chef_run).not_to run_execute(cmd) end end end diff --git a/spec/server-opensuse_spec.rb b/spec/server-opensuse_spec.rb index c018c0a..aae0079 100644 --- a/spec/server-opensuse_spec.rb +++ b/spec/server-opensuse_spec.rb @@ -6,7 +6,8 @@ describe "openstack-dashboard::server" do describe "opensuse" do context "mysql backend" do before do - @chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS + 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"}) @@ -14,7 +15,7 @@ describe "openstack-dashboard::server" do end it "installs mysql packages when mysql backend is configured" do - @chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS + @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" @@ -25,7 +26,8 @@ describe "openstack-dashboard::server" do context "postgresql backend" do before do - @chef_run = ::ChefSpec::ChefRunner.new ::OPENSUSE_OPTS + 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" @@ -42,23 +44,13 @@ describe "openstack-dashboard::server" do it "creates local_settings.py" do 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 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)).to be_owned_by "root" - end - - it "creates an openstack-dashboard virtual host with proper DocRoot" do - # XXX this should be hardcoded to /etc/apache2/... , but the - # upstream cookbook is broken for SUSE - # see for e.g. http://tickets.opscode.com/browse/COOK-2434 - file = @chef_run.template "#{@chef_run.node["apache"]["dir"]}/conf.d/openstack-dashboard.conf" - - expect(@chef_run).to create_file_with_content(file.name, - "DocumentRoot /usr/share/openstack-dashboard/openstack_dashboard/.blackhole/") + expect(@chef_run.directory(dir).owner).to eq("root") end end end diff --git a/spec/server-redhat_spec.rb b/spec/server-redhat_spec.rb index b437d1e..2551312 100644 --- a/spec/server-redhat_spec.rb +++ b/spec/server-redhat_spec.rb @@ -5,18 +5,15 @@ describe "openstack-dashboard::server" do describe "redhat" do before do - @chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS + redhat_stubs + @chef_run = ::ChefSpec::Runner.new ::REDHAT_OPTS @chef_run.converge "openstack-dashboard::server" end it "executes set-selinux-permissive" 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" cmd = "/sbin/setenforce Permissive" - expect(chef_run).to execute_command cmd + expect(@chef_run).to run_execute(cmd) end it "installs packages" do @@ -25,13 +22,9 @@ describe "openstack-dashboard::server" do end it "executes set-selinux-enforcing" 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" cmd = "/sbin/setenforce Enforcing ; restorecon -R /etc/httpd" - expect(chef_run).to execute_command cmd + expect(@chef_run).to run_execute(cmd) end describe "local_settings" do @@ -40,7 +33,8 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@file).to be_owned_by "root", "root" + expect(@file.owner).to eq("root") + expect(@file.group).to eq("root") end it "has proper modes" do @@ -48,7 +42,7 @@ describe "openstack-dashboard::server" do end it "rh specific template" do - expect(@chef_run).to create_file_with_content @file.name, "WEBROOT" + expect(@chef_run).to render_file(@file.name).with_content("WEBROOT") end end @@ -59,8 +53,10 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@crt).to be_owned_by "root", "root" - expect(@key).to be_owned_by "root", "root" + [@crt, @key].each do |file| + expect(file.owner).to eq("root") + expect(file.group).to eq("root") + end end it "has proper modes" do @@ -69,8 +65,8 @@ describe "openstack-dashboard::server" do 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 + expect(@crt).to notify("execute[restore-selinux-context]").to(:run) + expect(@key).to notify("execute[restore-selinux-context]").to(:run) end end @@ -81,7 +77,8 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@file).to be_owned_by "root", "root" + expect(@file.owner).to eq("root") + expect(@file.group).to eq("root") end it "has proper modes" do @@ -89,36 +86,28 @@ describe "openstack-dashboard::server" do end it "sets the ServerName directive " do - chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS do |n| + chef_run = ::ChefSpec::Runner.new ::REDHAT_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" + 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]", :run + expect(@file).to notify("execute[restore-selinux-context]").to(:run) end end 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" - 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 - 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" + expect(@chef_run).not_to purge_package "openstack-dashboard-ubuntu-theme" end it "doesn't remove default apache site" do @@ -126,13 +115,9 @@ describe "openstack-dashboard::server" do end it "doesn't execute restore-selinux-context" do - opts = ::REDHAT_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 + expect(@chef_run).not_to run_execute(cmd) end end end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index b77a7c5..5dbc0e8 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -5,18 +5,15 @@ describe "openstack-dashboard::server" do describe "ubuntu" do before do - @chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS + non_redhat_stubs + @chef_run = ::ChefSpec::Runner.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 + expect(@chef_run).not_to run_execute(cmd) end it "installs apache packages" do @@ -27,13 +24,9 @@ describe "openstack-dashboard::server" do 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 + expect(@chef_run).not_to run_execute(cmd) end it "installs packages" do @@ -48,7 +41,8 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@file).to be_owned_by "root", "root" + expect(@file.owner).to eq("root") + expect(@file.group).to eq("root") end it "has proper modes" do @@ -56,74 +50,70 @@ describe "openstack-dashboard::server" do end it "has the customer banner" do - expect(@chef_run).to create_file_with_content @file.name, "autogenerated" + expect(@chef_run).to render_file(@file.name).with_content("autogenerated") end it "has the memcached servers" do - expect(@chef_run).to create_file_with_content @file.name, "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::ChefRunner.new ::UBUNTU_OPTS + chef_run = ::ChefSpec::Runner.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" + 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::ChefRunner.new ::UBUNTU_OPTS + chef_run = ::ChefSpec::Runner.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" + 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::ChefRunner.new ::UBUNTU_OPTS do |n| + 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 create_file_with_content @file.name, "testPlugin1" + expect(chef_run).to render_file(@file.name).with_content("testPlugin1") end it "notifies apache2 restart" do - expect(@file).to notify "service[apache2]", :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( - create_file_with_content @file.name, "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::ChefRunner.new ::UBUNTU_OPTS do |n| + 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( - create_file_with_content @file.name, "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 create_file_with_content @file.name, "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 create_file_with_content @file.name, "CSRF_COOKIE_SECURE = True" - expect(@chef_run).to create_file_with_content @file.name, "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 execute_command(cmd).with( + expect(@chef_run).to run_execute(cmd).with( :cwd => "/usr/share/openstack-dashboard", :environment => { "PYTHONPATH" => "/etc/openstack-dashboard:" \ @@ -140,8 +130,10 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@crt).to be_owned_by "root", "root" - expect(@key).to be_owned_by "root", "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 @@ -150,15 +142,15 @@ describe "openstack-dashboard::server" do 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 + 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)).to be_owned_by "root" + expect(@chef_run.directory(dir).owner).to eq("root") end describe "openstack-dashboard virtual host" do @@ -168,7 +160,8 @@ describe "openstack-dashboard::server" do end it "has proper owner" do - expect(@file).to be_owned_by "root", "root" + expect(@file.owner).to eq("root") + expect(@file.group).to eq("root") end it "has proper modes" do @@ -176,58 +169,61 @@ describe "openstack-dashboard::server" do end it "has the default banner" do - expect(@chef_run).to create_file_with_content @file.name, "autogenerated" + expect(@chef_run).to render_file(@file.name).with_content("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/" + 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::ChefRunner.new ::UBUNTU_OPTS do |n| + 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" - expect(chef_run).to create_file_with_content @file.name, "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]", :run + expect(@file).to notify("execute[restore-selinux-context]").to(: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 + 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 + it "calls apache_site to disable 000-default virtualhost" do + chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) chef_run.converge "openstack-dashboard::server" - cmd = "/usr/sbin/a2dissite 000-default" - expect(chef_run).to execute_command cmd + resource = chef_run.find_resource("execute", + "a2dissite 000-default").to_hash + expect(resource).to include( + :action => "run", + :params => {:enable => false, :name => "000-default"} + ) end - it "enables virtualhost" do - opts = ::UBUNTU_OPTS.merge(:step_into => ["apache_site"]) - chef_run = ::ChefSpec::ChefRunner.new opts + it "calls apache_site to enable openstack-dashboard virtualhost" do + chef_run = ::ChefSpec::Runner.new(::UBUNTU_OPTS) chef_run.converge "openstack-dashboard::server" - cmd = "/usr/sbin/a2ensite openstack-dashboard" - expect(chef_run).to execute_command cmd + 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"} + ) end it "notifies apache2 restart" do @@ -235,13 +231,9 @@ describe "openstack-dashboard::server" do 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 + expect(@chef_run).not_to run_execute(cmd) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6506821..cf129cd 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,3 +28,13 @@ def dashboard_stubs ::Chef::Recipe.any_instance.stub(:db_password).with("horizon"). and_return "test-pass" 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) +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) +end