Skip to content

(fix) - Check for mysql_verison before assuming that triggers are a valid permission #708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -784,7 +784,11 @@ The library file name.

###Facts

####`mysql_server_id`
#### `mysql_version`

Determines the MySql version by parsing the output from `mysql --version`

#### `mysql_server_id`

Generates a unique id, based on the node's MAC address, which can be used as
`server_id`. This fact will *always* return `0` on all nodes which only have
Expand Down
8 changes: 8 additions & 0 deletions lib/facter/mysql_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Facter.add("mysql_version") do
setcode do
mysql_ver = Facter::Util::Resolution.exec('mysql --version')
if mysql_ver
mysql_ver.match(/\d+\.\d+\.\d+/)[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gives us 10.0.19 for mariadb-client-10.0, and 5.6.24 for mysql-client-core-5.6

i wonder what we can do with that now…

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hrm… how can i access the value of mysql_version fact from the mysql_grant or mysql_user type, and i don't mean in a confine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(asking for a friend, #548)

end
end
end
3 changes: 1 addition & 2 deletions manifests/backup/mysqldump.pp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
require => Class['mysql::server::root_password'],
}


if $include_triggers {
if $include_triggers and versioncmp($::mysql_version, '5.1.5') > 0 {
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER' ]
} else {
$privs = [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS' ]
Expand Down
18 changes: 16 additions & 2 deletions spec/classes/mysql_server_backup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
on_pe_supported_platforms(PLATFORMS).each do |pe_version,pe_platforms|
pe_platforms.each do |pe_platform,facts|
describe "on #{pe_version} #{pe_platform}" do
let(:facts) { facts }
let(:facts) { {'mysql_version' => '5.1.6'}.merge(facts) }

let(:default_params) {
{ 'backupuser' => 'testuser',
Expand All @@ -26,7 +26,12 @@
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS', 'TRIGGER']
).that_requires('Mysql_user[testuser@localhost]') }

context 'mysql < 5.1.6' do
let(:facts) { {'mysql_version' => '5.0.95'}.merge(facts) }
it { is_expected.to contain_mysql_grant('testuser@localhost/*.*').with(
:privileges => ['SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW', 'PROCESS']
).that_requires('Mysql_user[testuser@localhost]') }
end
context 'with triggers excluded' do
let(:params) do
{ :include_triggers => false }.merge(default_params)
Expand Down Expand Up @@ -275,6 +280,15 @@
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
)
end
describe 'mysql_version < 5.0.11' do
let(:facts) { facts.merge({'mysql_version' => '5.0.10'}) }
it 'should backup triggers when asked' do
is_expected.to contain_file('mysqlbackup.sh').with_content(
/ADDITIONAL_OPTIONS="\$ADDITIONAL_OPTIONS --triggers"/
)
end
end

end

context 'with include_triggers set to false' do
Expand Down
20 changes: 20 additions & 0 deletions spec/unit/facter/mysql_version_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require "spec_helper"

describe Facter::Util::Fact do
before {
Facter.clear
}

describe "mysql_version" do
context 'with value' do
before :each do
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')
end
it {
expect(Facter.fact(:mysql_version).value).to eq('5.0.95')
}
end

end

end