Basic testing of the ops-database recipes.

This creates basic testing of the recipes as well as remove unused code such as
the fedora support and the use of passing attributes to openstack::packages.

Change-Id: Iece19811151fbdfd067e12d3b3163cfb78174e49
This commit is contained in:
Matt Ray
2013-06-03 14:18:33 -05:00
parent 27911c00eb
commit 834838bcdc
10 changed files with 131 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
# Description #
This cookbook provides shared database configuration for the OpenStack **Grizzly** reference deployment provided by Chef for OpenStack. The http://github.com/mattray/chef-openstack-repo contains documentation for using this cookbook in the context of a full OpenStack deployment. It currently supports MySQL and will soon support PostgreSQL.
This cookbook provides a reference example of database configuration for the OpenStack **Grizzly** reference deployment provided by Chef for OpenStack. It currently supports MySQL and will soon support PostgreSQL.
# Requirements #
@@ -16,6 +16,11 @@ The following cookbooks are dependencies:
* database
* mysql
* postgresql
# Usage #
The usage of this cookbook is optional, you may choose to set up your own databases without using this cookbook. If you choose to do so, you will need to provide all of the attributes listed under the [Attributes](#attributes) and create the schema specified by the `openstack-*-db` recipes.
# Resources/Providers #

View File

@@ -4,7 +4,7 @@ default['openstack']['database']['service'] = 'mysql'
# platform defaults
case platform
when 'fedora', 'redhat', 'centos' # :pragma-foodcritic: ~FC024 - won't fix this
when 'redhat', 'centos' # :pragma-foodcritic: ~FC024 - won't fix this
default['openstack']['database']['platform']['mysql_python_packages'] = [ 'MySQL-python' ]
when 'ubuntu'
default['openstack']['database']['platform']['mysql_python_packages'] = [ 'python-mysqldb' ]

View File

@@ -5,12 +5,15 @@ license "Apache 2.0"
description "Provides the shared database configuration for Chef for OpenStack."
version "7.0.0"
recipe "client", "Installs client CLI package for the database used by the deployment."
recipe "client", "Installs client packages for the database used by the deployment."
recipe "server", "Installs and configures server packages for the database used by the deployment."
recipe "mysql-client", "Installs MySQL client packages."
recipe "mysql-server", "Installs and configured MySQL server packages."
%w{ ubuntu redhat fedora centos }.each do |os|
%w{ ubuntu redhat centos }.each do |os|
supports os
end
depends "database", ">= 1.3.12"
depends "database", ">= 1.4"
depends "mysql", ">= 3.0.0"
depends "postgresql", ">= 3.0.0"

View File

@@ -20,4 +20,6 @@
include_recipe "mysql::ruby"
include_recipe "mysql::client"
node.default['openstack']['packages']['ops-database::mysql-client'] = node['openstack']['database']['platform']['mysql_python_packages']
node['openstack']['database']['platform']['mysql_python_packages'].each do |pkg|
package pkg
end

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}

19
spec/client_spec.rb Normal file
View File

@@ -0,0 +1,19 @@
require_relative 'spec_helper'
describe 'openstack-ops-database::client' do
describe 'ubuntu' do
it "select 'mysql-client' recipe" do
chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
node.set['lsb'] = {'codename' => 'precise'}
node.set['openstack']= {'database' => {
'service' => 'mysql'
}
}
end
chef_run.converge 'openstack-ops-database::client'
expect(chef_run).to include_recipe "openstack-ops-database::mysql-client"
end
end
end

View File

@@ -1,4 +0,0 @@
require "spec_helper"
describe "openstack-ops-database::default" do
end

23
spec/mysql-client_spec.rb Normal file
View File

@@ -0,0 +1,23 @@
require_relative 'spec_helper'
describe 'openstack-ops-database::mysql-client' do
describe 'ubuntu' do
before do
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
node.set['lsb'] = {'codename' => 'precise'}
node.set['openstack']= {'database' => {
'service' => 'mysql'
}
}
end
@chef_run.converge "openstack-ops-database::mysql-client"
end
it "mysql-client recipe tests" do
expect(@chef_run).to include_recipe "mysql::ruby"
expect(@chef_run).to include_recipe "mysql::client"
expect(@chef_run).to install_package "python-mysqldb"
end
end
end

30
spec/mysql-server_spec.rb Normal file
View File

@@ -0,0 +1,30 @@
require_relative 'spec_helper'
describe 'openstack-ops-database::mysql-server' do
describe 'ubuntu' do
before do
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
node.set['lsb'] = {'codename' => 'precise'}
node.set['mysql'] = {
'server_debian_password' => 'foo',
'server_root_password' => 'bar',
'server_repl_password' => 'baz'
}
node.set['openstack']= {'database' => {
'service' => 'mysql'
}
}
end
@chef_run.converge "openstack-ops-database::mysql-server"
end
it "mysql-client recipe basic test" do
expect(@chef_run).to include_recipe "openstack-ops-database::mysql-client"
expect(@chef_run).to include_recipe "mysql::ruby"
expect(@chef_run).to include_recipe "mysql::client"
expect(@chef_run).to include_recipe "mysql::server"
expect(@chef_run).to install_package "python-mysqldb"
end
end
end

24
spec/server_spec.rb Normal file
View File

@@ -0,0 +1,24 @@
require_relative 'spec_helper'
describe 'openstack-ops-database::server' do
describe 'ubuntu' do
it "select 'mysql-server' recipe" do
chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |node|
node.set['lsb'] = {'codename' => 'precise'}
node.set['mysql'] = {
'server_debian_password' => 'foo',
'server_root_password' => 'bar',
'server_repl_password' => 'baz'
}
node.set['openstack']= {'database' => {
'service' => 'mysql'
}
}
end
chef_run.converge 'openstack-ops-database::server'
expect(chef_run).to include_recipe "openstack-ops-database::mysql-server"
end
end
end