summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ray <matthewhray@gmail.com>2015-09-17 14:03:48 -0500
committerMatt Ray <matthewhray@gmail.com>2015-09-17 14:03:48 -0500
commit7b80ddbb760997c6a2ac08aefa2c62206cbc706b (patch)
tree5ad92b7c896f984c30681d2d45f2e13d95a00987
parent46ae1a297ca05ee896cbd181a847d3ded4a254df (diff)
parent7a716b730571cba51f41e8dfe840e40774bdefab (diff)
downloadohai-7b80ddbb760997c6a2ac08aefa2c62206cbc706b.tar.gz
Merge pull request #618 from adamleff/wrlinux7
Adding support for Wind River Linux 7.
-rw-r--r--lib/ohai/plugins/linux/platform.rb15
-rw-r--r--spec/unit/plugins/linux/platform_spec.rb111
2 files changed, 117 insertions, 9 deletions
diff --git a/lib/ohai/plugins/linux/platform.rb b/lib/ohai/plugins/linux/platform.rb
index 40c29b6b..659d69fd 100644
--- a/lib/ohai/plugins/linux/platform.rb
+++ b/lib/ohai/plugins/linux/platform.rb
@@ -143,9 +143,18 @@ Ohai.plugin(:Platform) do
# kernel release will be used - ex. 3.13
platform_version `uname -r`.strip
elsif os_release_file_is_cisco?
- raise "unknown Cisco /etc/os-release ID field" unless os_release_info['ID'].include?('nexus')
- raise "unknown Cisco /etc/os-release ID-LIKE field" unless os_release_info['ID_LIKE'].include?('wrlinux')
- platform 'nexus'
+ raise 'unknown Cisco /etc/os-release or /etc/cisco-release ID_LIKE field' if
+ os_release_info['ID_LIKE'].nil? || ! os_release_info['ID_LIKE'].include?('wrlinux')
+
+ case os_release_info['ID']
+ when 'nexus'
+ platform 'nexus'
+ when 'ios_xr'
+ platform 'ios_xr'
+ else
+ raise 'unknown Cisco /etc/os-release or /etc/cisco-release ID field'
+ end
+
platform_family 'wrlinux'
platform_version os_release_info['VERSION']
elsif lsb[:id] =~ /RedHat/i
diff --git a/spec/unit/plugins/linux/platform_spec.rb b/spec/unit/plugins/linux/platform_spec.rb
index dbd5a431..025ea223 100644
--- a/spec/unit/plugins/linux/platform_spec.rb
+++ b/spec/unit/plugins/linux/platform_spec.rb
@@ -650,17 +650,116 @@ CISCO_RELEASE
end
end
- describe "on Wind River Linux for Cisco Nexus" do
+ describe '#read_os_release_info' do
+ let(:file_contents) { "COW=MOO\nDOG=\"BARK\"" }
+ it 'returns nil if the file does not exist' do
+ allow(File).to receive(:exist?).with('/etc/test-release').and_return(false)
+ expect(@plugin.read_os_release_info('/etc/test-release')).to be nil
+ end
+
+ it 'returns a hash of expected contents' do
+ allow(File).to receive(:exist?).with('/etc/test-release').and_return(true)
+ allow(File).to receive(:read).with('/etc/test-release').and_return(file_contents)
+ release_info = @plugin.read_os_release_info('/etc/test-release')
+
+ expect(release_info['COW']).to eq('MOO')
+ expect(release_info['DOG']).to eq('BARK')
+ end
+ end
+
+ describe '#os_release_info' do
+ context 'when CISCO_RELEASE_INFO is not populated' do
+ let(:release_info) { { 'ID' => 'os_id' } }
+
+ before do
+ allow(File).to receive(:exist?).with('/etc/os-release').and_return(true)
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
+ end
+ it 'reads the os-release file' do
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
+ @plugin.os_release_info
+ end
+
+ it 'returns a hash of expected contents' do
+ expect(@plugin.os_release_info['ID']).to eq('os_id')
+ end
+ end
+
+ context 'when CISCO_RELEASE_INFO is populated' do
+ let(:release_info) { { 'ID' => 'os_id', 'CISCO_RELEASE_INFO' => '/etc/cisco-release' } }
+ let(:cisco_release_info) { { 'ID' => 'cisco_id' } }
+
+ before do
+ allow(File).to receive(:exist?).with('/etc/os-release').and_return(true)
+ allow(File).to receive(:exist?).with('/etc/cisco-release').and_return(true)
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
+ allow(@plugin).to receive(:read_os_release_info).with('/etc/cisco-release').and_return(cisco_release_info)
+ end
+
+ it 'reads the os-release AND the cisco-release file' do
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/os-release').and_return(release_info)
+ expect(@plugin).to receive(:read_os_release_info).with('/etc/cisco-release').and_return(release_info)
+ @plugin.os_release_info
+ end
+
+ it 'returns the ID from the cisco-release file instead of the os-release file' do
+ expect(@plugin.os_release_info['ID']).to eq('cisco_id')
+ end
+ end
+ end
+
+ describe 'on Wind River Linux 5 for Cisco Nexus' do
let(:have_os_release) { true }
+ let(:os_release_info) do
+ {
+ 'ID' => 'nexus',
+ 'ID_LIKE' => 'wrlinux',
+ 'NAME' => 'Nexus',
+ 'VERSION' => '7.0(3)I2(0.475E.6)',
+ 'VERSION_ID' => '7.0(3)I2',
+ 'PRETTY_NAME' => 'Nexus 7.0(3)I2',
+ 'HOME_URL' => 'http://www.cisco.com',
+ 'BUILD_ID' => '6',
+ 'CISCO_RELEASE_INFO' => '/etc/os-release'
+ }
+ end
+
+ it 'should set platform to nexus and platform_family to wrlinux' do
+ allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
+ @plugin.lsb = nil
+ @plugin.run
- it "should set platform to nexus and platform_family to wrlinux" do
+ expect(@plugin[:platform]).to eq('nexus')
+ expect(@plugin[:platform_family]).to eq('wrlinux')
+ expect(@plugin[:platform_version]).to eq('7.0(3)I2(0.475E.6)')
+ end
+ end
+
+ describe 'on Wind River Linux 7 for Cisco IOS-XR' do
+ let(:have_os_release) { true }
+ let(:os_release_info) do
+ {
+ 'ID' => 'ios_xr',
+ 'ID_LIKE' => 'cisco-wrlinux wrlinux',
+ 'NAME' => 'IOS XR',
+ 'VERSION' => '6.0.0.14I',
+ 'VERSION_ID' => '6.0.0.14I',
+ 'PRETTY_NAME' => 'Cisco IOS XR Software, Version 6.0.0.14I',
+ 'BUILD_ID' => '2015-09-10-15-50-17',
+ 'HOME_URL' => 'http://www.cisco.com',
+ 'CISCO_RELEASE_INFO' => '/etc/os-release'
+ }
+ end
+
+ it 'should set platform to ios_xr and platform_family to wrlinux' do
+ allow(@plugin).to receive(:os_release_info).and_return(os_release_info)
@plugin.lsb = nil
- expect(File).to receive(:read).twice.with("/etc/os-release").and_return("ID=nexus\nID_LIKE=wrlinux\nNAME=Nexus\nVERSION=\"7.0(3)I2(0.475E.6)\"\nVERSION_ID=\"7.0(3)I2\"\nPRETTY_NAME=\"Nexus 7.0(3)I2\"\nHOME_URL=http://www.cisco.com\nBUILD_ID=6\nCISCO_RELEASE_INFO=/etc/os-release")
@plugin.run
- expect(@plugin[:platform]).to eq("nexus")
- expect(@plugin[:platform_family]).to eq("wrlinux")
- expect(@plugin[:platform_version]).to eq("7.0(3)I2(0.475E.6)")
+
+ expect(@plugin[:platform]).to eq('ios_xr')
+ expect(@plugin[:platform_family]).to eq('wrlinux')
+ expect(@plugin[:platform_version]).to eq('6.0.0.14I')
end
end
end