specinfra 2.14.4 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 78e4cd20118f7da1c280111157c3553b3fc480db
4
- data.tar.gz: 08355f950af76fbb57ee56091635e026c41146da
3
+ metadata.gz: 361d8ffe8fa2b17b7b9eee8351881419f8f5379b
4
+ data.tar.gz: 330df612efb50b40068c034e33105196fa64aea0
5
5
  SHA512:
6
- metadata.gz: 877f03d84359256870c26860e03b99364f6153c1e2ceb502ff5478b25a1945d9eece9f118794a9d34ab5107042404203906477539f87f5aada1b0b6e644562e2
7
- data.tar.gz: 59cc1afa0bd36ea01ca1f90d9f6c8557a13522d8ce78fb25b8645ac77fd7e553dd262b4a058d4c871fab3de4eb0f7adc2322b7fe57730644591364bfcc581032
6
+ metadata.gz: 0043e8d43ba0e507d13ff9ad7ddeb08489f926612396d264187e6e5ddd4b800072712bc348e2f588e287da58d552e4a7dcedcb1fc02e61e0ebf5b808ef5171a5
7
+ data.tar.gz: c7a2d8f61357127fd7d09929e9331c1f959ad15da7187313d0b247c86b5e953f7dfff2e9d910cf5172e499ee724d7fc66b8371d9f75fd75d01bfcbaccbc71e5d
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ if defined?(RSpec)
9
9
  task :spec => 'spec:all'
10
10
 
11
11
  namespace :spec do
12
- task :all => [ :helper, :backend, :configuration, :command ]
12
+ task :all => [ :helper, :backend, :configuration, :command, :host_inventory ]
13
13
 
14
14
  RSpec::Core::RakeTask.new(:helper) do |t|
15
15
  t.pattern = "spec/helper/*_spec.rb"
@@ -35,5 +35,9 @@ if defined?(RSpec)
35
35
  RSpec::Core::RakeTask.new(:command) do |t|
36
36
  t.pattern = "spec/command/**/*.rb"
37
37
  end
38
+
39
+ RSpec::Core::RakeTask.new(:host_inventory) do |t|
40
+ t.pattern = "spec/host_inventory/*_spec.rb"
41
+ end
38
42
  end
39
43
  end
@@ -8,6 +8,7 @@ require 'specinfra/command/module/zfs'
8
8
  # Base
9
9
  require 'specinfra/command/base'
10
10
  require 'specinfra/command/base/bridge'
11
+ require 'specinfra/command/base/bond'
11
12
  require 'specinfra/command/base/cron'
12
13
  require 'specinfra/command/base/file'
13
14
  require 'specinfra/command/base/fstab'
@@ -39,6 +40,7 @@ require 'specinfra/command/base/zfs'
39
40
  require 'specinfra/command/linux'
40
41
  require 'specinfra/command/linux/base'
41
42
  require 'specinfra/command/linux/base/bridge'
43
+ require 'specinfra/command/linux/base/bond'
42
44
  require 'specinfra/command/linux/base/file'
43
45
  require 'specinfra/command/linux/base/fstab'
44
46
  require 'specinfra/command/linux/base/interface'
@@ -0,0 +1,2 @@
1
+ class Specinfra::Command::Base::Bond < Specinfra::Command::Base
2
+ end
@@ -0,0 +1,11 @@
1
+ class Specinfra::Command::Linux::Base::Bond < Specinfra::Command::Base::Bond
2
+ class << self
3
+ def check_exists(name)
4
+ "ip link show #{name}"
5
+ end
6
+
7
+ def check_has_interface(name, interface)
8
+ "grep -o 'Slave Interface: #{interface}' /proc/net/bonding/#{name}"
9
+ end
10
+ end
11
+ end
@@ -4,6 +4,10 @@ class Specinfra::Command::Linux::Base::Inventory < Specinfra::Command::Base::Inv
4
4
  'cat /proc/meminfo'
5
5
  end
6
6
 
7
+ def get_cpu
8
+ 'cat /proc/cpuinfo'
9
+ end
10
+
7
11
  def get_hostname
8
12
  'hostname -s'
9
13
  end
@@ -6,6 +6,7 @@ require 'specinfra/host_inventory/fqdn'
6
6
  require 'specinfra/host_inventory/platform'
7
7
  require 'specinfra/host_inventory/platform_version'
