Prep work before adding each db recipe

Brought in openstack-common as a dep.  Updated the tests to
better match what the recipes are doing (added tests where
missing).  Updated attributes to match the format of our other
cookbooks.  This is mostly some cleanups, to prepare for features.
Since this cookbook is not in use, made a larger commit than
would have if adding functionality to a released cookbook.  Also,
upgraded to new Berkshelf which handles locking to cookbooks properly.

Change-Id: I8e4123d30012a9890ce3029184e1396d2083a6f1
This commit is contained in:
John Dewey 2013-06-21 15:19:54 -07:00
parent e9f43fb646
commit 6e0df1d809
17 changed files with 270 additions and 128 deletions

1
.gitignore vendored
View File

@ -1,2 +1 @@
.bundle/
Berksfile.lock

View File

@ -1 +1,4 @@
metadata
cookbook "openstack-common",
git: "git://github.com/stackforge/cookbook-openstack-common.git"

37
Berksfile.lock Normal file
View File

@ -0,0 +1,37 @@
{
"sha": "f4f9d20dae74eaf72a8d7141ba2932f079adc5c6",
"sources": {
"openstack-ops-database": {
"path": "."
},
"openstack-common": {
"locked_version": "0.3.0",
"git": "git://github.com/stackforge/cookbook-openstack-common.git",
"ref": "0c771cfab3147489e7dffcf9b9b067f2aa9d0f8b"
},
"database": {
"locked_version": "1.4.0"
},
"mysql": {
"locked_version": "3.0.0"
},
"openssl": {
"locked_version": "1.0.2"
},
"build-essential": {
"locked_version": "1.4.0"
},
"postgresql": {
"locked_version": "3.0.0"
},
"apt": {
"locked_version": "1.10.0"
},
"aws": {
"locked_version": "0.101.0"
},
"xfs": {
"locked_version": "1.1.0"
}
}
}

View File

@ -2,7 +2,7 @@ source "https://rubygems.org"
gem "chef", "~> 11.4.4"
gem "json", "<= 1.7.7" # chef 11 dependency
gem "berkshelf", "~> 1.4.5"
gem "berkshelf", "~> 2.0.3"
gem "chefspec", "~> 1.2.0"
gem "foodcritic"
gem "strainer"

View File

@ -1,33 +1,41 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (3.2.13)
i18n (= 0.6.1)
multi_json (~> 1.0)
activesupport (4.0.0)
i18n (~> 0.6, >= 0.6.4)
minitest (~> 4.2)
multi_json (~> 1.3)
thread_safe (~> 0.1)
tzinfo (~> 0.3.37)
addressable (2.3.4)
akami (1.2.0)
gyoku (>= 0.4.0)
nokogiri (>= 1.4.0)
berkshelf (1.4.5)
atomic (1.1.9)
berkshelf (2.0.5)
activesupport (>= 3.2.0)
addressable
addressable (~> 2.3.4)
buff-shell_out (~> 0.1)
celluloid (>= 0.14.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.12.4)
solve (>= 0.4.2)
minitar (~> 0.5.4)
rbzip2 (~> 0.2.0)
retryable (~> 1.3.3)
ridley (~> 1.2.1)
solve (>= 0.5.0)
thor (~> 0.18.0)
yajl-ruby
buff-extensions (0.5.0)
buff-ruby_engine (0.1.0)
buff-shell_out (0.1.0)
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)
@ -62,7 +70,7 @@ GEM
httparty
net-ssh
ohai
ffi (1.8.1)
ffi (1.9.0)
foodcritic (2.1.0)
erubis
gherkin (~> 2.11.7)
@ -84,7 +92,7 @@ GEM
httpclient (2.2.0.2)
httpi (0.9.7)
rack
i18n (0.6.1)
i18n (0.6.4)
ipaddress (0.8.0)
json (1.7.7)
little-plugger (1.1.3)
@ -93,7 +101,7 @@ GEM
little-plugger (>= 1.1.3)
mime-types (1.23)
minitar (0.5.4)
minitest (4.7.4)
minitest (4.7.5)
minitest-chef-handler (1.0.1)
chef
ci_reporter
@ -104,7 +112,7 @@ GEM
mixlib-config (1.1.2)
mixlib-log (1.6.0)
mixlib-shellout (1.1.0)
multi_json (1.7.6)
multi_json (1.7.7)
multi_xml (0.5.4)
multipart-post (1.2.0)
net-http-persistent (2.8)
@ -114,7 +122,8 @@ GEM
net-ssh-multi (1.1)
net-ssh (>= 2.1.4)
net-ssh-gateway (>= 0.99.0)
nokogiri (1.5.9)
nio4r (0.4.6)
nokogiri (1.5.10)
nori (1.1.5)
ohai (6.16.0)
ipaddress
@ -127,24 +136,26 @@ GEM
polyglot (0.3.3)
rack (1.5.2)
rak (1.4)
rbzip2 (0.2.0)
rest-client (1.6.7)
mime-types (>= 1.16)
retryable (1.3.3)
ridley (0.12.4)
ridley (1.2.3)
addressable
buff-extensions (~> 0.3)
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
retryable
solve (>= 0.4.4)
varia_model (~> 0.1)
winrm (~> 1.1.0)
rspec (2.13.0)
rspec-core (~> 2.13.0)
@ -163,10 +174,9 @@ 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.5.0)
strainer (3.0.3)
berkshelf (~> 2.0)
systemu (2.5.2)
tailor (1.2.1)
log_switch (>= 0.3.0)
@ -176,12 +186,18 @@ GEM
tins (~> 0.8)
text-table (1.2.3)
thor (0.18.1)
thread_safe (0.1.0)
atomic
timers (1.1.0)
tins (0.8.0)
tins (0.8.2)
treetop (1.4.14)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.37)
uuidtools (2.1.4)
varia_model (0.1.0)
buff-extensions (~> 0.1)
hashie (>= 2.0.2)
wasabi (1.0.0)
nokogiri (>= 1.4.0)
winrm (1.1.2)
@ -198,7 +214,7 @@ PLATFORMS
ruby
DEPENDENCIES
berkshelf (~> 1.4.5)
berkshelf (~> 2.0.3)
chef (~> 11.4.4)
chefspec (~> 1.2.0)
foodcritic

View File

@ -16,6 +16,7 @@ The following cookbooks are dependencies:
* database
* mysql
* openstack-common
* postgresql
# Usage #
@ -50,10 +51,10 @@ None
# Attributes #
* `openstack['database']['server_role']` - which role should other nodes search on to find the database service, defaults to 'os-ops-database'
* `openstack['database']['service']` - which service to use, defaults to 'mysql'
* `openstack['database']['platform']['mysql_python_packages']` - platform-specific mysql python packages to install
* `openstack["database"]["server_role"]` - which role should other nodes search on to find the database service, defaults to 'os-ops-database'
* `openstack["database"]["service_type"]` - which service to use, defaults to 'mysql'
* `openstack["database"]["bind_interface"]` - bind to interfaces IPv4 address
* `openstack["database"]["platform"]["mysql_python_packages"]` - platform-specific mysql python packages to install
Testing
=====
@ -83,9 +84,11 @@ License and Author
| **Author** | Matt Thompson (<matt.thompson@rackspace.co.uk>) |
| **Author** | Matt Ray (<matt@opscode.com>) |
| **Author** | Sean Gallagher (<sean.gallagher@.att.com>) |
| **Author** | John Dewey (<jdewey@att.com>) |
| | |
| **Copyright** | Copyright (c) 2012-2013, Rackspace US, Inc. |
| **Copyright** | Copyright (c) 2012-2013, Opscode, Inc. |
| **Copyright** | Copyright (c) 2013, AT&T Services, Inc. |
Licensed under the Apache License, Version 2.0 (the "License");

View File

@ -1,11 +1,30 @@
default['openstack']['database']['server_role'] = 'os-ops-database'
#
# Cookbook Name:: openstack-ops-database
# Recipe:: default
#
# Copyright 2013, AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
default['openstack']['database']['service'] = 'mysql'
default["openstack"]["database"]["server_role"] = "os-ops-database"
default["openstack"]["database"]["service_type"] = "mysql"
default["openstack"]["database"]["bind_interface"] = "lo"
# platform defaults
# Platform defaults
case platform
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' ]
when "fedora", "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" ]
end

View File

