Skip to content

Commit 0305561

Browse files
committed
Merge pull request #708 from cyberious/master
(fix) - Check for mysql_verison before assuming that triggers are a valid permission
2 parents dd129d5 + 8b1fa24 commit 0305561

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,11 @@ The library file name.
784784

785785
###Facts
786786

787-
####`mysql_server_id`
787+
#### `mysql_version`
788+
789+
Determines the MySql version by parsing the output from `mysql --version`
790+
791+
#### `mysql_server_id`
788792

789793
Generates a unique id, based on the node's MAC address, which can be used as
790794
`server_id`. This fact will *always* return `0` on all nodes which only have

lib/facter/mysql_version.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Facter.add("mysql_version") do
2+
setcode do
3+
mysql_ver = Facter::Util::Resolution.exec('mysql --version')
4+
if mysql_ver
5+
mysql_ver.match(/\d+\.\d+\.\d+/)[0]
6+
end
7+
end
8+
end

manifests/backup/mysqldump.pp

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
require => Class['mysql::server::root_password'],
2727
}
2828

29-
30-
if $include_triggers {
29+
if $include_triggers and versioncmp($::mysql_version, '5.1.5') > 0 {
3130
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER' ]
3231
} else {
3332
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ]

spec/classes/mysql_server_backup_spec.rb

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
55
pe_platforms.each do |pe_platform,facts|
66
describe "on #{pe_version} #{pe_platform}" do
7-
let(:facts) { facts }
7+
let(:facts) { {'mysql_version' => '5.1.6'}.merge(facts) }
88

99
let(:default_params) {
1010
{ 'backupuser' => 'testuser',
@@ -26,7 +26,12 @@
2626
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
2727
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER']
2828
).that_requires('Mysql_user[testuser@localhost]') }
29-
29+
context 'mysql < 5.1.6' do
30+
let(:facts) { {'mysql_version' => '5.0.95'}.merge(facts) }
31+
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
32+
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS']
33+
).that_requires('Mysql_user[testuser@localhost]') }
34+
end
3035
context 'with triggers excluded' do
3136
let(:params) do
3237
{ :include_triggers => false }.merge(default_params)
@@ -275,6 +280,15 @@
275280
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
276281
)
277282
end
283+
describe 'mysql_version < 5.0.11' do
284+
let(:facts) { facts.merge({'mysql_version' => '5.0.10'}) }
285+
it 'should backup triggers when asked' do
286+
is_expected.to contain_file('mysqlbackup.sh').with_content(
287+
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
288+
)
289+
end
290+
end
291+
278292
end
279293

280294
context 'with include_triggers set to false' do
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
describe "mysql_version" do
9+
context 'with value' do
10+
before :each do
11+
Facter::Util::Resolution.stubs(:exec).with('mysql --version').returns('mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1')
12+
end
13+
it {
14+
expect(Facter.fact(:mysql_version).value).to eq('5.0.95')
15+
}
16+
end
17+
18+
end
19+
20+
end

0 commit comments

Comments
 (0)