Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect F5 Big-IPs as platform bigip #1035

Merged
merged 2 commits into from
Jul 19, 2017
Merged
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
18 changes: 17 additions & 1 deletion lib/ohai/plugins/linux/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ def cumulus_version
nil
end

#
# Determines the platform version for F5 Big-IP systems
#
# @returns [String] bigip Linux version from /etc/f5-release
#
def bigip_version
release_contents = File.read("/etc/f5-release")
release_contents.match(/BIG-IP release (\S*)/)[1] # http://rubular.com/r/O8nlrBVqSb
rescue NoMethodError, Errno::ENOENT, Errno::EACCES # rescue regex failure, file missing, or permission denied
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An explanation since it took me a moment: The NoMethodError catches the regex failure because String#match returns nil if there was no match and [] isn't a method on nil.

Ohai::Log.warn("Detected F5 Big-IP, but /etc/f5-release could not be parsed to determine platform_version")
nil
end

#
# Determines the platform version for Debian based systems
#
Expand All @@ -107,7 +120,7 @@ def determine_platform_family
case platform
when /debian/, /ubuntu/, /linuxmint/, /raspbian/, /cumulus/
"debian"
when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
when /oracle/, /centos/, /redhat/, /scientific/, /enterpriseenterprise/, /xenserver/, /cloudlinux/, /ibm_powerkvm/, /parallels/, /nexus_centos/, /clearos/, /bigip/ # Note that 'enterpriseenterprise' is oracle's LSB "distributor ID"
"rhel"
when /amazon/
"amazon"
Expand Down Expand Up @@ -142,6 +155,9 @@ def determine_platform_family
contents = File.read("/etc/enterprise-release").chomp
platform "oracle"
platform_version get_redhatish_version(contents)
elsif File.exist?("/etc/f5-release")
platform "bigip"
platform_version bigip_version
elsif File.exist?("/etc/debian_version")
# Ubuntu and Debian both have /etc/debian_version
# Ubuntu should always have a working lsb, debian does not by default
Expand Down
19 changes: 19 additions & 0 deletions spec/unit/plugins/linux/platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
let(:have_os_release) { false }
let(:have_usr_lib_os_release) { false }
let(:have_cisco_release) { false }
let(:have_f5_release) { false }
let(:have_cumulus_dir) { false }

before(:each) do
Expand All @@ -58,6 +59,7 @@
allow(File).to receive(:exist?).with("/etc/parallels-release").and_return(have_parallels_release)
allow(File).to receive(:exist?).with("/usr/bin/raspi-config").and_return(have_raspi_config)
allow(File).to receive(:exist?).with("/etc/os-release").and_return(have_os_release)
allow(File).to receive(:exist?).with("/etc/f5-release").and_return(have_f5_release)
allow(File).to receive(:exist?).with("/usr/lib/os-release").and_return(have_usr_lib_os_release)
allow(File).to receive(:exist?).with("/etc/shared/os-release").and_return(have_cisco_release)
allow(Dir).to receive(:exist?).with("/etc/cumulus").and_return(have_cumulus_dir)
Expand Down Expand Up @@ -309,6 +311,23 @@
end
end

describe "on f5 big-ip" do

let(:have_f5_release) { true }

before(:each) do
@plugin.lsb = nil
end

it "should set platform to bigip" do
expect(File).to receive(:read).with("/etc/f5-release").and_return("BIG-IP release 13.0.0 (Final)")
@plugin.run
expect(@plugin[:platform]).to eq("bigip")
expect(@plugin[:platform_family]).to eq("rhel")
expect(@plugin[:platform_version]).to eq("13.0.0")
end
end

describe "on exherbo" do

let(:have_exherbo_release) { true }
Expand Down