Refactored tests

* Tests are now passing
* Removed chef-solo conditional from #memcached_server
* All tests should log if fatal encountered, this cleans up stdout
* #db_create_with_user test had a test which wouldn't occur, b/c
  the attributes have a default value
* Added a couple pending tests for the database LWRPs
This commit is contained in:
John Dewey
2013-05-06 19:05:22 -07:00
parent 852a8e679d
commit 5df85f3706
13 changed files with 196 additions and 149 deletions

View File

@@ -1,9 +0,0 @@
cookbook 'openstack-common', :path => '/home/jdewey/git/cookbook-openstack-common'
cookbook 'apt', :locked_version => '1.8.0'
cookbook 'database', :locked_version => '1.3.10'
cookbook 'mysql', :locked_version => '2.1.0'
cookbook 'openssl', :locked_version => '1.0.0'
cookbook 'build-essential', :locked_version => '1.3.2'
cookbook 'postgresql', :locked_version => '2.1.0'
cookbook 'aws', :locked_version => '0.100.6'
cookbook 'xfs', :locked_version => '1.1.0'

View File

@@ -1,5 +1,6 @@
source :rubygems
source "https://rubygems.org"
gem "berkshelf", "~> 1.0.4"
gem "chefspec", "~> 0.9.0"
gem "foodcritic", "~> 1.6.1"
gem "chef", "~> 10.18.2"
gem "berkshelf", "~> 1.4.0"
gem "chefspec", "~> 1.0.0"
gem "foodcritic", "~> 2.1.0"

View File

