Initial testing via chefspec of all recipes

* Did not implement template testing ATM.  Need to go through
  and add those.  Hoping to get some help with that.
This commit is contained in:
John Dewey 2013-05-05 21:28:57 -07:00
parent 170ef0404d
commit 9ae54fc736
14 changed files with 623 additions and 1 deletions

4
.gitignore vendored
View File

@ -1 +1,3 @@
*.swp
.bundle
.cookbooks/
Berksfile.lock

8
Berksfile Normal file
View File

@ -0,0 +1,8 @@
metadata
cookbook "glance",
git: "git@github.com:att-cloud/cookbook-glance.git"
cookbook "keystone",
git: "git@github.com:att-cloud/cookbook-keystone.git"
cookbook "openstack-common",
git: "git@github.com:att-cloud/cookbook-openstack-common.git"

6
Gemfile Normal file
View File

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

165
Gemfile.lock Normal file
View File

@ -0,0 +1,165 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
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
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.2.0)
bunny (0.7.9)
celluloid (0.13.0)
timers (>= 1.0.0)
chef (10.18.2)
bunny (>= 0.6.0, < 0.8.0)
erubis
highline (>= 1.6.9)
json (>= 1.4.4, <= 1.6.1)
mixlib-authentication (>= 1.3.0)
mixlib-cli (>= 1.1.0)
mixlib-config (>= 1.1.2)
mixlib-log (>= 1.3.0)
mixlib-shellout
moneta (< 0.7.0)
net-ssh (~> 2.2.2)
net-ssh-multi (~> 1.1.0)
ohai (>= 0.6.0)
rest-client (>= 1.0.4, < 1.7.0)
treetop (~> 1.4.9)
uuidtools
yajl-ruby (~> 1.1)
chefspec (1.0.0)
chef (>= 10.0)
erubis
fauxhai (~> 0.1)
minitest-chef-handler (>= 0.6.0)
rspec (~> 2.0)
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)
erubis (2.7.0)
faraday (0.8.7)
multipart-post (~> 1.1)
fauxhai (0.1.1)
chef
httparty
net-ssh
foodcritic (2.1.0)
erubis
gherkin (~> 2.11.7)
nokogiri (~> 1.5.4)
rak (~> 1.4)
treetop (~> 1.4.10)
yajl-ruby (~> 1.1.0)
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.6.1)
mime-types (1.23)
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-log (1.6.0)
mixlib-shellout (1.1.0)
moneta (0.6.0)
multi_json (1.7.3)
multi_xml (0.5.3)
multipart-post (1.2.0)
net-http-persistent (2.8)
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.9)
ohai (6.16.0)
ipaddress
mixlib-cli
mixlib-config
mixlib-log
mixlib-shellout
systemu
yajl-ruby
polyglot (0.3.3)
rak (1.4)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.2)
ridley (0.9.1)
activesupport (>= 3.2.0)
addressable
celluloid (~> 0.13.0)
chozo (>= 0.6.0)
erubis
faraday (>= 0.8.4)
json (>= 1.5.0)
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
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.2)
json
systemu (2.5.2)
thor (0.18.1)
timers (1.1.0)
treetop (1.4.12)
polyglot
polyglot (>= 0.3.1)
uuidtools (2.1.4)
yajl-ruby (1.1.0)
PLATFORMS
ruby
DEPENDENCIES
berkshelf (~> 1.4.0)
chef (~> 10.18.2)
chefspec (~> 1.0.0)
foodcritic (~> 2.1.0)

19
run_tests.bash Executable file
View File