8
8
  require 'specinfra/host_inventory/filesystem'
9
+ require 'specinfra/host_inventory/cpu'
9
10
 
10
11
  module Specinfra
11
12
  class HostInventory
@@ -0,0 +1,73 @@
1
+ module Specinfra
2
+ class HostInventory
3
+ class Cpu
4
+ def self.get
5
+ cmd = Specinfra.command.get(:get_inventory_cpu)
6
+ ret = Specinfra.backend.run_command(cmd).stdout
7
+ parse(ret)
8
+ end
9
+ def self.parse(cmd_ret)
10
+ cpuinfo = {}
11
+ cpus = cmd_ret.split(/[^^]processor/)
12
+ cpuinfo['total'] = cpus.length.to_s
13
+ cpus.each_with_index do |cpu, idx|
14
+ idx = idx.to_s
15
+ cpuinfo[idx] = {}
16
+ cpu.each_line do |line|
17
+ case line
18
+ when /^vendor_id\s*:\s+(.+)$/
19
+ cpuinfo[idx]['vendor_id'] = $1
20
+ when /^cpu family\s*:\s+(\d+)$/
21
+ cpuinfo[idx]['cpu_family'] = $1
22
+ when /^model\s*:\s+(\d+)$/
23
+ cpuinfo[idx]['model'] = $1
24
+ when /^model\sname\s*:\s+(.+)$/
25
+ cpuinfo[idx]['model_name'] = $1
26
+ when /^stepping\s*:\s+(\d+)$/
27
+ cpuinfo[idx]['stepping'] = $1
28
+ when /^microcode\s*:\s+(.+)$/
29
+ cpuinfo[idx]['microcode'] = $1
30
+ when /^cpu MHz\s*:\s+(.+)$/
31
+ cpuinfo[idx]['cpu_mhz'] = $1
32
+ when /^cache size\s*:\s+(\d+) (.+)$/
33
+ cpuinfo[idx]['cache_size'] = "#{$1}#{$2}"
34
+ when /^physical id\s*:\s+(\d+)$/
35
+ cpuinfo[idx]['physical_id'] = $1
36
+ when /^siblings\s*:\s+(\d+)$/
37
+ cpuinfo[idx]['siblings'] = $1
38
+ when /^core id\s*:\s+(\d+)$/
39
+ cpuinfo[idx]['core_id'] = $1
40
+ when /^cpu cores\s*:\s+(\d+)$/
41
+ cpuinfo[idx]['cpu_cores'] = $1
42
+ when /^apicid\s*:\s+(\d+)$/
43
+ cpuinfo[idx]['apicid'] = $1
44
+ when /^initial apicid\s*:\s+(\d+)$/
45
+ cpuinfo[idx]['initial_apicid'] = $1
46
+ when /^fpu\s*:\s+(.+)$/
47
+ cpuinfo[idx]['fpu'] = $1
48
+ when /^fpu_exception\s*:\s+(.+)$/
49
+ cpuinfo[idx]['fpu_exception'] = $1
50
+ when /^cpuid level\s*:\s+(\d+)$/
51
+ cpuinfo[idx]['cpuid_level'] = $1
52
+ when /^wp\s*:\s+(.+)$/
53
+ cpuinfo[idx]['wp'] = $1
54
+ when /^flags\s*:\s+(.+)$/
55
+ cpuinfo[idx]['flags'] = $1.split(/\s/)
56
+ when /^bogomips\s*:\s+(.+)$/
57
+ cpuinfo[idx]['bogomips'] = $1
58
+ when /^clflush size\s*:\s+(\d+)$/
59
+ cpuinfo[idx]['clflush_size'] = $1
60
+ when /^cache_alignment\s*:\s+(\d+)$/
61
+ cpuinfo[idx]['cache_alignment'] = $1
62
+ when /^address sizes\s*:\s+(.+)$/
63
+ cpuinfo[idx]['address_sizes'] = $1
64
+ when /^power management\s*:\s+(.*)$/
65
+ cpuinfo[idx]['power_management'] = $1
66
+ end
67
+ end
68
+ end
69
+ cpuinfo
70
+ end
71
+ end
72
+ end
73
+ end
@@ -1,3 +1,3 @@
1
1
  module Specinfra
