Skip to content

Commit c5955e9

Browse files
committed
Avoid env command in facter plugin
... because it interferes with the capability of core facter utility to translate command to its full path. Also override of environment variables is not really necessary when 'mysqd' command is found in PATH. Signed-off-by: Takashi Kajinami <[email protected]>
1 parent d230e80 commit c5955e9

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

‎lib/facter/mysqld_version.rb‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
Facter.add('mysqld_version')do
44
setcodedo
5-
ifFacter::Core::Execution.which('mysqld') || Facter::Core::Execution.which('/usr/libexec/mysqld')
6-
Facter::Core::Execution.execute('env PATH=$PATH:/usr/libexec mysqld --no-defaults -V 2>/dev/null')
5+
ifFacter::Core::Execution.which('mysqld')
6+
Facter::Core::Execution.execute('mysqld --no-defaults -V 2>/dev/null')
7+
elsifFacter::Core::Execution.which('/usr/libexec/mysqld')
8+
Facter::Core::Execution.execute('/usr/libexec/mysqld --no-defaults -V 2>/dev/null')
79
elsifFacter::Core::Execution.which('mariadbd')
810
Facter::Core::Execution.execute('mariadbd --no-defaults -V 2>/dev/null')
911
end

‎spec/unit/facter/mysqld_version_spec.rb‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,23 @@
1111
context'with mysqld'do
1212
before:eachdo
1313
allow(Facter::Core::Execution).toreceive(:which).with('mysqld').and_return('/usr/sbin/mysqld')
14+
allow(Facter::Core::Execution).toreceive(:which).with('/usr/libexec/mysqld').and_return(false)
15+
allow(Facter::Core::Execution).toreceive(:which).with('mariadbd').and_return(false)
16+
allow(Facter::Core::Execution).toreceive(:execute).with('mysqld --no-defaults -V 2>/dev/null')
17+
.and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
18+
end
19+
20+
it{
21+
expect(Facter.fact(:mysqld_version).value).toeq('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
22+
}
23+
end
24+
25+
context'with mysqld in /usr/libexec/mysqld'do
26+
before:eachdo
27+
allow(Facter::Core::Execution).toreceive(:which).with('mysqld').and_return(false)
28+
allow(Facter::Core::Execution).toreceive(:which).with('/usr/libexec/mysqld').and_return('/usr/libexec/mysqld')
1429
allow(Facter::Core::Execution).toreceive(:which).with('mariadbd').and_return(false)
15-
allow(Facter::Core::Execution).toreceive(:execute).with('env PATH=$PATH:/usr/libexecmysqld --no-defaults -V 2>/dev/null')
30+
allow(Facter::Core::Execution).toreceive(:execute).with('/usr/libexec/mysqld --no-defaults -V 2>/dev/null')
1631
.and_return('mysqld Ver 5.5.49-37.9 for Linux on x86_64 (Percona Server (GPL), Release 37.9, Revision efa0073)')
1732
end
1833

0 commit comments

Comments
(0)