From 834838bcdc29681ab7e020d81d10ff0017dae210 Mon Sep 17 00:00:00 2001 From: Matt Ray Date: Mon, 3 Jun 2013 14:18:33 -0500 Subject: [PATCH] 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 --- README.md | 7 ++++++- attributes/default.rb | 2 +- metadata.rb | 9 ++++++--- recipes/mysql-client.rb | 4 +++- run_tests.bash | 19 +++++++++++++++++++ spec/client_spec.rb | 19 +++++++++++++++++++ spec/default_spec.rb | 4 ---- spec/mysql-client_spec.rb | 23 +++++++++++++++++++++++ spec/mysql-server_spec.rb | 30 ++++++++++++++++++++++++++++++ spec/server_spec.rb | 24 ++++++++++++++++++++++++ 10 files changed, 131 insertions(+), 10 deletions(-) create mode 100755 run_tests.bash create mode 100644 spec/client_spec.rb delete mode 100644 spec/default_spec.rb create mode 100644 spec/mysql-client_spec.rb create mode 100644 spec/mysql-server_spec.rb create mode 100644 spec/server_spec.rb diff --git a/README.md b/README.md index 02d9b16..6adf00f 100644 --- a/README.md +++ b/README.md @@ -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 # diff --git a/attributes/default.rb b/attributes/default.rb index fedc70e..2700046 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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' ] diff --git a/metadata.rb b/metadata.rb index bd2ebe5..ca5aad6 100644 --- a/metadata.rb +++ b/metadata.rb @@ -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" diff --git a/recipes/mysql-client.rb b/recipes/mysql-client.rb index b7def7f..d7fce88 100644 --- a/recipes/mysql-client.rb +++ b/recipes/mysql-client.rb @@ -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 diff --git a/run_tests.bash b/run_tests.bash new file mode 100755 index 0000000..141e8ee --- /dev/null +++ b/run_tests.bash @@ -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} diff --git a/spec/client_spec.rb b/spec/client_spec.rb new file mode 100644 index 0000000..17b9ace --- /dev/null +++ b/spec/client_spec.rb @@ -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 diff --git a/spec/default_spec.rb b/spec/default_spec.rb deleted file mode 100644 index 996e330..0000000 --- a/spec/default_spec.rb +++ /dev/null @@ -1,4 +0,0 @@ -require "spec_helper" - -describe "openstack-ops-database::default" do -end diff --git a/spec/mysql-client_spec.rb b/spec/mysql-client_spec.rb new file mode 100644 index 0000000..0c9b308 --- /dev/null +++ b/spec/mysql-client_spec.rb @@ -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 diff --git a/spec/mysql-server_spec.rb b/spec/mysql-server_spec.rb new file mode 100644 index 0000000..a974634 --- /dev/null +++ b/spec/mysql-server_spec.rb @@ -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 diff --git a/spec/server_spec.rb b/spec/server_spec.rb new file mode 100644 index 0000000..9458e67 --- /dev/null +++ b/spec/server_spec.rb @@ -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