@ -0,0 +1,19 @@
#!/usr/bin/env bash
# A script to run tests locally before committing.
set -e
COOKBOOK=$(awk '/^name/ {print $NF}' metadata.rb |tr -d \"\')
if [ -z $COOKBOOK ]; then
echo "Cookbook name not defined in metadata.rb"
exit 1
fi
BUNDLE_PATH=${BUNDLE_PATH:-.bundle}
BERKSHELF_PATH=${BERKSHELF_PATH:-.cookbooks}
bundle install --path=${BUNDLE_PATH}
bundle exec berks install --path=${BERKSHELF_PATH}
bundle exec foodcritic -f any -t ~FC003 -t ~FC023 ${BERKSHELF_PATH}/${COOKBOOK}
bundle exec rspec ${BERKSHELF_PATH}/${COOKBOOK}

21
spec/api-redhat_spec.rb Normal file
View File

@ -0,0 +1,21 @@
require "spec_helper"
describe "cinder::api" do
describe "redhat" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS
@chef_run.converge "cinder::api"
end
it "installs cinder api packages" do
expect(@chef_run).to upgrade_package "openstack-cinder"
expect(@chef_run).to upgrade_package "python-cinderclient"
expect(@chef_run).to upgrade_package "MySQL-python"
end
it "starts cinder api on boot" do
expect(@chef_run).to set_service_to_start_on_boot "openstack-cinder-api"
end
end
end

72
spec/api_spec.rb Normal file
View File

@ -0,0 +1,72 @@
require "spec_helper"
describe "cinder::api" do
describe "ubuntu" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@node = @chef_run.node
@node.set["cinder"]["syslog"]["use"] = true
@chef_run.converge "cinder::api"
end
expect_runs_openstack_common_logging_recipe
it "installs cinder api packages" do
expect(@chef_run).to upgrade_package "cinder-common"
expect(@chef_run).to upgrade_package "cinder-api"
expect(@chef_run).to upgrade_package "python-cinderclient"
expect(@chef_run).to upgrade_package "python-mysqldb"
end
##
#TODO: ChefSpec needs to handle guards better. This
# should only be created when pki is enabled.
describe "/var/cache/cinder" do
before do
@dir = @chef_run.directory "/var/cache/cinder"
end
it "has proper owner" do
expect(@dir).to be_owned_by "cinder", "cinder"
end
it "has proper modes" do
expect(sprintf("%o", @dir.mode)).to eq "700"
end
end
it "starts cinder api on boot" do
expect(@chef_run).to set_service_to_start_on_boot "cinder-api"
end
expect_creates_cinder_conf "service[cinder-api]"
it "runs db migrations" do
cmd = "cinder-manage db sync"
expect(@chef_run).to execute_command cmd
end
describe "api-paste.ini" do
before do
@file = @chef_run.template "/etc/cinder/api-paste.ini"
end
it "has proper owner" do
expect(@file).to be_owned_by "cinder", "cinder"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "644"
end
it "template contents" do
pending "TODO: implement"
end
it "notifies nova-api-ec2 restart" do
expect(@file).to notify "service[cinder-api]", :restart
end
end
end
end

24
spec/db_spec.rb Normal file
View File

@ -0,0 +1,24 @@
require "spec_helper"
describe "cinder::db" do
it "installs mysql packages" do
@chef_run = converge
expect(@chef_run).to include_recipe "mysql::client"
expect(@chef_run).to include_recipe "mysql::ruby"
end
it "creates database and user" do
::Chef::Recipe.any_instance.should_receive(:db_create_with_user).
with "volume", "cinder", "test-pass"
converge
end
def converge
::Chef::Recipe.any_instance.stub(:db_password).with("cinder").
and_return "test-pass"
::ChefSpec::ChefRunner.new(::UBUNTU_OPTS).converge "cinder::db"
end
end

View File

@ -0,0 +1,5 @@
require "spec_helper"
describe "cinder::keystone_registration" do
#TODO: implement
end

View File

@ -0,0 +1,24 @@
require "spec_helper"
describe "cinder::scheduler" do
describe "redhat" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS
@chef_run.converge "cinder::scheduler"
end
it "installs cinder api packages" do
expect(@chef_run).to upgrade_package "openstack-cinder"
expect(@chef_run).to upgrade_package "MySQL-python"
end
it "starts cinder scheduler" do
expect(@chef_run).to start_service "openstack-cinder-scheduler"
end
it "starts cinder scheduler on boot" do
expect(@chef_run).to set_service_to_start_on_boot "openstack-cinder-scheduler"
end
end
end

52
spec/scheduler_spec.rb Normal file
View File

@ -0,0 +1,52 @@
require "spec_helper"
describe "cinder::scheduler" do
describe "ubuntu" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@node = @chef_run.node
@node.set["cinder"]["syslog"]["use"] = true
@chef_run.converge "cinder::scheduler"
end
expect_runs_openstack_common_logging_recipe
it "installs cinder api packages" do
expect(@chef_run).to upgrade_package "cinder-scheduler"
expect(@chef_run).to upgrade_package "python-mysqldb"
end
it "starts cinder scheduler" do
expect(@chef_run).to start_service "cinder-scheduler"
end
it "starts cinder scheduler on boot" do
expect(@chef_run).to set_service_to_start_on_boot "cinder-scheduler"
end
describe "cinder-volume-usage-audit" do
before do
f = "/usr/local/bin/cinder-volume-usage-audit"
@file = @chef_run.cookbook_file 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 "755"
end
end
it "has cinder-volume-usage-audit cronjob" do
cron = @chef_run.cron "cinder-volume-usage-audit"
cmd = "/usr/local/bin/cinder-volume-usage-audit > " \
"/var/log/cinder/audit.log 2>&1"
expect(cron.command).to eq cmd
end
expect_creates_cinder_conf "service[cinder-scheduler]"
end
end

54
spec/spec_helper.rb Normal file
View File

@ -0,0 +1,54 @@
require "chefspec"
::LOG_LEVEL = :fatal
::REDHAT_OPTS = {
:platform => "redhat",
:log_level => ::LOG_LEVEL
}
::UBUNTU_OPTS = {
:platform => "ubuntu",
:version => "12.04",
:log_level => ::LOG_LEVEL
}
def glance_stubs
::Chef::Recipe.any_instance.stub(:config_by_role).
with("rabbitmq-server", "queue").and_return(
{'host' => 'rabbit-host', 'port' => 'rabbit-port'}
)
::Chef::Recipe.any_instance.stub(:config_by_role).
with("glance-api", "glance").and_return []
::Chef::Recipe.any_instance.stub(:db_password).and_return String.new
::Chef::Recipe.any_instance.stub(:user_password).and_return String.new
::Chef::Recipe.any_instance.stub(:service_password).and_return String.new
end
def expect_runs_openstack_common_logging_recipe
it "runs logging recipe if node attributes say to" do
expect(@chef_run).to include_recipe "openstack-common::logging"
end
end
def expect_creates_cinder_conf service, action=:restart
describe "cinder.conf" do
before do
@file = @chef_run.template "/etc/cinder/cinder.conf"
end
it "has proper owner" do
expect(@file).to be_owned_by "cinder", "cinder"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "644"
end
it "template contents" do
pending "TODO: implement"
end
it "notifies nova-api-ec2 restart" do
expect(@file).to notify service, action
end
end
end

View File

@ -0,0 +1,33 @@
require "spec_helper"
describe "cinder::volume" do
describe "redhat" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::REDHAT_OPTS
@chef_run.converge "cinder::volume"
end
it "installs cinder volume packages" do
expect(@chef_run).to upgrade_package "openstack-cinder"
expect(@chef_run).to upgrade_package "MySQL-python"
end
it "installs cinder iscsi packages" do
expect(@chef_run).to upgrade_package "scsi-target-utils"
end
it "starts cinder volume" do
expect(@chef_run).to start_service "openstack-cinder-volume"
end
it "starts cinder volume on boot" do
expected = "openstack-cinder-volume"
expect(@chef_run).to set_service_to_start_on_boot expected
end
it "starts iscsi target on boot" do
expect(@chef_run).to set_service_to_start_on_boot "tgtd"
end
end
end

137
spec/volume_spec.rb Normal file
View File

@ -0,0 +1,137 @@
require "spec_helper"
describe "cinder::volume" do
describe "ubuntu" do
before do
glance_stubs
@chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@node = @chef_run.node
@node.set["cinder"]["syslog"]["use"] = true
@chef_run.converge "cinder::volume"
end
expect_runs_openstack_common_logging_recipe
it "installs cinder volume packages" do
expect(@chef_run).to upgrade_package "cinder-volume"
expect(@chef_run).to upgrade_package "python-mysqldb"
end
it "installs cinder iscsi packages" do
expect(@chef_run).to upgrade_package "tgt"
end
it "starts cinder volume" do
expect(@chef_run).to start_service "cinder-volume"
end
it "starts cinder volume on boot" do
expect(@chef_run).to set_service_to_start_on_boot "cinder-volume"
end
expect_creates_cinder_conf "service[cinder-volume]"
it "starts iscsi target on boot" do
expect(@chef_run).to set_service_to_start_on_boot "tgt"
end
describe "targets.conf" do
before do
@file = @chef_run.template "/etc/tgt/targets.conf"
end
it "has proper modes" do
expect(sprintf("%o", @file.mode)).to eq "600"
end
it "notifies nova-api-ec2 restart" do
expect(@file).to notify "service[iscsitarget]", :restart
end
end
describe "patches" do
before do
@os_dir = "/usr/share/pyshared/cinder/openstack/common"
@dist_dir = "/usr/lib/python2.7/dist-packages/cinder/openstack/common"
end
describe "fileutils.py" do
before do
@source = ::File.join @os_dir, "fileutils.py"
@file = @chef_run.cookbook_file @source
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 "symlinks fileutils.py" do
ln = ::File.join @dist_dir, "fileutils.py"
expect(@chef_run.link(ln)).to link_to @source
end
end
describe "gettextutils.py" do
before do
@source = ::File.join @os_dir, "gettextutils.py"
@file = @chef_run.cookbook_file @source
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 "symlinks gettextutils.py" do
pending "TODO: should there be a gettextutils symlink?"
end
end
describe "lockutils.py" do
before do
@source = ::File.join @os_dir, "lockutils.py"
@file = @chef_run.cookbook_file @source
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 "symlinks gettextutils.py" do
ln = ::File.join @dist_dir, "lockutils.py"
expect(@chef_run.link(ln)).to link_to @source
end
end
describe "netapp.py" do
before do
f = "/usr/share/pyshared/cinder/volume/netapp.py"
@file = @chef_run.cookbook_file 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 "notifies nova-api-ec2 restart" do
expect(@file).to notify "service[cinder-volume]", :restart
end
end
end
end
end