Skip to content
Open
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: 4 additions & 2 deletions lib/facter/mysqld_version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion spec/unit/facter/mysqld_version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading