Last active
August 29, 2015 14:09
-
-
Save ftnk/5db6762ab6da8769062e to your computer and use it in GitHub Desktop.
Serverspec sample - MySQL my.cnf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
=begin | |
とある技術ブログを読んで、いろいろと気になったので書いてみた | |
properties はこんな感じ。 | |
:mysql: | |
:version: 5.6 | |
:config: | |
:groups: | |
- client | |
- mysql | |
- mysqld | |
- mysqldump | |
- myisamchk | |
- mysqld_safe | |
mysqld: | |
bind-address: 127.0.0.1 | |
port: 3306 | |
character_set_server: utf8 | |
default_storage_engine: InnoDB | |
innodb_buffer_pool_size: 128M | |
mysqld_safe: | |
open-files-limit: 8192 | |
properties を使いまわして、 | |
次のような感じで server 側で設定を確認することもできる。 | |
describe command('mysql -NBe "SHOW VARIABLES"') do | |
property[:mysql][:config]['mysqld'].each do |opt_name, value| | |
if /\A(\d+)([TGMK])\z/ =~ value.to_s | |
num = $1 | |
unit = $2 | |
case unit | |
when 'K' | |
value = num.to_i * 1024 | |
when 'M' | |
value = num.to_i * 1024 * 1024 | |
when 'G' | |
value = num.to_i * 1024 * 1024 * 1024 | |
when 'T' | |
value = num.to_i * 1024 * 1024 * 1024 * 1024 | |
end | |
end | |
its(:stdout) { should match(/^#{opt_name.gsub(/\-/, '_')}\s+#{value}$/) } | |
end | |
end | |
=end | |
require 'spec_helper' | |
if os[:family] == 'solaris' | |
if property[:mysql][:version] | |
mycnf = "/etc/mysql/#{property[:mysql][:version]}/my.cnf" | |
describe file('/etc/mysql/my.cnf') do | |
it { should be_linked_to mycnf } | |
end | |
else | |
STDERR.puts "preperty[:mysql][:version] is required." | |
end | |
else | |
mycnf = '/etc/my.cnf' | |
end | |
describe file(mycnf) do | |
it { should be_file } | |
groups = property[:mysql][:config][:groups].map{ |i| "^\\[#{i}\\]" } | |
groups_reg = /\A#{groups.join('[^\[\]]+')}[^\[\]]+\z/m | |
its(:content) { should match groups_reg } | |
property[:mysql][:config][:groups].each_with_index do |group, index| | |
target_group = "\\[#{group}\\]" | |
if property[:mysql][:config][:groups].last == group | |
next_group = '\z' | |
else | |
next_group = "\\[#{property[:mysql][:config][:groups][index + 1]}\\]" | |
end | |
if property[:mysql][:config][group] | |
property[:mysql][:config][group].each do |opt_name, value| | |
its(:content) { should match(/^#{target_group}$[^\[\]]*^#{opt_name}\s+=\s+#{value}$[^\[\]]*#{next_group}/m) } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment