20
.gitignore
vendored
20
.gitignore
vendored
@@ -1,9 +1,25 @@
|
||||
# IDEs
|
||||
.idea
|
||||
.settings
|
||||
.project
|
||||
|
||||
# ISO
|
||||
iso/local_mirror
|
||||
iso/build
|
||||
|
||||
# Python
|
||||
*.pyc
|
||||
|
||||
# Doc
|
||||
_build
|
||||
metadata.json
|
||||
.project
|
||||
|
||||
# Editors
|
||||
*.swp
|
||||
*~
|
||||
|
||||
# Vagrant
|
||||
.vagrant
|
||||
Vagrantfile
|
||||
|
||||
metadata.json
|
||||
Gemfile.lock
|
||||
|
||||
3
deployment/puppet/mysql/.rspec
Normal file
3
deployment/puppet/mysql/.rspec
Normal file
@@ -0,0 +1,3 @@
|
||||
--format doc
|
||||
--colour
|
||||
--backtrace
|
||||
@@ -0,0 +1,24 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe command('mysql --user=myuser --password=mypassword --host=localhost -e "show grants"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'myuser'@'localhost'/ }
|
||||
end
|
||||
|
||||
describe file('/usr/local/sbin/mysqlbackup.sh') do
|
||||
it { should be_file }
|
||||
it { should be_mode 700 }
|
||||
it { should be_owned_by 'root' }
|
||||
it { should be_grouped_into 'root' }
|
||||
end
|
||||
|
||||
describe file('/tmp/backups') do
|
||||
it { should be_directory }
|
||||
it { should be_mode 700 }
|
||||
it { should be_owned_by 'root' }
|
||||
it { should be_grouped_into 'root' }
|
||||
end
|
||||
|
||||
describe cron do
|
||||
it { should have_entry('5 23 * * * /usr/local/sbin/mysqlbackup.sh').with_user('root') }
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
$mysql_client_package = case attr[:osfamily]
|
||||
when 'Debian' then 'mysql-client'
|
||||
when 'RedHat' then 'MySQL-client'
|
||||
else 'mysql-client'
|
||||
end
|
||||
|
||||
describe package($mysql_client_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
$mysql_java_package = case attr[:osfamily]
|
||||
when 'Debian' then 'libmysql-java'
|
||||
when 'RedHat' then 'mysql-connector-java'
|
||||
else 'mysql-connector-java'
|
||||
end
|
||||
|
||||
describe package($mysql_java_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
$mysql_python_package = case attr[:osfamily]
|
||||
when 'Debian' then 'python-mysqldb'
|
||||
when 'RedHat' then 'MySQL-python'
|
||||
else 'mysql-python'
|
||||
end
|
||||
|
||||
describe package($mysql_python_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
describe command('ruby -e "require \'rubygems\'; require \'mysql\';"') do
|
||||
it { should return_exit_status 0 }
|
||||
end
|
||||
@@ -0,0 +1,65 @@
|
||||
require File.expand_path('../../spec_helper', __FILE__)
|
||||
|
||||
$mysql_server_package = case attr[:osfamily]
|
||||
when 'Debian' then 'mysql-server'
|
||||
when 'RedHat' then 'MySQL-server'
|
||||
else 'mysql-server'
|
||||
end
|
||||
|
||||
$mysql_server_service = case attr[:osfamily]
|
||||
when 'Debian' then 'mysql'
|
||||
when 'RedHat' then 'mysql'
|
||||
else 'mysql'
|
||||
end
|
||||
|
||||
describe package($mysql_server_package) do
|
||||
it { should be_installed }
|
||||
end
|
||||
|
||||
describe service($mysql_server_service) do
|
||||
it { should be_running }
|
||||
it { should be_enabled }
|
||||
end
|
||||
|
||||
describe file('/root/.my.cnf') do
|
||||
it { should be_file }
|
||||
it { should contain '[client]' }
|
||||
it { should contain 'user=root' }
|
||||
it { should contain 'host=localhost' }
|
||||
it { should contain 'password=password' }
|
||||
end
|
||||
|
||||
describe command('mysql -B -e "show create database redmine_db"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /CHARACTER SET utf8/ }
|
||||
end
|
||||
|
||||
describe command('mysql -B -e "show create database other_db"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /CHARACTER SET utf8/ }
|
||||
end
|
||||
|
||||
describe command('mysql -B -e "show create database old_db"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /CHARACTER SET latin1/ }
|
||||
end
|
||||
|
||||
describe command('mysql --user=dan --password=blah --host=localhost -e "show grants"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /GRANT ALL PRIVILEGES ON `other_db`.* TO 'dan'@'localhost' WITH GRANT OPTION/ }
|
||||
end
|
||||
|
||||
describe command('mysql --user=redmine --password=redmine --host=localhost -e "show grants"') do
|
||||
it { should return_exit_status 0 }
|
||||
it { should return_stdout /GRANT ALL PRIVILEGES ON `redmine_db`.* TO 'redmine'@'localhost' WITH GRANT OPTION/ }
|
||||
end
|
||||
|
||||
describe command('mysql -B -e "show create database test"') do
|
||||
it { should_not return_exit_status 0 }
|
||||
end
|
||||
|
||||
describe command('mysql -e "show grants for \'\'@\'localhost\'"') do
|
||||
it { should_not return_exit_status 0 }
|
||||
it { should_not return_stdout /GRANT USAGE ON/ }
|
||||
end
|
||||
|
||||
34
deployment/puppet/mysql/spec/integration/spec_helper.rb
Normal file
34
deployment/puppet/mysql/spec/integration/spec_helper.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
require 'rubygems'
|
||||
require 'serverspec'
|
||||
require 'pathname'
|
||||
require 'facter'
|
||||
require 'puppet'
|
||||
|
||||
include Serverspec::Helper::Exec
|
||||
include Serverspec::Helper::DetectOS
|
||||
|
||||
Puppet.parse_config
|
||||
|
||||
if Puppet[:libdir] && !Facter.search_path.include?(Puppet[:libdir])
|
||||
Facter.search(Puppet[:libdir])
|
||||
end
|
||||
|
||||
facts = {}
|
||||
Facter.list.each do |fact|
|
||||
facts[fact] = Facter.value(fact) || ''
|
||||
end
|
||||
|
||||
Facter.list.map { |fact| [fact, Facter.value(fact) || ''].flatten }
|
||||
|
||||
RSpec.configure do |c|
|
||||
if ENV['ASK_SUDO_PASSWORD']
|
||||
require 'highline/import'
|
||||
c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
|
||||
else
|
||||
c.sudo_password = ENV['SUDO_PASSWORD']
|
||||
end
|
||||
attr_set facts
|
||||
c.before :all do
|
||||
ENV['LANG'] = 'C'
|
||||
end
|
||||
end
|
||||
@@ -1,6 +0,0 @@
|
||||
--format
|
||||
s
|
||||
--colour
|
||||
--loadby
|
||||
mtime
|
||||
--backtrace
|
||||
71
deployment/puppet/mysql/tests/Rakefile
Normal file
71
deployment/puppet/mysql/tests/Rakefile
Normal file
@@ -0,0 +1,71 @@
|
||||
require 'find'
|
||||
|
||||
TESTS_DIR = File.dirname(File.expand_path(__FILE__))
|
||||
SPEC_DIR = File.expand_path(TESTS_DIR + '/../spec/integration')
|
||||
if ENV['puppet_debug']
|
||||
PUPPET_OPTIONS = "--detailed-exitcodes --verbose --debug --trace --evaltrace"
|
||||
else
|
||||
PUPPET_OPTIONS = "--detailed-exitcodes"
|
||||
end
|
||||
RSPEC_OPTIONS = "--color -f doc"
|
||||
|
||||
def puppet(manifest_file)
|
||||
fail "No such manifest '#{manifest_file}'!" unless File.exist?(manifest_file)
|
||||
sh "puppet apply #{PUPPET_OPTIONS} '#{manifest_file}'" do |ok, res|
|
||||
fail "Apply of manifest '#{manifest_file}' failed with exit code #{res.exitstatus}!" unless [0,2].include?(res.exitstatus)
|
||||
end
|
||||
end
|
||||
|
||||
def rspec(test_name)
|
||||
rspec_file = "#{SPEC_DIR}/default/#{test_name}_spec.rb"
|
||||
rspec_file = "#{SPEC_DIR}/#{test_name}_spec.rb" unless File.exists?(rspec_file)
|
||||
if File.exists?(rspec_file)
|
||||
Dir.chdir(SPEC_DIR) || fail("Can't cd to #{SPEC_DIR}!")
|
||||
sh "rspec #{RSPEC_OPTIONS} '#{rspec_file}'" do |ok, res|
|
||||
fail("Test #{test_name} failed with exit code #{res.exitstatus}!") unless ok
|
||||
end
|
||||
else
|
||||
puts "Spec file for test '#{test_name}' doesn't exist! Skipping test phase."
|
||||
end
|
||||
end
|
||||
|
||||
Dir.chdir(TESTS_DIR) || exit(1)
|
||||
|
||||
all_tasks = []
|
||||
Find.find('.') do |path|
|
||||
next unless File.file?(path)
|
||||
next unless path.end_with?('.pp')
|
||||
path.sub!('./','')
|
||||
test_name = path.chomp('.pp')
|
||||
namespace test_name do
|
||||
task :run => [ :apply, :test ] do
|
||||
puts "#{test_name} run ends"
|
||||
end
|
||||
task :apply do
|
||||
puppet(path)
|
||||
puts "#{test_name} have been applied!"
|
||||
end
|
||||
task :test do
|
||||
rspec(test_name)
|
||||
puts "#{test_name} have been tested!"
|
||||
end
|
||||
desc "#{test_name} integration test"
|
||||
end
|
||||
task test_name do
|
||||
Rake::Task["#{test_name}:apply"].invoke
|
||||
Rake::Task["#{test_name}:test"].invoke
|
||||
end
|
||||
all_tasks.push(test_name)
|
||||
end
|
||||
|
||||
desc "Run all tests"
|
||||
task :all do
|
||||
all_tasks.each do |test_name|
|
||||
pwd = Dir.pwd
|
||||
Rake::Task["#{test_name}:apply"].invoke
|
||||
Rake::Task["#{test_name}:test"].invoke
|
||||
Dir.chdir(pwd)
|
||||
end
|
||||
end
|
||||
|
||||
task :default => [:all]
|
||||
@@ -1,12 +0,0 @@
|
||||
class { 'mysql::server':
|
||||
config_hash => {'root_password' => 'password'}
|
||||
}
|
||||
database{ ['test1', 'test2', 'test3']:
|
||||
ensure => present,
|
||||
charset => 'utf8',
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
database{ 'test4':
|
||||
ensure => present,
|
||||
charset => 'latin1',
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
database_grant{'test1@localhost/redmine':
|
||||
privileges => [update],
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
$mysql_root_pw = 'password'
|
||||
|
||||
class { 'mysql::server':
|
||||
config_hash => {
|
||||
root_password => 'password',
|
||||
}
|
||||
}
|
||||
|
||||
database_user{ 'redmine@localhost':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('redmine'),
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
database_user{ 'dan@localhost':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('blah')
|
||||
}
|
||||
|
||||
database_user{ 'dan@%':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('blah'),
|
||||
}
|
||||
@@ -1,3 +1,50 @@
|
||||
class { 'openstack::mirantis_repos': }
|
||||
|
||||
class { 'mysql::server':
|
||||
config_hash => { 'root_password' => 'password', },
|
||||
config_hash => {
|
||||
'root_password' => 'password',
|
||||
}
|
||||
}
|
||||
|
||||
class { 'mysql::server::account_security': }
|
||||
|
||||
database{ ['redmine_db', 'other_db']:
|
||||
ensure => present,
|
||||
charset => 'utf8',
|
||||
}
|
||||
|
||||
database{ 'old_db':
|
||||
ensure => present,
|
||||
charset => 'latin1',
|
||||
}
|
||||
|
||||
database_grant{'redmine@localhost/redmine_db':
|
||||
privileges => ['all'],
|
||||
}
|
||||
|
||||
database_grant{'dan@localhost/other_db':
|
||||
privileges => ['all'],
|
||||
}
|
||||
|
||||
database_user{ 'redmine@localhost':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('redmine'),
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
database_user{ 'dan@localhost':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('blah'),
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
database_user{ 'dan@%':
|
||||
ensure => present,
|
||||
password_hash => mysql_password('blah'),
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
|
||||
Class['openstack::mirantis_repos'] -> Class['mysql::server']
|
||||
Class['mysql::server'] -> Database <| |>
|
||||
Class['mysql::server'] -> Database_grant <| |>
|
||||
Class['mysql::server'] -> Database_user <| |>
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
class { 'mysql::server':
|
||||
config_hash => { 'root_password' => 'password', },
|
||||
}
|
||||
class { 'mysql::server::account_security': }
|
||||
Reference in New Issue
Block a user