train 0.15.1 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 332d26c5b09101df480ed9d2e9498595c92578d1
4
- data.tar.gz: 5d37347588dd7c9d322d95e2d5e85806f93da786
3
+ metadata.gz: 3e2adbc98a3d3527bf063c5656ac331bab4d1581
4
+ data.tar.gz: 64ea8e451841885f39ed1f70b439c69bed0bbb44
5
5
  SHA512:
6
- metadata.gz: 7a9fe54a0ba1b3457086f47021798e50426aa9b70d72bd5476a1bf6260fbb32917e598d1bc600ebb2ac1dfbbd792d1bd3900f0d3ed70f9b832b29a10c80b1823
7
- data.tar.gz: b9ff47d72083a29b300dfe0ff0b5ec1c2059a4b0672fe5490ccf093d47fa44de74cc954129388ce01286221c749871f915ffbbecf648b0a669957d51ea0ba1bc
6
+ metadata.gz: fe7951e7b3f37b58d5e1ee934635ca7ffe8bf8db228bd4a7c37d131c3a05be864204dcfd4d89eda8f60a4a982b1c90f953d750fdb28e8e2f20c33824b9b4e599
7
+ data.tar.gz: b7e24e575dbc3be5b086d9d3abdadcb5d904eec82e78db34b00386849c62dca414db6d3971051138d590f174b408b96ef99328929bfc3ca588453227581ea1a0
@@ -1,7 +1,15 @@
1
1
  # Change Log
2
2
 