@@ -1,30 +1,30 @@
GEM
remote: http://rubygems.org/
remote: https://rubygems.org/
specs:
activemodel (3.2.11)
activesupport (= 3.2.11)
builder (~> 3.0.0)
activesupport (3.2.11)
i18n (~> 0.6)
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
addressable (2.3.2)
archive-tar-minitar (0.5.2)
berkshelf (1.0.4)
activesupport
chef (>= 10.16.2)
chozo (>= 0.2.3)
hashie
addressable (2.3.4)
berkshelf (1.4.2)
activesupport (>= 3.2.0)
addressable
celluloid (>= 0.13.0)
chozo (>= 0.6.1)
faraday (>= 0.8.5)
hashie (>= 2.0.2)
json (>= 1.5.0)
minitar
multi_json (>= 1.3.0)
ridley (>= 0.4.1)
solve (>= 0.4.0.rc1)
thor (~> 0.16.0)
vagrant (~> 1.0.5)
mixlib-config (~> 1.1)
mixlib-shellout (~> 1.1)
multi_json (~> 1.5)
retryable
ridley (~> 0.9.0)
solve (>= 0.4.2)
thor (~> 0.18.0)
yajl-ruby
builder (3.0.4)
builder (3.2.0)
bunny (0.7.9)
celluloid (0.12.4)
facter (>= 1.6.12)
celluloid (0.13.0)
timers (>= 1.0.0)
chef (10.18.2)
bunny (>= 0.6.0, < 0.8.0)
@@ -44,71 +44,68 @@ GEM
treetop (~> 1.4.9)
uuidtools
yajl-ruby (~> 1.1)
chefspec (0.9.0)
chef (>= 0.9.12)
chefspec (1.0.0)
chef (>= 10.0)
erubis
minitest-chef-handler (~> 0.6.0)
rspec (~> 2.11.0)
childprocess (0.3.7)
ffi (~> 1.0, >= 1.0.6)
chozo (0.4.2)
fauxhai (~> 0.1)
minitest-chef-handler (>= 0.6.0)
rspec (~> 2.0)
chozo (0.6.1)
activesupport (>= 3.2.0)
hashie
hashie (>= 2.0.2)
multi_json (>= 1.3.0)
ci_reporter (1.8.4)
builder (>= 2.1.2)
coderay (1.0.8)
diff-lcs (1.1.3)
diff-lcs (1.2.4)
erubis (2.7.0)
facter (1.6.17)
faraday (0.8.4)
faraday (0.8.7)
multipart-post (~> 1.1)
ffi (1.3.1)
foodcritic (1.6.1)
fauxhai (0.1.1)
chef
httparty
net-ssh
foodcritic (2.1.0)
erubis
gherkin (~> 2.11.1)
gist (~> 3.1.0)
nokogiri (= 1.5.0)
pry (~> 0.9.8.4)
gherkin (~> 2.11.7)
nokogiri (~> 1.5.4)
rak (~> 1.4)
treetop (~> 1.4.10)
yajl-ruby (~> 1.1.0)
gherkin (2.11.5)
json (>= 1.4.6)
gist (3.1.1)
hashie (1.2.0)
highline (1.6.15)
gherkin (2.11.8)
multi_json (~> 1.3)
hashie (2.0.4)
highline (1.6.18)
httparty (0.11.0)
multi_json (~> 1.0)
multi_xml (>= 0.5.2)
i18n (0.6.1)
ipaddress (0.8.0)
json (1.5.4)
log4r (1.1.10)
method_source (0.7.1)
mime-types (1.19)
json (1.6.1)
mime-types (1.23)
minitar (0.5.4)
minitest (4.5.0)
minitest-chef-handler (0.6.5)
minitest (4.7.4)
minitest-chef-handler (1.0.1)
chef
ci_reporter
minitest
minitest (~> 4.7.3)
mixlib-authentication (1.3.0)
mixlib-log
mixlib-cli (1.3.0)
mixlib-config (1.1.2)
mixlib-log (1.4.1)
mixlib-log (1.6.0)
mixlib-shellout (1.1.0)
moneta (0.6.0)
multi_json (1.5.0)
multipart-post (1.1.5)
multi_json (1.7.3)
multi_xml (0.5.3)
multipart-post (1.2.0)
net-http-persistent (2.8)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
net-ssh (2.2.2)
net-ssh-gateway (1.1.0)
net-ssh (>= 1.99.1)
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nokogiri (1.5.0)
nokogiri (1.5.9)
ohai (6.16.0)
ipaddress
mixlib-cli
@@ -118,60 +115,51 @@ GEM
systemu
yajl-ruby
polyglot (0.3.3)
pry (0.9.8.4)
coderay (~> 1.0.5)
method_source (~> 0.7.1)
slop (>= 2.4.4, < 3)
rak (1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
ridley (0.6.3)
activemodel (>= 3.2.0)
retryable (1.3.2)
ridley (0.9.1)
activesupport (>= 3.2.0)
addressable
celluloid
chozo (>= 0.2.2)
celluloid (~> 0.13.0)
chozo (>= 0.6.0)
erubis
faraday
faraday (>= 0.8.4)
json (>= 1.5.0)
mixlib-authentication
mixlib-log
mixlib-authentication (>= 1.3.0)
mixlib-config (>= 1.1.0)
mixlib-log (>= 1.3.0)
mixlib-shellout (>= 1.1.0)
multi_json (>= 1.0.4)
net-http-persistent (>= 2.8)
net-ssh
rspec (2.11.0)
rspec-core (~> 2.11.0)
rspec-expectations (~> 2.11.0)
rspec-mocks (~> 2.11.0)
rspec-core (2.11.1)
rspec-expectations (2.11.3)
diff-lcs (~> 1.1.3)
rspec-mocks (2.11.3)
slop (2.4.4)
solve (0.4.1)
retryable
solve (>= 0.4.1)
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)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.13.1)
solve (0.4.3)
json
systemu (2.5.2)
thor (0.16.0)
thor (0.18.1)
timers (1.1.0)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
uuidtools (2.1.3)
vagrant (1.0.6)
archive-tar-minitar (= 0.5.2)
childprocess (~> 0.3.1)
erubis (~> 2.7.0)
i18n (~> 0.6.0)
json (~> 1.5.1)
log4r (~> 1.1.9)
net-scp (~> 1.0.4)
net-ssh (~> 2.2.2)
uuidtools (2.1.4)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
berkshelf (~> 1.0.4)
chefspec (~> 0.9.0)
foodcritic (~> 1.6.1)
berkshelf (~> 1.4.0)
chef (~> 10.18.2)
chefspec (~> 1.0.0)
foodcritic (~> 2.1.0)

