From 798e4493d7df801eab4ae4aba4d44c13095cd43d Mon Sep 17 00:00:00 2001 From: Marcel Huth Date: Thu, 8 Feb 2018 11:54:26 +0100 Subject: [PATCH] Support for Brocade FOS devices Signed-off-by: Marcel Huth --- .../platforms/detect/helpers/os_common.rb | 12 ++++++++++ .../platforms/detect/specifications/os.rb | 22 +++++++++++++++++++ test/unit/platforms/os_detect_test.rb | 12 ++++++++++ 3 files changed, 46 insertions(+) diff --git a/lib/train/platforms/detect/helpers/os_common.rb b/lib/train/platforms/detect/helpers/os_common.rb index e4c80d79..aff66899 100644 --- a/lib/train/platforms/detect/helpers/os_common.rb +++ b/lib/train/platforms/detect/helpers/os_common.rb @@ -53,6 +53,18 @@ def unix_uname_m @uname[:m] = command_output('uname -m') end + def brocade_version + return @cache[:brocade] if @cache.key?(:brocade) + res = command_output('version') + + m = res.match(/^Fabric OS:\s+v(\S+)$/) + unless m.nil? + return @cache[:brocade] = { version: m[1], type: 'fos' } + end + + @cache[:brocade] = nil + end + def cisco_show_version return @cache[:cisco] if @cache.key?(:cisco) res = command_output('show version') diff --git a/lib/train/platforms/detect/specifications/os.rb b/lib/train/platforms/detect/specifications/os.rb index cc744893..0d3d04a4 100644 --- a/lib/train/platforms/detect/specifications/os.rb +++ b/lib/train/platforms/detect/specifications/os.rb @@ -288,6 +288,13 @@ def self.load end } + # brocade family detected here if device responds to 'uname' command, + # happens when logging in as root + plat.family('brocade').title('Brocade Family').in_family('linux') + .detect { + !brocade_version.nil? + } + # genaric linux # this should always be last in the linux family list plat.name('linux').title('Genaric Linux').in_family('linux') @@ -537,6 +544,21 @@ def self.load @platform[:arch] = nil true } + + # brocade family + plat.family('brocade').title('Brocade Family').in_family('os') + .detect { + !brocade_version.nil? + } + + plat.name('brocade_fos').title('Brocade FOS').in_family('brocade') + .detect { + v = brocade_version + next unless v[:type] == 'fos' + @platform[:release] = v[:version] + @platform[:arch] = nil + true + } end end end diff --git a/test/unit/platforms/os_detect_test.rb b/test/unit/platforms/os_detect_test.rb index da21a677..dd522fd5 100644 --- a/test/unit/platforms/os_detect_test.rb +++ b/test/unit/platforms/os_detect_test.rb @@ -224,4 +224,16 @@ def debian_scan(id, version) platform[:release].must_equal('5.2') end end + + describe 'brocade' do + it 'recognizes Brocade FOS-based SAN switches' do + mock = Train::Transports::Mock::Connection.new + mock.mock_command('version', "Kernel: 2.6.14.2\nFabric OS: v7.4.2a\nMade on: Thu Jun 29 19:22:14 2017\nFlash: Sat Sep 9 17:30:42 2017\nBootProm: 1.0.11") + platform = Train::Platforms::Detect.scan(mock) + + platform[:name].must_equal('brocade_fos') + platform[:family].must_equal('brocade') + platform[:release].must_equal('7.4.2a') + end + end end