Skip to content

[MODULES-3441] Discover mysql version using facts #852

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 1 commit into from
Jun 15, 2016
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ host=localhost
password=secret
```

This module uses the `mysqld_version` fact to discover the server version being used. By default, this is set to the output of `mysqld -V`. If you're working with a remote MySQL server, you may need to set a custom fact for `mysqld_version` to ensure correct behaviour.

When working with a remote server, do *not* use the `mysql::server` class in your Puppet manifests.

### Specify passwords
Expand Down
5 changes: 5 additions & 0 deletions lib/facter/mysqld_version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Facter.add("mysqld_version") do
setcode do
Facter::Util::Resolution.exec('mysqld -V')
Copy link

Choose a reason for hiding this comment

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

Does this one not need the .compact method chained on it, like it used to do on the provider?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the .compact is superfluous. It'd remove nil elements from a list. In the provider, the call to .compact is run against an anonymous, single-item list, where it will have no effect.

Copy link

Choose a reason for hiding this comment

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

💯

end
end
2 changes: 1 addition & 1 deletion lib/puppet/provider/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def mysqld_type
def self.mysqld_version_string
# we cache the result ...
return @mysqld_version_string unless @mysqld_version_string.nil?
@mysqld_version_string = mysqld(['-V'].compact)
@mysqld_version_string = Facter.value(:mysqld_version)
return @mysqld_version_string
end

Expand Down
20 changes: 20 additions & 0 deletions spec/unit/facter/mysqld_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 "mysqld_version" do
context 'with value' do
before :each do
Facter::Util::Resolution.stubs(:exec).with('mysqld -V').returns('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
end
it {
expect(Facter.fact(:mysqld_version).value).to eq('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
}
end

end

end
11 changes: 8 additions & 3 deletions spec/unit/puppet/provider/mysql_user/mysql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,15 @@
end

describe 'self.mysqld_version' do
it 'queries mysql if unset' do
it 'uses the mysqld_version fact if unset' do
provider.class.instance_variable_set(:@mysqld_version_string, nil)
provider.class.expects(:mysqld).with(['-V'])
expect(provider.mysqld_version).to be_nil
Facter.stubs(:value).with(:mysqld_version).returns('5.6.24')
expect(provider.mysqld_version).to eq '5.6.24'
end
it 'returns nil if the mysqld_version fact is absent' do
provider.class.instance_variable_set(:@mysqld_version_string, nil)
Facter.stubs(:value).with(:mysqld_version).returns(nil)
expect(provider.mysqld_version).to eq nil
end
it 'returns 5.7.6 for "mysqld Ver 5.7.6 for Linux on x86_64 (MySQL Community Server (GPL))"' do
provider.class.instance_variable_set(:@mysqld_version_string, 'mysqld Ver 5.7.6 for Linux on x86_64 (MySQL Community Server (GPL))')
Expand Down