View File

@@ -37,8 +37,8 @@ module ::Openstack
case type
when "postgresql", "pgsql"
include_recipe "database::postgresql"
db_prov = Chef::Provider::Database::Postgresql
user_prov = Chef::Provider::Database::PostgresqlUser
db_prov = ::Chef::Provider::Database::Postgresql
user_prov = ::Chef::Provider::Database::PostgresqlUser
super_user = "postgres"
if root_user_use_databag
user_key = node['openstack']['db']['root_user_key']
@@ -49,8 +49,8 @@ module ::Openstack
when "mysql"
# we have to install the 'mysql' gem, otherwise the provider won't work
include_recipe "database::mysql"
db_prov = Chef::Provider::Database::Mysql
user_prov = Chef::Provider::Database::MysqlUser
db_prov = ::Chef::Provider::Database::Mysql
user_prov = ::Chef::Provider::Database::MysqlUser
super_user = "root"
# For some reason, setting this to anything other than localhost fails miserably :(
@@ -62,7 +62,7 @@ module ::Openstack
super_password = node['mysql']['server_root_password']
end
else
Chef::Log.error("Unsupported database type #{type}")
::Chef::Log.error("Unsupported database type #{type}")
end
connection_info = {

View File

@@ -79,16 +79,8 @@ module ::Openstack
# env - sets environment where to search
# role - sets role that is used to filter out memcached nodes
def memcached_servers(env=node.chef_environment, role="infra-caching")
if Chef::Config[:solo]
if node['memcached']
["#{node['memcached']['listen']}:11211"]
else
[]
end
else
search(:node, "chef_environment:#{env} AND roles:#{role}").map do |c_node|
"#{c_node['memcached']['listen']}:11211"
end
search(:node, "chef_environment:#{env} AND roles:#{role}").map do |c_node|
"#{c_node['memcached']['listen']}:11211"
end
end

View File

@@ -24,15 +24,12 @@ when "debian"
end
apt_uri = node["openstack"]["apt"]["uri"]
log("Setting APT repository to #{apt_uri}, with components:") { level :info }
apt_components = node["openstack"]["apt"]["components"]
# Simple variable substitution for LSB codename and OpenStack release
apt_components.each do | comp |
comp = comp.gsub "%release%", node["openstack"]["release"]
comp = comp.gsub "%codename%", node["lsb"]["codename"]
log(" #{comp}") { level :info }
end
apt_repository "openstack-ppa" do

View File

@@ -0,0 +1,9 @@
require "spec_helper"
describe "openstack-common::default" do
describe "suse" do
it "configures openstack repository" do
pending "TODO: implement"
end
end
end

View File

@@ -1,42 +1,43 @@
require "chefspec"
require "spec_helper"
require ::File.join ::File.dirname(__FILE__), "..", "libraries", "default"
describe "openstack-common::default" do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
end
describe "apt setup" do
it "sets apt repositories correctly" do
Chef::Recipe.any_instance.stub :apt_repository
@chef_run = ::ChefSpec::ChefRunner.new(:log_level => :info) do |n|
n.set["platform_family"] = "debian"
describe "ubuntu" do
before do
opts = ::UBUNTU_OPTS.merge :step_into => ["apt_repository"]
@chef_run = ::ChefSpec::ChefRunner.new(opts) do |n|
n.set["lsb"]["codename"] = "precise"
n.set["openstack"]["release"] = "folsom"
end
@chef_run.converge "openstack-common::default"
@chef_run.should install_package "ubuntu-cloud-keyring"
@chef_run.should log " precise-updates/folsom"
@chef_run.should log " main"
end
it "installs ubuntu-cloud-keyring package" do
expect(@chef_run).to install_package "ubuntu-cloud-keyring"
end
it "configures openstack repository" do
file = "/etc/apt/sources.list.d/openstack-ppa.list"
expected = "deb http://ubuntu-cloud.archive.canonical.com/ubuntu precise-updates/grizzly main"
expect(@chef_run).to create_file_with_content file, expected
end
end
end
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
@chef_run = ::ChefSpec::ChefRunner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default"
@subject = ::Object.new.extend ::Openstack
@subject.stub :include_recipe
end
describe "#db_create_with_user" do
it "returns nil when no openstack.db not in node attrs" do
@subject.stub(:node).and_return {}
@subject.db_create_with_user("nonexisting", "user", "pass").should be_nil
end
it "returns nil when no such service was found" do
@subject.stub(:node).and_return @chef_run.node
@subject.db_create_with_user("nonexisting", "user", "pass").should be_nil
end
it "returns db info and creates database with user when service found" do
@subject.stub(:database).and_return {}
@subject.stub(:database_user).and_return {}
@@ -45,5 +46,17 @@ describe ::Openstack do
result['host'].should == "127.0.0.1"
result['port'].should == "3306"
end
it "creates database" do
pending "TODO: test this LWRP"
end
it "creates database user" do
pending "TODO: test this LWRP"
end
it "grants privs to database user" do
pending "TODO: test this LWRP"
end
end
end

View File

@@ -3,7 +3,8 @@ require ::File.join ::File.dirname(__FILE__), "..", "libraries", "endpoints"
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
@chef_run = ::ChefSpec::ChefRunner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default"
@subject = ::Object.new.extend ::Openstack
end

42
spec/logging_spec.rb Normal file
View File

@@ -0,0 +1,42 @@
require "spec_helper"
describe "openstack-common::logging" do
describe "ubuntu" do
before do
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-common::logging"
end
describe "/etc/openstack" do
before do
@dir = @chef_run.directory "/etc/openstack"
end
it "has proper owner" do
expect(@dir).to be_owned_by "root", "root"
end
it "has proper modes" do
expect(sprintf("%o", @dir.mode)).to eq "755"
end
end
describe "logging.conf" do
before do
@file = @chef_run.template "/etc/openstack/logging.conf"
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 "template contents" do
pending "TODO: implement"
end
end
end
end

View File

@@ -3,13 +3,14 @@ require ::File.join ::File.dirname(__FILE__), "..", "libraries", "passwords"
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
@chef_run = ::ChefSpec::ChefRunner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default"
@subject = ::Object.new.extend(::Openstack)
end
describe "#secret" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new(:log_level => :info) do |n|
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@@ -29,7 +30,7 @@ describe ::Openstack do
describe "#service_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new do |n|
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@@ -49,7 +50,7 @@ describe ::Openstack do
describe "#db_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new do |n|
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"
@@ -69,7 +70,7 @@ describe ::Openstack do
describe "#user_password" do
it "returns index param when developer_mode is true" do
@chef_run = ::ChefSpec::ChefRunner.new do |n|
@chef_run = ::ChefSpec::ChefRunner.new(::CHEFSPEC_OPTS) do |n|
n.set["openstack"]["developer_mode"] = true
end
@chef_run.converge "openstack-common::default"

View File

@@ -4,7 +4,8 @@ require ::File.join ::File.dirname(__FILE__), "..", "libraries", "roles"
describe ::Openstack do
before do
@chef_run = ::ChefSpec::ChefRunner.new.converge "openstack-common::default"
@chef_run = ::ChefSpec::ChefRunner.new ::CHEFSPEC_OPTS
@chef_run.converge "openstack-common::default"
@subject = ::Object.new.extend ::Openstack
end

11
spec/spec_helper.rb Normal file
View File

@@ -0,0 +1,11 @@
require "chefspec"
::LOG_LEVEL = :fatal
::UBUNTU_OPTS = {
:platform => "ubuntu",
:version => "12.04",
:log_level => ::LOG_LEVEL
}
::CHEFSPEC_OPTS = {
:log_level => ::LOG_LEVEL
}