diff --git a/lib/facter/mysqld_version.rb b/lib/facter/mysqld_version.rb index 6a383190c..ad28fd5b8 100644 --- a/lib/facter/mysqld_version.rb +++ b/lib/facter/mysqld_version.rb @@ -2,8 +2,10 @@ Facter.add('mysqld_version') do setcode do - if Facter::Core::Execution.which('mysqld') || Facter::Core::Execution.which('/usr/libexec/mysqld') - Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + if Facter::Core::Execution.which('mysqld') + Facter::Core::Execution.execute('mysqld --no-defaults -V 2>/dev/null') + elsif Facter::Core::Execution.which('/usr/libexec/mysqld') + Facter::Core::Execution.execute('/usr/libexec/mysqld --no-defaults -V 2>/dev/null') elsif Facter::Core::Execution.which('mariadbd') Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null') end diff --git a/spec/unit/facter/mysqld_version_spec.rb b/spec/unit/facter/mysqld_version_spec.rb index 6a029d1c2..b69cfd7ef 100644 --- a/spec/unit/facter/mysqld_version_spec.rb +++ b/spec/unit/facter/mysqld_version_spec.rb @@ -11,8 +11,23 @@ context 'with mysqld' do before :each do allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return('/usr/sbin/mysqld') + allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false) + allow(Facter::Core::Execution).to receive(:execute).with('mysqld --no-defaults -V 2>/dev/null') + .and_return('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 + + context 'with mysqld in /usr/libexec/mysqld' do + before :each do + allow(Facter::Core::Execution).to receive(:which).with('mysqld').and_return(false) + allow(Facter::Core::Execution).to receive(:which).with('/usr/libexec/mysqld').and_return('/usr/libexec/mysqld') allow(Facter::Core::Execution).to receive(:which).with('mariadbd').and_return(false) - allow(Facter::Core::Execution).to receive(:execute).with('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null') + allow(Facter::Core::Execution).to receive(:execute).with('/usr/libexec/mysqld --no-defaults -V 2>/dev/null') .and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)') end