diff --git a/lib/train/extras/os_common.rb b/lib/train/extras/os_common.rb index a82126b2..d3737930 100644 --- a/lib/train/extras/os_common.rb +++ b/lib/train/extras/os_common.rb @@ -22,6 +22,7 @@ class OSCommon include Train::Extras::DetectWindows include Train::Extras::DetectEsx + attr_accessor :backend def initialize(backend, platform = nil) @backend = backend @platform = platform || {} diff --git a/lib/train/extras/os_detect_darwin.rb b/lib/train/extras/os_detect_darwin.rb index 50ff5595..241a10e9 100644 --- a/lib/train/extras/os_detect_darwin.rb +++ b/lib/train/extras/os_detect_darwin.rb @@ -18,6 +18,9 @@ def detect_darwin # TODO: ditto on error return false if cmd.stdout.empty? + uname_m = @backend.run_command("uname -m").stdout.chomp + return false if uname_m.empty? + name = cmd.stdout[/^ProductName:\s+(.+)$/, 1] # TODO: ditto on error return false if name.nil? @@ -26,6 +29,7 @@ def detect_darwin @platform[:build] = cmd.stdout[/^BuildVersion:\s+(.+)$/, 1] # TODO: keep for now due to backwards compatibility with serverspec @platform[:family] = 'darwin' + @platform[:arch] = uname_m true end end diff --git a/lib/train/extras/os_detect_linux.rb b/lib/train/extras/os_detect_linux.rb index 3d5ef461..e1be21e3 100644 --- a/lib/train/extras/os_detect_linux.rb +++ b/lib/train/extras/os_detect_linux.rb @@ -105,17 +105,21 @@ def family_for_platform end def uname_s - @uname_s ||= @backend.run_command('uname -s').stdout + @uname_s ||= backend.run_command('uname -s').stdout end def uname_r @uname_r ||= ( - res = @backend.run_command('uname -r').stdout + res = backend.run_command('uname -r').stdout res.strip! unless res.nil? res ) end + def uname_m + @uname_m ||= backend.run_command('uname -m').stdout.chomp + end + def redhatish_platform(conf) conf[/^red hat/i] ? 'redhat' : conf[/(\w+)/i, 1].downcase end @@ -126,10 +130,20 @@ def redhatish_version(conf) conf[/release ([\d\.]+)/, 1] end + def detect_linux_architecture + if uname_m.nil? || uname_m.empty? + false + else + @platform[:arch] = uname_m + true + end + end + def detect_linux # TODO: print an error in this step of the detection return false if uname_s.nil? || uname_s.empty? return false if uname_r.nil? || uname_r.empty? + return false if !detect_linux_architecture return true if detect_linux_via_config return true if detect_linux_via_lsb diff --git a/test/unit/extras/os_detect_linux_test.rb b/test/unit/extras/os_detect_linux_test.rb index 89b901d5..3397570c 100644 --- a/test/unit/extras/os_detect_linux_test.rb +++ b/test/unit/extras/os_detect_linux_test.rb @@ -14,6 +14,16 @@ def initialize describe 'os_detect_linux' do let(:detector) { OsDetectLinuxTester.new } + describe '#detect_linux_architecture' do + it "sets the arch using uname" do + be = mock("Backend") + detector.stubs(:backend).returns(be) + be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n")) + detector.detect_linux_architecture.must_equal(true) + detector.platform[:arch].must_equal("x84_64") + end + end + describe '#detect_linux_via_config' do before do