2
- VERSION = "2.14.4"
2
+ VERSION = "2.15.0"
3
3
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ property[:os] = nil
4
+ set :os, :family => 'linux'
5
+
6
+ describe get_command(:check_bond_exists, 'bond0') do
7
+ it { should eq "ip link show bond0" }
8
+ end
9
+
10
+ describe get_command(:check_bond_has_interface, 'br0', 'eth0') do
11
+ it { should eq "grep -o 'Slave Interface: eth0' /proc/net/bonding/br0" }
12
+ end
@@ -5,3 +5,7 @@ set :os, :family => 'linux'
5
5
  describe get_command(:get_inventory_memory) do
6
6
  it { should eq 'cat /proc/meminfo' }
7
7
  end
8
+
9
+ describe get_command(:get_inventory_cpu) do
10
+ it { should eq 'cat /proc/cpuinfo' }
11
+ end
@@ -0,0 +1,122 @@
1
+ require 'spec_helper'
2
+
3
+ str = <<-EOH
4
+ processor : 0
5
+ vendor_id : GenuineIntel
6
+ cpu family : 6
7
+ model : 60
8
+ model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
9
+ stepping : 3
10
+ microcode : 0x19
11
+ cpu MHz : 3132.076
12
+ cache size : 6144 KB
13
+ physical id : 0
14
+ siblings : 2
15
+ core id : 0
16
+ cpu cores : 2
17
+ apicid : 0
18
+ initial apicid : 0
19
+ fpu : yes
20
+ fpu_exception : yes
21
+ cpuid level : 5
22
+ wp : yes
23
+ flags : fpu vme de pse
24
+ bogomips : 6264.15
25
+ clflush size : 64
26
+ cache_alignment : 64
27
+ address sizes : 39 bits physical, 48 bits virtual
28
+ power management:
29
+
30
+ processor : 1
31
+ vendor_id : GenuineIntel
32
+ cpu family : 6
33
+ model : 60
34
+ model name : Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz
35
+ stepping : 3
36
+ microcode : 0x19
37
+ cpu MHz : 3132.076
38
+ cache size : 6144 KB
39
+ physical id : 0
40
+ siblings : 2
41
+ core id : 1
42
+ cpu cores : 2
43
+ apicid : 1
44
+ initial apicid : 1
45
+ fpu : yes
46
+ fpu_exception : yes
47
+ cpuid level : 5
48
+ wp : yes
49
+ flags : fpu vme de
50
+ bogomips : 6264.15
51
+ clflush size : 64
52
+ cache_alignment : 64
53
+ address sizes : 39 bits physical, 48 bits virtual
54
+ power management:
55
+ EOH
56
+
57
+ describe Specinfra::HostInventory::Cpu do
58
+ describe 'Example of Ubuntu 14.04.1 LTS Kernel version 3.13.11' do
59
+ ret = Specinfra::HostInventory::Cpu.parse(str)
60
+ example do
61
+ expect(ret["0"]).to include(
62
+ "vendor_id" => "GenuineIntel",
63
+ "cpu_family" => "6",
64
+ "model" => "60",
65
+ "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz",
66
+ "stepping" => "3",
67
+ "microcode" => "0x19",
68
+ "cpu_mhz" => "3132.076",
69
+ "cache_size" => "6144KB",
70
+ "physical_id" => "0",
71
+ "siblings" => "2",
72
+ "core_id" => "0",
73
+ "cpu_cores" => "2",
74
+ "apicid" => "0",
75
+ "initial_apicid" => "0",
76
+ "fpu" => "yes",
77
+ "fpu_exception" => "yes",
78
+ "cpuid_level" => "5",
79
+ "wp" => "yes",
80
+ "flags" => ["fpu", "vme", "de", "pse"],
81
+ "bogomips" => "6264.15",
82
+ "clflush_size" => "64",
83
+ "cache_alignment" => "64",
84
+ "address_sizes" => "39 bits physical, 48 bits virtual",
85
+ "power_management" => ""
86
+ )
87
+ end
88
+
89
+ example do
90
+ expect(ret["1"]).to include(
91
+ "vendor_id" => "GenuineIntel",
92
+ "cpu_family" => "6",
93
+ "model" => "60",
94
+ "model_name" => "Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz",
95
+ "stepping" => "3",
96
+ "microcode" => "0x19",
97
+ "cpu_mhz" => "3132.076",
98
+ "cache_size" => "6144KB",
99
+ "physical_id" => "0",
100
+ "siblings" => "2",
101
+ "core_id" => "1",
102
+ "cpu_cores" => "2",
103
+ "apicid" => "1",
104
+ "initial_apicid" => "1",
105
+ "fpu" => "yes",
106
+ "fpu_exception" => "yes",
107
+ "cpuid_level" => "5",
108
+ "wp" => "yes",
109
+ "flags" => ["fpu", "vme", "de"],
110
+ "bogomips" => "6264.15",
111
+ "clflush_size" => "64",
112
+ "cache_alignment" => "64",
113
+ "address_sizes" => "39 bits physical, 48 bits virtual",
114
+ "power_management" => ""
115
+ )
116
+ end
117
+
118
+ example do
119
+ expect(ret["total"]).to eq "2"
120
+ end
121
+ end
122
+ end
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'specinfra'
2
2
  require 'rspec/mocks/standalone'