@ -10,10 +10,11 @@ recipe "server", "Installs and configures server packages for the database used
recipe "mysql-client", "Installs MySQL client packages."
recipe "mysql-server", "Installs and configured MySQL server packages."
%w{ ubuntu redhat centos }.each do |os|
%w{ fedora ubuntu redhat centos }.each do |os|
supports os
end
depends "database", ">= 1.4"
depends "mysql", ">= 3.0.0"
depends "openstack-common", "~> 0.3.0"
depends "postgresql", ">= 3.0.0"

View File

@ -3,12 +3,13 @@
# Recipe:: client
#
# Copyright 2013, Opscode, Inc.
# Copyright 2013, AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@ -17,4 +18,4 @@
# limitations under the License.
#
include_recipe "openstack-ops-database::#{node['openstack']['database']['service']}-client"
include_recipe "openstack-ops-database::#{node["openstack"]["database"]["service_type"]}-client"

View File

@ -3,6 +3,7 @@
# Recipe:: mysql-client
#
# Copyright 2013, Opscode, Inc.
# Copyright 2013, AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -20,6 +21,6 @@
include_recipe "mysql::ruby"
include_recipe "mysql::client"
node['openstack']['database']['platform']['mysql_python_packages'].each do |pkg|
node["openstack"]["database"]["platform"]["mysql_python_packages"].each do |pkg|
package pkg
end

View File

@ -4,6 +4,7 @@
#
# Copyright 2013, Opscode, Inc.
# Copyright 2012-2013, Rackspace US, Inc.
# Copyright 2013, AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -18,43 +19,42 @@
# limitations under the License.
#
# override default attributes in the upstream mysql cookbook
node.set["mysql"]["bind_address"] = bind_ip = "0.0.0.0"
node.set['mysql']['tunable']['innodb_thread_concurrency'] = "0"
node.set['mysql']['tunable']['innodb_commit_concurrency'] = "0"
node.set['mysql']['tunable']['innodb_read_io_threads'] = "4"
node.set['mysql']['tunable']['innodb_flush_log_at_trx_commit'] = "2"
listen_address = address_for node["openstack"]["database"]["bind_interface"]
node.override["mysql"]["bind_address"] = listen_address
node.override["mysql"]["tunable"]["innodb_thread_concurrency"] = "0"
node.override["mysql"]["tunable"]["innodb_commit_concurrency"] = "0"
node.override["mysql"]["tunable"]["innodb_read_io_threads"] = "4"
node.override["mysql"]["tunable"]["innodb_flush_log_at_trx_commit"] = "2"
include_recipe "openstack-ops-database::mysql-client"
include_recipe "mysql::server"
mysql_connection_info = {:host => "localhost",
:username => 'root',
:password => node['mysql']['server_root_password']}
mysql_connection_info = {
:host => "localhost",
:username => "root",
:password => node["mysql"]["server_root_password"]
}
# removing insecure default mysql users
mysql_database_user 'drop empty localhost user' do
username ''
host 'localhost'
mysql_database_user "drop empty localhost user" do
username ""
host "localhost"
connection mysql_connection_info
action :drop
end
# removing insecure default mysql users
mysql_database_user 'drop empty hostname user' do
username ''
host node['hostname']
mysql_database_user "drop empty hostname user" do
username ""
host node["hostname"]
connection mysql_connection_info
action :drop
end
# drop the test database
mysql_database 'test' do
mysql_database "test" do
connection mysql_connection_info
action :drop
end
# flush the privileges
mysql_database "FLUSH privileges" do
connection mysql_connection_info
sql "FLUSH privileges"

View File

@ -3,6 +3,7 @@
# Recipe:: server
#
# Copyright 2013, Opscode, Inc.
# Copyright 2013, AT&T Services, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -17,4 +18,4 @@
# limitations under the License.
#
include_recipe "openstack-ops-database::#{node['openstack']['database']['service']}-server"
include_recipe "openstack-ops-database::#{node["openstack"]["database"]["service_type"]}-server"

View File

@ -1,19 +1,14 @@
require_relative 'spec_helper'
require_relative "spec_helper"
describe 'openstack-ops-database::client' do
describe 'ubuntu' do
describe "openstack-ops-database::client" do
before { ops_database_stubs }
describe "ubuntu" do
it "uses proper database client recipe" do
chef_run = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
chef_run.converge "openstack-ops-database::client"
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,23 +1,20 @@
require_relative 'spec_helper'
require_relative "spec_helper"
describe 'openstack-ops-database::mysql-client' do
describe 'ubuntu' do
describe "openstack-ops-database::mysql-client" do
before { ops_database_stubs }
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 = ::ChefSpec::ChefRunner.new ::UBUNTU_OPTS
@chef_run.converge "openstack-ops-database::mysql-client"
end
it "mysql-client recipe tests" do
it "includes mysql recipes" 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
it "installs mysql packages" do
expect(@chef_run).to install_package "python-mysqldb"
end
end
end

View File

@ -1,30 +1,97 @@
require_relative 'spec_helper'
require_relative "spec_helper"
describe 'openstack-ops-database::mysql-server' do
describe 'ubuntu' do
describe "openstack-ops-database::mysql-server" do
before { ops_database_stubs }
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'
}
@chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n|
n.set["mysql"] = {
"server_debian_password" => "server-debian-password",
"server_root_password" => "server-root-password",
"server_repl_password" => "server-repl-password"
}
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"
it "overrides default mysql attributes" do
expect(@chef_run.node["mysql"]["bind_address"]).to eql "127.0.0.1"
expect(@chef_run.node['mysql']['tunable']['innodb_thread_concurrency']).to eql "0"
expect(@chef_run.node['mysql']['tunable']['innodb_commit_concurrency']).to eql "0"
expect(@chef_run.node['mysql']['tunable']['innodb_read_io_threads']).to eql "4"
expect(@chef_run.node['mysql']['tunable']['innodb_flush_log_at_trx_commit']).to eql "2"
end
it "includes mysql recipes" do
expect(@chef_run).to include_recipe "openstack-ops-database::mysql-client"
expect(@chef_run).to include_recipe "mysql::server"
end
describe "lwrps" do
before do
@connection = {
:host => "localhost",
:username => "root",
:password => "server-root-password"
}
end
it "removes insecure default localhost mysql users" do
resource = @chef_run.find_resource(
"mysql_database_user",
"drop empty localhost user"
).to_hash
expect(resource).to include(
:username => "",
:host => "localhost",
:connection => @connection,
:action => [:drop]
)
end
it "removes insecure default hostname mysql users" do
resource = @chef_run.find_resource(
"mysql_database_user",
"drop empty hostname user"
).to_hash
expect(resource).to include(
:username => "",
:host => "Fauxhai",
:connection => @connection,
:action => [:drop]
)
end
it "drops the test database" do
resource = @chef_run.find_resource(
"mysql_database",
"test"
).to_hash
expect(resource).to include(
:connection => @connection,
:action => [:drop]
)
end
it "flushes privileges" do
resource = @chef_run.find_resource(
"mysql_database",
"FLUSH privileges"
).to_hash
expect(resource).to include(
:connection => @connection,
:sql => "FLUSH privileges",
:action => [:nothing]
)
end
it "flush privileges subscribes to 'mysql_database[test]', :query" do
pending "How to test subscribes"
end
end
end
end

View File

@ -1,24 +1,20 @@
require_relative 'spec_helper'
require_relative "spec_helper"
describe 'openstack-ops-database::server' do
describe 'ubuntu' do
describe "openstack-ops-database::server" do
before { ops_database_stubs }
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'
}
it "uses proper database server recipe" do
chef_run = ::ChefSpec::ChefRunner.new(::UBUNTU_OPTS) do |n|
n.set["mysql"] = {
"server_debian_password" => "server-debian-password",
"server_root_password" => "server-root-password",
"server_repl_password" => "server-repl-password"
}
end
chef_run.converge 'openstack-ops-database::server'
chef_run.converge "openstack-ops-database::server"
expect(chef_run).to include_recipe "openstack-ops-database::mysql-server"
end
end
end

View File

@ -11,3 +11,9 @@ require "chefspec"
:version => "12.04",
:log_level => ::LOG_LEVEL
}
def ops_database_stubs
::Chef::Recipe.any_instance.stub(:address_for).
with("lo").
and_return "127.0.0.1"
end