Merge pull request #852 from jtopper/use_fact_for_mysqld_version
[MODULES-3441] Discover mysql version using facts
This commit is contained in:
commit
86a51fd5bf
5 changed files with 36 additions and 4 deletions
|
@ -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
|
||||
|
|
5
lib/facter/mysqld_version.rb
Normal file
5
lib/facter/mysqld_version.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
Facter.add("mysqld_version") do
|
||||
setcode do
|
||||
Facter::Util::Resolution.exec('mysqld -V')
|
||||
end
|
||||
end
|
|
@ -33,7 +33,7 @@ class Puppet::Provider::Mysql < Puppet::Provider
|
|||
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
|
||||
|
||||
|
|
20
spec/unit/facter/mysqld_version_spec.rb
Normal file
20
spec/unit/facter/mysqld_version_spec.rb
Normal file
|
@ -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
|
|
@ -200,10 +200,15 @@ usvn_user@localhost
|
|||
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))')
|
||||
|
|
Loading…
Reference in a new issue