3
3
  require 'rspec/its'
4
4
  require 'specinfra/helper/set'
5
+ require 'specinfra/helper/host_inventory'
5
6
  include Specinfra::Helper::Set
6
7
 
7
8
  set :backend, :exec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specinfra
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.4
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gosuke Miyashita
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-23 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -151,6 +151,7 @@ files:
151
151
  - lib/specinfra/command/arch/base/package.rb
152
152
  - lib/specinfra/command/arch/base/service.rb
153
153
  - lib/specinfra/command/base.rb
154
+ - lib/specinfra/command/base/bond.rb
154
155
  - lib/specinfra/command/base/bridge.rb
155
156
  - lib/specinfra/command/base/cron.rb
156
157
  - lib/specinfra/command/base/file.rb
@@ -213,6 +214,7 @@ files:
213
214
  - lib/specinfra/command/gentoo/base/service.rb
214
215
  - lib/specinfra/command/linux.rb
215
216
  - lib/specinfra/command/linux/base.rb
217
+ - lib/specinfra/command/linux/base/bond.rb
216
218
  - lib/specinfra/command/linux/base/bridge.rb
217
219
  - lib/specinfra/command/linux/base/file.rb
218
220
  - lib/specinfra/command/linux/base/fstab.rb
@@ -338,6 +340,7 @@ files:
338
340
  - lib/specinfra/helper/properties.rb
339
341
  - lib/specinfra/helper/set.rb
340
342
  - lib/specinfra/host_inventory.rb
343
+ - lib/specinfra/host_inventory/cpu.rb
341
344
  - lib/specinfra/host_inventory/domain.rb
342
345
  - lib/specinfra/host_inventory/ec2.rb
343
346
  - lib/specinfra/host_inventory/filesystem.rb
@@ -362,6 +365,7 @@ files:
362
365
  - spec/command/debian/service_spec.rb
363
366
  - spec/command/factory_spec.rb
364
367
  - spec/command/freebsd/file_spec.rb
368
+ - spec/command/linux/bond_spec.rb
365
369
  - spec/command/linux/bridge_spec.rb
366
370
  - spec/command/linux/interface_spec.rb
367
371
  - spec/command/linux/inventory_spec.rb
@@ -378,6 +382,7 @@ files:
378
382
  - spec/helper/os_spec.rb
379
383
  - spec/helper/properties_spec.rb
380
384
  - spec/helper/set_spec.rb
385
+ - spec/host_inventory/cpu_spec.rb
381
386
  - spec/spec_helper.rb
382
387
  - specinfra.gemspec
383
388
  - wercker.yml
@@ -418,6 +423,7 @@ test_files:
418
423
  - spec/command/debian/service_spec.rb
419
424
  - spec/command/factory_spec.rb
420
425
  - spec/command/freebsd/file_spec.rb
426
+ - spec/command/linux/bond_spec.rb
421
427
  - spec/command/linux/bridge_spec.rb
422
428
  - spec/command/linux/interface_spec.rb
423
429
  - spec/command/linux/inventory_spec.rb
@@ -434,4 +440,5 @@ test_files:
434
440
  - spec/helper/os_spec.rb
435
441
  - spec/helper/properties_spec.rb
436
442
  - spec/helper/set_spec.rb
443
+ - spec/host_inventory/cpu_spec.rb
437
444
  - spec/spec_helper.rb