diff --git a/lib/puppet/provider/mysql.rb b/lib/puppet/provider/mysql.rb index 097ee0f..181d788 100644 --- a/lib/puppet/provider/mysql.rb +++ b/lib/puppet/provider/mysql.rb @@ -31,10 +31,8 @@ class Puppet::Provider::Mysql < Puppet::Provider end def self.mysqld_version_string - # we cache the result ... - return @mysqld_version_string unless @mysqld_version_string.nil? - @mysqld_version_string = Facter.value(:mysqld_version) - return @mysqld_version_string + # As the possibility of the mysqld being remote we need to allow the version string to be overridden, this can be done by facter.value as seen below. In the case that it has not been set and the facter value is nil we use the mysql -v command to ensure we report the correct version of mysql for later use cases. + @mysqld_version_string ||= Facter.value(:mysqld_version) || mysqld('-V') end def mysqld_version_string diff --git a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb index d0a25ee..e8c138d 100644 --- a/spec/unit/puppet/provider/mysql_user/mysql_spec.rb +++ b/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -205,11 +205,6 @@ usvn_user@localhost 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))') expect(provider.mysqld_version).to eq '5.7.6'