Skip to content

Commit 3ce8ad3

Browse files
author
Travis Fields
committed
(maint) - Add a fact for capturing the mysql version installed
- Add spec test for mysql_version fact - Add `mysql_version` fact to README
1 parent dd129d5 commit 3ce8ad3

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,11 @@ The library file name.
784784

785785
###Facts
786786

787-
####`mysql_server_id`
787+
#### `mysql_version`
788+
789+
Determines the MySql version by parsing the output from `mysql --version`
790+
791+
#### `mysql_server_id`
788792

789793
Generates a unique id, based on the node's MAC address, which can be used as
790794
`server_id`. This fact will *always* return `0` on all nodes which only have

lib/facter/mysql_version.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Facter.add("mysql_version") do
2+
setcode do
3+
mysql_ver = Facter::Util::Resolution.exec('mysql --version')
4+
if mysql_ver
5+
mysql_ver.match(/\d+\.\d+\.\d+/)[0]
6+
end
7+
end
8+
end
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
require "spec_helper"
2+
3+
describe Facter::Util::Fact do
4+
before {
5+
Facter.clear
6+
}
7+
8+
describe "mysql_version" do
9+
context 'with value' do
10+
before :each do
11+
Facter::Util::Resolution.stubs(:exec).with('mysql --version').returns('mysql Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (x86_64) using readline 5.1')
12+
end
13+
it {
14+
expect(Facter.fact(:mysql_version).value).to eq('5.0.95')
15+
}
16+
end
17+
18+
end
19+
20+
end

0 commit comments

Comments
 (0)