3
- ## [0.15.1](https://github.com/chef/train/tree/0.15.1) (2016-07-10)
4
- [Full Changelog](https://github.com/chef/train/compare/v0.15.0...0.15.1)
3
+ ## [0.16.0](https://github.com/chef/train/tree/0.16.0) (2016-08-08)
4
+ [Full Changelog](https://github.com/chef/train/compare/v0.15.1...0.16.0)
5
+
6
+ **Merged pull requests:**
7
+
8
+ - provide file\_version and product\_version for windows files [\#127](https://github.com/chef/train/pull/127) ([chris-rock](https://github.com/chris-rock))
9
+ - Bring train platform data more in line with ohai's platform data [\#126](https://github.com/chef/train/pull/126) ([stevendanna](https://github.com/stevendanna))
10
+
11
+ ## [v0.15.1](https://github.com/chef/train/tree/v0.15.1) (2016-07-11)
12
+ [Full Changelog](https://github.com/chef/train/compare/v0.15.0...v0.15.1)
5
13
 
6
14
  **Fixed bugs:**
7
15
 
@@ -69,11 +69,13 @@ module Train::Extras
69
69
  end
70
70
 
71
71
  def product_version
72
- nil
72
+ @product_version ||= @backend.run_command(
73
+ "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").ProductVersion").stdout.chomp
73
74
  end
74
75
 
75
76
  def file_version
76
- nil
77
+ @file_version ||= @backend.run_command(
78
+ "[System.Diagnostics.FileVersionInfo]::GetVersionInfo(\"#{@spath}\").FileVersion").stdout.chomp
77
79
  end
78
80
 
79
81
  def stat
@@ -22,6 +22,7 @@ module Train::Extras
22
22
  include Train::Extras::DetectWindows
23
23
  include Train::Extras::DetectEsx
24
24
 
25
+ attr_accessor :backend
25
26
  def initialize(backend, platform = nil)
26
27
  @backend = backend
27
28
  @platform = platform || {}
@@ -37,15 +38,10 @@ module Train::Extras
37
38
  end
38
39
 
39
40
  OS = { # rubocop:disable Style/MutableConstant
40
- 'redhat' => %w{
41
- redhat oracle centos fedora amazon scientific xenserver wrlinux
42
- },
43
- 'debian' => %w{
44
- debian ubuntu linuxmint raspbian
45
- },
46
- 'suse' => %w{
47
- suse opensuse
48
- },
41
+ 'redhat' => REDHAT_FAMILY,
42
+ 'debian' => DEBIAN_FAMILY,
43
+ 'suse' => SUSE_FAMILY,
44
+ 'fedora' => %w{fedora},
49
45
  'bsd' => %w{
50
46
  freebsd netbsd openbsd darwin
51
47
  },
@@ -66,7 +62,7 @@ module Train::Extras
66
62
  },
67
63
  }
68
64
 
69
- OS['linux'] = %w{linux alpine arch coreos exherbo gentoo slackware} + OS['redhat'] + OS['debian'] + OS['suse']
65
+ OS['linux'] = %w{linux alpine arch coreos exherbo gentoo slackware fedora amazon} + OS['redhat'] + OS['debian'] + OS['suse']
70
66
 
71
67
  OS['unix'] = %w{unix aix hpux} + OS['linux'] + OS['solaris'] + OS['bsd']
72
68
 
@@ -7,9 +7,12 @@
7
7
  # OHAI https://github.com/chef/ohai
8
8
  # by Adam Jacob, Chef Software Inc
9
9
  #
10
+ require 'train/extras/uname'
10
11
 
11
12
  module Train::Extras
12
13
  module DetectDarwin
14
+ include Train::Extras::Uname
15
+
13
16
  def detect_darwin
14
17
  cmd = @backend.run_command('/usr/bin/sw_vers')
15
18
  # TODO: print an error in this step of the detection,
@@ -26,7 +29,12 @@ module Train::Extras
26
29
  @platform[:build] = cmd.stdout[/^BuildVersion:\s+(.+)$/, 1]
27
30
  # TODO: keep for now due to backwards compatibility with serverspec
28
31
  @platform[:family] = 'darwin'
32
+ detect_darwin_arch
29
33
  true
30
34
  end
35
+
36
+ def detect_darwin_arch
37
+ @platform[:arch] = uname_m
38
+ end
31
39
  end
32
40
  end
@@ -9,96 +9,108 @@
9
9
  #
10
10
 
11
11
  require 'train/extras/linux_lsb'
12
+ require 'train/extras/uname'
12
13
 
13
14
  module Train::Extras
14
15
  module DetectLinux # rubocop:disable Metrics/ModuleLength
16
+ DEBIAN_FAMILY = %w{debian ubuntu linuxmint raspbian}.freeze
17
+ REDHAT_FAMILY = %w{centos redhat oracle scientific enterpriseenterprise xenserver cloudlinux ibm_powerkvm nexus_centos wrlinux}.freeze
18
+ SUSE_FAMILY = %w{suse opensuse}.freeze
19
+
15
20
  include Train::Extras::LinuxLSB
21
+ include Train::Extras::Uname
16
22
 
17
23
  def detect_linux_via_config # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
18
24
  if !(raw = get_config('oracle-release')).nil?
19
- @platform[:family] = 'oracle'
25
+ @platform[:name] = 'oracle'
20
26
  @platform[:release] = redhatish_version(raw)
21
27
  elsif !(raw = get_config('/etc/enterprise-release')).nil?
22
- @platform[:family] = 'oracle'
28
+ @platform[:name] = 'oracle'
23
29
  @platform[:release] = redhatish_version(raw)
24
30
  elsif !(raw = get_config('/etc/debian_version')).nil?
25
31
  case lsb[:id]
26
32
  when /ubuntu/i
27
- @platform[:family] = 'ubuntu'
33
+ @platform[:name] = 'ubuntu'
28
34
  @platform[:release] = lsb[:release]
29
35
  when /linuxmint/i
30
- @platform[:family] = 'linuxmint'
36
+ @platform[:name] = 'linuxmint'
31
37
  @platform[:release] = lsb[:release]
32
38
  else
33
- @platform[:family] = unix_file?('/usr/bin/raspi-config') ? 'raspbian' : 'debian'
39
+ @platform[:name] = unix_file?('/usr/bin/raspi-config') ? 'raspbian' : 'debian'
34
40
  @platform[:release] = raw.chomp
35
41
  end
36
42
  elsif !(raw = get_config('/etc/parallels-release')).nil?
37
- @platform[:family] = redhatish_platform(raw)
43
+ @platform[:name] = redhatish_platform(raw)
38
44
  @platform[:release] = raw[/(\d\.\d\.\d)/, 1]
39
45
  elsif !(raw = get_config('/etc/redhat-release')).nil?
40
46
  # TODO: Cisco
41
47
  # TODO: fully investigate os-release and integrate it;
42
48
  # here we just use it for centos
43
- if !(osrel = get_config('/etc/os-release')).nil? && osrel =~ /centos/i
44
- @platform[:family] = 'centos'
45
- else
46
- @platform[:family] = redhatish_platform(raw)
47
- end
49
+ @platform[:name] = if !(osrel = get_config('/etc/os-release')).nil? && osrel =~ /centos/i
50
+ 'centos'
51
+ else
52
+ redhatish_platform(raw)
53
+ end
54
+
48
55
  @platform[:release] = redhatish_version(raw)
49
56
  elsif !(raw = get_config('/etc/system-release')).nil?
50
57
  # Amazon Linux
51
- @platform[:family] = redhatish_platform(raw)
58
+ @platform[:name] = redhatish_platform(raw)
52
59
  @platform[:release] = redhatish_version(raw)
53
60
  elsif !(suse = get_config('/etc/SuSE-release')).nil?
54
61
  version = suse.scan(/VERSION = (\d+)\nPATCHLEVEL = (\d+)/).flatten.join('.')
55
62
  version = suse[/VERSION = ([\d\.]{2,})/, 1] if version == ''
56
63
  @platform[:release] = version
57
- @platform[:family] = 'suse'
58
- @platform[:family] = 'opensuse' if suse =~ /^openSUSE/
64
+ @platform[:name] = if suse =~ /^openSUSE/
65
+ 'opensuse'
66
+ else
67
+ 'suse'
68
+ end
59
69
  elsif !(raw = get_config('/etc/arch-release')).nil?
60
- @platform[:family] = 'arch'
70
+ @platform[:name] = 'arch'
61
71
  # Because this is a rolling release distribution,
62
72
  # use the kernel release, ex. 4.1.6-1-ARCH
63
73
  @platform[:release] = uname_r
64
74
  elsif !(raw = get_config('/etc/slackware-version')).nil?
65
- @platform[:family] = 'slackware'
75
+ @platform[:name] = 'slackware'
66
76
  @platform[:release] = raw.scan(/(\d+|\.+)/).join
67
77
  elsif !(raw = get_config('/etc/exherbo-release')).nil?
68
- @platform[:family] = 'exherbo'
78
+ @platform[:name] = 'exherbo'
69
79
  # Because this is a rolling release distribution,
70
80
  # use the kernel release, ex. 4.1.6
71
81
  @platform[:release] = uname_r
72
82
  elsif !(raw = get_config('/etc/gentoo-release')).nil?
73
- @platform[:family] = 'gentoo'
83
+ @platform[:name] = 'gentoo'
74
84
  @platform[:release] = raw.scan(/(\d+|\.+)/).join
75
85
  elsif !(raw = get_config('/etc/alpine-release')).nil?
76
- @platform[:family] = 'alpine'
86
+ @platform[:name] = 'alpine'
77
87
  @platform[:release] = raw.strip
78
88
  elsif !(raw = get_config('/etc/coreos/update.conf')).nil?
79
- @platform[:family] = 'coreos'
89
+ @platform[:name] = 'coreos'
80
90
  meta = lsb_config(raw)
81
91
  @platform[:release] = meta[:release]
82
92
  elsif !(os_info = fetch_os_release).nil?
83
93
  if os_info['ID_LIKE'] =~ /wrlinux/
84
- @platform[:family] = 'wrlinux'
94
+ @platform[:name] = 'wrlinux'
85
95
  @platform[:release] = os_info['VERSION']
86
96
  end
87
97
  end
88
98
 
89
- !@platform[:family].nil? && !@platform[:release].nil?
90
- end
99
+ @platform[:family] = family_for_platform
91
100
 
92
- def uname_s
93
- @uname_s ||= @backend.run_command('uname -s').stdout
101
+ !@platform[:family].nil? && !@platform[:release].nil?
94
102
  end
95
103
 
96
- def uname_r
97
- @uname_r ||= (
98
- res = @backend.run_command('uname -r').stdout
99
- res.strip! unless res.nil?
100
- res
101
- )
104
+ def family_for_platform
105
+ if DEBIAN_FAMILY.include?(@platform[:name])
106
+ 'debian'
107
+ elsif REDHAT_FAMILY.include?(@platform[:name])
108
+ 'redhat'
109
+ elsif SUSE_FAMILY.include?(@platform[:name])
110
+ 'suse'
111
+ else
112
+ @platform[:name] || @platform[:family]
113
+ end
102
114
  end
103
115
 
104
116
  def redhatish_platform(conf)
@@ -111,11 +123,16 @@ module Train::Extras
111
123
  conf[/release ([\d\.]+)/, 1]
112
124
  end
113
125
 
126
+ def detect_linux_arch
127
+ @platform[:arch] = uname_m
128
+ end
129
+
114
130
  def detect_linux
115
131
  # TODO: print an error in this step of the detection
116
132
  return false if uname_s.nil? || uname_s.empty?
117
133
  return false if uname_r.nil? || uname_r.empty?
118
134
 
135
+ detect_linux_arch
119
136
  return true if detect_linux_via_config
120
137
  return true if detect_linux_via_lsb
121
138
  # in all other cases we failed the detection
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ # author: Dominik Richter
3
+ # author: Christoph Hartmann
4
+ #
5
+ # This is heavily based on:
6
+ #
7
+ # OHAI https://github.com/chef/ohai
8
+ # by Adam Jacob, Chef Software Inc
9
+ #
10
+ module Train::Extras
11
+ module Uname
12
+ def uname_s
13
+ @uname_s ||= backend.run_command('uname -s').stdout
14
+ end
15
+
16
+ def uname_r
17
+ @uname_r ||= begin
18
+ res = backend.run_command('uname -r').stdout
19
+ res.strip! unless res.nil?
20
+ res
21
+ end
22
+ end
23
+
24
+ def uname_m
25
+ @uname_m ||= backend.run_command('uname -m').stdout.chomp
26
+ end
27
+ end
28
+ end
@@ -3,5 +3,5 @@
3
3
  # Author:: Dominik Richter (<dominik.richter@gmail.com>)
4
4
 
5
5
  module Train
6
- VERSION = '0.15.1'.freeze
6
+ VERSION = '0.16.0'.freeze
7
7
  end
@@ -57,7 +57,18 @@ describe 'os common plugin' do
57
57
 
58
58
  describe 'with platform set to fedora' do
59
59
  let(:os) { mock_platform('fedora') }
60
- it { os.redhat?.must_equal(true) }
60
+ it { os.fedora?.must_equal(true) }
61
+ it { os.redhat?.must_equal(false) }
62
+ it { os.debian?.must_equal(false) }
63
+ it { os.suse?.must_equal(false) }
64
+ it { os.linux?.must_equal(true) }
65
+ it { os.unix?.must_equal(true) }
66
+ end
67
+
68
+ describe 'with platform set to amazon' do
69
+ let(:os) { mock_platform('amazon') }
70
+ it { os.fedora?.must_equal(false) }
71
+ it { os.redhat?.must_equal(false) }
61
72
  it { os.debian?.must_equal(false) }
62
73
  it { os.suse?.must_equal(false) }
63
74
  it { os.linux?.must_equal(true) }
@@ -14,6 +14,16 @@ end
14
14
  describe 'os_detect_linux' do
15
15
  let(:detector) { OsDetectLinuxTester.new }
16
16
 
17
+ describe '#detect_linux_arch' do
18
+ it "sets the arch using uname" do
19
+ be = mock("Backend")
20
+ detector.stubs(:backend).returns(be)
21
+ be.stubs(:run_command).with("uname -m").returns(mock("Output", stdout: "x86_64\n"))
22
+ detector.detect_linux_arch
23
+ detector.platform[:arch].must_equal("x86_64")
24
+ end
25
+ end
26
+
17
27
  describe '#detect_linux_via_config' do
18
28
 
19
29
  before do
@@ -27,11 +37,25 @@ describe 'os_detect_linux' do
27
37
  detector.stubs(:get_config).with('/etc/enterprise-release').returns('data')
28
38
 
29
39
  detector.detect_linux_via_config.must_equal(true)
30
- detector.platform[:family].must_equal('oracle')
40
+ detector.platform[:name].must_equal('oracle')
41
+ detector.platform[:family].must_equal('redhat')
31
42
  detector.platform[:release].must_equal('redhat-version')
32
43
  end
33
44
  end
34
45
 
46
+ describe "/etc/redhat-release" do
47
+ describe "and /etc/os-release" do
48
+ it "sets the correct family, name, and release on centos" do
49
+ detector.stubs(:get_config).with("/etc/redhat-release").returns("CentOS Linux release 7.2.1511 (Core) \n")
50
+ detector.stubs(:get_config).with("/etc/os-release").returns("NAME=\"CentOS Linux\"\nVERSION=\"7 (Core)\"\nID=\"centos\"\nID_LIKE=\"rhel fedora\"\n")
51
+ detector.detect_linux_via_config.must_equal(true)
52
+ detector.platform[:name].must_equal('centos')
53
+ detector.platform[:family].must_equal('redhat')
54
+ detector.platform[:release].must_equal('redhat-version')
55
+ end
56
+ end
57
+ end
58
+
35
59
  describe '/etc/debian_version' do
36
60
 
37
61
  before { detector.stubs(:get_config).with('/etc/debian_version').returns('deb-version') }
@@ -41,7 +65,8 @@ describe 'os_detect_linux' do
41
65
  detector.stubs(:lsb).returns({ id: 'ubuntu', release: 'ubuntu-release' })
42
66
 
43
67
  detector.detect_linux_via_config.must_equal(true)
44
- detector.platform[:family].must_equal('ubuntu')
68
+ detector.platform[:name].must_equal('ubuntu')
69
+ detector.platform[:family].must_equal('debian')
45
70
  detector.platform[:release].must_equal('ubuntu-release')
46
71
  end
47
72
  end
@@ -51,7 +76,8 @@ describe 'os_detect_linux' do
51
76
  detector.stubs(:lsb).returns({ id: 'linuxmint', release: 'mint-release' })
52
77
 
53
78
  detector.detect_linux_via_config.must_equal(true)
54
- detector.platform[:family].must_equal('linuxmint')
79
+ detector.platform[:name].must_equal('linuxmint')
80
+ detector.platform[:family].must_equal('debian')
55
81
  detector.platform[:release].must_equal('mint-release')
56
82
  end
57
83
  end
@@ -62,7 +88,8 @@ describe 'os_detect_linux' do
62
88
  detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(true)
63
89
 
64
90
  detector.detect_linux_via_config.must_equal(true)
65
- detector.platform[:family].must_equal('raspbian')
91
+ detector.platform[:name].must_equal('raspbian')
92
+ detector.platform[:family].must_equal('debian')
66
93
  detector.platform[:release].must_equal('deb-version')
67
94
  end
68
95
  end
@@ -73,6 +100,7 @@ describe 'os_detect_linux' do
73
100
  detector.expects(:unix_file?).with('/usr/bin/raspi-config').returns(false)
74
101
 
75
102
  detector.detect_linux_via_config.must_equal(true)
103
+ detector.platform[:name].must_equal('debian')
76
104
  detector.platform[:family].must_equal('debian')
77
105
  detector.platform[:release].must_equal('deb-version')
78
106
  end
@@ -102,7 +130,8 @@ describe 'os_detect_linux' do
102
130
  detector.stubs(:fetch_os_release).returns(data)
103
131
 
104
132
  detector.detect_linux_via_config.must_equal(true)
105
- detector.platform[:family].must_equal('wrlinux')
133
+ detector.platform[:name].must_equal('wrlinux')
134
+ detector.platform[:family].must_equal('redhat')
106
135
  detector.platform[:release].must_equal('cisco123')
107
136
  end
108
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: train
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2016-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -158,6 +158,7 @@ files:
158
158
  - lib/train/extras/os_detect_unix.rb
159
159
  - lib/train/extras/os_detect_windows.rb
160
160
  - lib/train/extras/stat.rb
161
+ - lib/train/extras/uname.rb
161
162
  - lib/train/options.rb
162
163
  - lib/train/plugins.rb
163
164
  - lib/train/plugins/base_connection.rb