ohai 14.4.2 → 14.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -0
- data/README.md +12 -7
- data/Rakefile +26 -8
- data/lib/ohai/application.rb +4 -8
- data/lib/ohai/plugins/openstack.rb +3 -1
- data/lib/ohai/plugins/root_group.rb +13 -2
- data/lib/ohai/plugins/windows/filesystem.rb +115 -22
- data/lib/ohai/util/win32/group_helper.rb +3 -0
- data/lib/ohai/version.rb +1 -1
- data/spec/unit/plugins/openstack_spec.rb +22 -4
- data/spec/unit/plugins/root_group_spec.rb +12 -4
- data/spec/unit/plugins/windows/filesystem_spec.rb +226 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a51cf17407e9d91624a5fa169e8057d15a75eac70805fc38a4fcbf928141121b
|
4
|
+
data.tar.gz: 69c101063af73a9b0aba3f0956e57ce9c488607e76f605d1425e0d40951bcb38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 354f6a0bd33873e3d8b124eeb23bfd111bd8b6cf46642fd119c3dd5cfd82666629ccff70fad44b08ac4a7fb2900a566cc0639558b0b5b2d10b95cec4d2e5a052
|
7
|
+
data.tar.gz: 67bdf1bfc49797e0f61d95c96e2ad769c124ea19dc682358ae5fc27042cd8cdc4e08ea3f831a05c5b5edf3e1dd495579e90e9ac1321d7d678db41f58f167b4b9
|
data/Gemfile
CHANGED
@@ -17,6 +17,19 @@ group :ci do
|
|
17
17
|
gem "rspec_junit_formatter"
|
18
18
|
end
|
19
19
|
|
20
|
+
group :docs do
|
21
|
+
gem "yard"
|
22
|
+
gem "redcarpet"
|
23
|
+
gem "github-markup"
|
24
|
+
end
|
25
|
+
|
26
|
+
group :debug do
|
27
|
+
gem "pry"
|
28
|
+
gem "pry-byebug"
|
29
|
+
gem "pry-stack_explorer"
|
30
|
+
gem "rb-readline"
|
31
|
+
end
|
32
|
+
|
20
33
|
instance_eval(ENV["GEMFILE_MOD"]) if ENV["GEMFILE_MOD"]
|
21
34
|
|
22
35
|
# If you want to load debugging tools into the bundle exec sandbox,
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ Ohai will print out a JSON data blob for all the known data about your system. W
|
|
11
11
|
Chef distributes ohai as a RubyGem. This README is for developers who want to modify the Ohai source code. For users who want to write plugins for Ohai, see the docs:
|
12
12
|
|
13
13
|
- General documentation: <https://docs.chef.io/ohai.html>
|
14
|
-
-
|
14
|
+
- Writing Ohai Plugins documentation: <https://docs.chef.io/ohai_custom.html>
|
15
15
|
|
16
16
|
## Development Environment:
|
17
17
|
|
@@ -37,11 +37,16 @@ Ohai has some Rake tasks for doing various things.
|
|
37
37
|
|
38
38
|
```
|
39
39
|
rake -T
|
40
|
-
rake build
|
41
|
-
rake
|
42
|
-
rake
|
43
|
-
rake
|
44
|
-
rake
|
40
|
+
rake build # Build ohai-$VERSION.gem into the pkg directory
|
41
|
+
rake clean # Remove any temporary products
|
42
|
+
rake clobber # Remove any generated files
|
43
|
+
rake docs # Generate YARD Documentation
|
44
|
+
rake install # Build and install ohai-$VERSION.gem into system gems
|
45
|
+
rake install:local # Build and install ohai-$VERSION.gem into system gems without network access
|
46
|
+
rake release[remote] # Create tag $VERSION and build and push ohai-$VERSION.gem to rubygems.org
|
47
|
+
rake spec # Run RSpec code examples
|
48
|
+
rake style # Run Chefstyle tests
|
49
|
+
rake style:auto_correct # Auto-correct RuboCop offenses
|
45
50
|
|
46
51
|
($VERSION is the current version, from the GemSpec in Rakefile)
|
47
52
|
```
|
@@ -65,7 +70,7 @@ For information on contributing to this project see <https://github.com/chef/che
|
|
65
70
|
Ohai - system information application
|
66
71
|
|
67
72
|
- Author:: Adam Jacob ([adam@chef.io](mailto:adam@chef.io))
|
68
|
-
- Copyright:: Copyright (c) 2008-
|
73
|
+
- Copyright:: Copyright (c) 2008-2018 Chef Software, Inc.
|
69
74
|
- License:: Apache License, Version 2.0
|
70
75
|
|
71
76
|
```text
|
data/Rakefile
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "date"
|
3
|
-
require "ohai/version"
|
4
2
|
|
5
3
|
begin
|
6
4
|
require "rspec/core/rake_task"
|
@@ -11,14 +9,34 @@ begin
|
|
11
9
|
rescue LoadError
|
12
10
|
desc "rspec is not installed, this task is disabled"
|
13
11
|
task :spec do
|
14
|
-
abort "rspec is not installed.
|
12
|
+
abort "rspec is not installed. bundle install first to make sure all dependencies are installed."
|
15
13
|
end
|
16
14
|
end
|
17
15
|
|
18
|
-
|
16
|
+
begin
|
17
|
+
require "chefstyle"
|
18
|
+
require "rubocop/rake_task"
|
19
|
+
desc "Run Chefstyle tests"
|
20
|
+
RuboCop::RakeTask.new(:style) do |task|
|
21
|
+
task.options += ["--display-cop-names", "--no-color"]
|
22
|
+
end
|
23
|
+
rescue LoadError
|
24
|
+
puts "chefstyle gem is not installed. bundle install first to make sure all dependencies are installed."
|
25
|
+
end
|
19
26
|
|
20
|
-
|
21
|
-
require "
|
22
|
-
|
23
|
-
|
27
|
+
begin
|
28
|
+
require "yard"
|
29
|
+
YARD::Rake::YardocTask.new(:docs)
|
30
|
+
rescue LoadError
|
31
|
+
puts "yard is not available. bundle install first to make sure all dependencies are installed."
|
32
|
+
end
|
33
|
+
|
34
|
+
task :console do
|
35
|
+
require "irb"
|
36
|
+
require "irb/completion"
|
37
|
+
require "ohai"
|
38
|
+
ARGV.clear
|
39
|
+
IRB.start
|
24
40
|
end
|
41
|
+
|
42
|
+
task default: [:style, :spec]
|
data/lib/ohai/application.rb
CHANGED
@@ -69,14 +69,6 @@ class Ohai::Application
|
|
69
69
|
proc: lambda { |v| puts "Ohai: #{::Ohai::VERSION}" },
|
70
70
|
exit: 0
|
71
71
|
|
72
|
-
def initialize
|
73
|
-
super
|
74
|
-
|
75
|
-
# Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
|
76
|
-
# from failing due to permissions when launched as a less privileged user.
|
77
|
-
Dir.chdir("/")
|
78
|
-
end
|
79
|
-
|
80
72
|
def run
|
81
73
|
elapsed = Benchmark.measure do
|
82
74
|
configure_ohai
|
@@ -95,6 +87,10 @@ class Ohai::Application
|
|
95
87
|
end
|
96
88
|
|
97
89
|
def run_application
|
90
|
+
# Always switch to a readable directory. Keeps subsequent Dir.chdir() {}
|
91
|
+
# from failing due to permissions when launched as a less privileged user.
|
92
|
+
Dir.chdir("/")
|
93
|
+
|
98
94
|
config[:invoked_from_cli] = true
|
99
95
|
config[:logger] = Ohai::Log.with_child
|
100
96
|
ohai = Ohai::System.new(config)
|
@@ -64,8 +64,10 @@ Ohai.plugin(:Openstack) do
|
|
64
64
|
openstack Mash.new
|
65
65
|
openstack[:provider] = openstack_provider
|
66
66
|
|
67
|
+
timeout = Ohai::Config.ohai[:openstack_metadata_timeout] || 2
|
68
|
+
|
67
69
|
# fetch the metadata if we can do a simple socket connect first
|
68
|
-
if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
70
|
+
if can_socket_connect?(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, timeout)
|
69
71
|
fetch_metadata.each do |k, v|
|
70
72
|
openstack[k] = v
|
71
73
|
end
|
@@ -19,8 +19,19 @@ Ohai.plugin(:RootGroup) do
|
|
19
19
|
provides "root_group"
|
20
20
|
|
21
21
|
collect_data(:windows) do
|
22
|
-
require "
|
23
|
-
|
22
|
+
require "wmi-lite/wmi"
|
23
|
+
|
24
|
+
wmi = WmiLite::Wmi.new
|
25
|
+
# Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
|
26
|
+
# internal name for the Administrators group, which lets us work
|
27
|
+
# properly in environments with a renamed or localized name for the
|
28
|
+
# Administrators group.
|
29
|
+
# Use LocalAccount=True because otherwise WMI will attempt to include
|
30
|
+
# (unneeded) Active Directory groups by querying AD, which is a performance
|
31
|
+
# and reliability issue since AD might not be reachable.
|
32
|
+
groups = wmi.query("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
|
33
|
+
windows_root_group_name = groups[0]["name"]
|
34
|
+
root_group windows_root_group_name
|
24
35
|
end
|
25
36
|
|
26
37
|
collect_data(:default) do
|
@@ -19,36 +19,129 @@
|
|
19
19
|
Ohai.plugin(:Filesystem) do
|
20
20
|
provides "filesystem"
|
21
21
|
|
22
|
-
|
22
|
+
# Volume encryption or decryption status
|
23
|
+
#
|
24
|
+
# @see https://docs.microsoft.com/en-us/windows/desktop/SecProv/getconversionstatus-win32-encryptablevolume#parameters
|
25
|
+
#
|
26
|
+
CONVERSION_STATUS = %w{FullyDecrypted FullyEncrypted EncryptionInProgress
|
27
|
+
DecryptionInProgress EncryptionPaused DecryptionPaused}.freeze
|
23
28
|
|
24
|
-
|
29
|
+
# Returns a Mash loaded with logical details
|
30
|
+
#
|
31
|
+
# Uses Win32_LogicalDisk and logical_properties to return encryption details of volumes.
|
32
|
+
#
|
33
|
+
# Returns an empty Mash in case of any WMI exception.
|
34
|
+
#
|
35
|
+
# @see https://docs.microsoft.com/en-us/windows/desktop/CIMWin32Prov/win32-logicaldisk
|
36
|
+
#
|
37
|
+
# @return [Mash]
|
38
|
+
#
|
39
|
+
def logical_info
|
40
|
+
wmi = WmiLite::Wmi.new("Root\\CIMV2")
|
25
41
|
|
26
|
-
|
27
|
-
|
42
|
+
# Note: we should really be parsing Win32_Volume and Win32_Mapped drive.
|
43
|
+
disks = wmi.instances_of("Win32_LogicalDisk")
|
44
|
+
logical_properties(disks)
|
45
|
+
rescue WmiLite::WmiException
|
46
|
+
Ohai::Log.debug("Unable to access Win32_LogicalDisk. Skipping logical details")
|
47
|
+
Mash.new
|
48
|
+
end
|
28
49
|
|
29
|
-
|
50
|
+
# Returns a Mash loaded with encryption details
|
51
|
+
#
|
52
|
+
# Uses Win32_EncryptableVolume and encryption_properties to return encryption details of volumes.
|
53
|
+
#
|
54
|
+
# Returns an empty Mash in case of any WMI exception.
|
55
|
+
#
|
56
|
+
# @note We are fetching Encryption Status only as of now
|
57
|
+
#
|
58
|
+
# @see https://msdn.microsoft.com/en-us/library/windows/desktop/aa376483(v=vs.85).aspx
|
59
|
+
#
|
60
|
+
# @return [Mash]
|
61
|
+
#
|
62
|
+
def encryptable_info
|
63
|
+
wmi = WmiLite::Wmi.new("Root\\CIMV2\\Security\\MicrosoftVolumeEncryption")
|
64
|
+
disks = wmi.instances_of("Win32_EncryptableVolume")
|
65
|
+
encryption_properties(disks)
|
66
|
+
rescue WmiLite::WmiException
|
67
|
+
Ohai::Log.debug("Unable to access Win32_EncryptableVolume. Skipping encryptable details")
|
68
|
+
Mash.new
|
69
|
+
end
|
30
70
|
|
31
|
-
|
32
|
-
|
33
|
-
|
71
|
+
# Refines and calculates logical properties out of given instances
|
72
|
+
#
|
73
|
+
# @param [WmiLite::Wmi::Instance] disks
|
74
|
+
#
|
75
|
+
# @return [Mash] Each drive containing following properties:
|
76
|
+
#
|
77
|
+
# * :kb_size (Integer)
|
78
|
+
# * :kb_available (Integer)
|
79
|
+
# * :kb_used (Integer)
|
80
|
+
# * :percent_used (Integer)
|
81
|
+
# * :mount (String)
|
82
|
+
# * :fs_type (String)
|
83
|
+
# * :volume_name (String)
|
84
|
+
#
|
85
|
+
def logical_properties(disks)
|
86
|
+
properties = Mash.new
|
87
|
+
disks.each do |disk|
|
88
|
+
property = Mash.new
|
89
|
+
drive = disk["deviceid"]
|
90
|
+
property[:kb_size] = disk["size"].to_i / 1000
|
91
|
+
property[:kb_available] = disk["freespace"].to_i / 1000
|
92
|
+
property[:kb_used] = property[:kb_size] - property[:kb_available]
|
93
|
+
property[:percent_used] = (property[:kb_size] == 0 ? 0 : (property[:kb_used] * 100 / property[:kb_size]))
|
94
|
+
property[:mount] = disk["name"]
|
95
|
+
property[:fs_type] = disk["filesystem"].to_s.downcase
|
96
|
+
property[:volume_name] = disk["volumename"].to_s.downcase
|
97
|
+
properties[drive] = property
|
98
|
+
end
|
99
|
+
properties
|
100
|
+
end
|
34
101
|
|
102
|
+
# Refines and calculates encryption properties out of given instances
|
103
|
+
#
|
104
|
+
# @param [WmiLite::Wmi::Instance] disks
|
105
|
+
#
|
106
|
+
# @return [Mash] Each drive containing following properties:
|
107
|
+
#
|
108
|
+
# * :encryption_status (String)
|
109
|
+
#
|
110
|
+
def encryption_properties(disks)
|
111
|
+
properties = Mash.new
|
35
112
|
disks.each do |disk|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
113
|
+
drive = disk["driveletter"]
|
114
|
+
property = Mash.new
|
115
|
+
property[:encryption_status] = disk["conversionstatus"] ? CONVERSION_STATUS[disk["conversionstatus"]] : ""
|
116
|
+
properties[drive] = property
|
117
|
+
end
|
118
|
+
properties
|
119
|
+
end
|
120
|
+
|
121
|
+
# Merges all the various properties of filesystems
|
122
|
+
#
|
123
|
+
# @param [Array<Mash>] disks_info
|
124
|
+
# Array of the Mashes containing disk properties
|
125
|
+
#
|
126
|
+
# @return [Mash]
|
127
|
+
#
|
128
|
+
def merge_info(disks_info)
|
129
|
+
fs = Mash.new
|
130
|
+
disks_info.each do |info|
|
131
|
+
info.each do |disk, data|
|
132
|
+
if fs[disk]
|
133
|
+
fs[disk].merge!(data)
|
134
|
+
else
|
135
|
+
fs[disk] = data.dup
|
136
|
+
end
|
41
137
|
end
|
42
|
-
fs[filesystem][:kb_size] = ld_info[filesystem][:size].to_i / 1000
|
43
|
-
fs[filesystem][:kb_available] = ld_info[filesystem][:free_space].to_i / 1000
|
44
|
-
fs[filesystem][:kb_used] = fs[filesystem][:kb_size].to_i - fs[filesystem][:kb_available].to_i
|
45
|
-
fs[filesystem][:percent_used] = (fs[filesystem][:kb_size].to_i != 0 ? fs[filesystem][:kb_used].to_i * 100 / fs[filesystem][:kb_size].to_i : 0)
|
46
|
-
fs[filesystem][:mount] = ld_info[filesystem][:name]
|
47
|
-
fs[filesystem][:fs_type] = ld_info[filesystem][:file_system].downcase unless ld_info[filesystem][:file_system].nil?
|
48
|
-
fs[filesystem][:volume_name] = ld_info[filesystem][:volume_name]
|
49
138
|
end
|
139
|
+
fs
|
140
|
+
end
|
50
141
|
|
51
|
-
|
52
|
-
|
142
|
+
collect_data(:windows) do
|
143
|
+
require "wmi-lite/wmi"
|
144
|
+
filesystem merge_info([logical_info,
|
145
|
+
encryptable_info])
|
53
146
|
end
|
54
147
|
end
|
@@ -21,6 +21,7 @@ require "ohai/util/win32"
|
|
21
21
|
module Ohai
|
22
22
|
module Util
|
23
23
|
class Win32::GroupHelper
|
24
|
+
# @deprecated
|
24
25
|
|
25
26
|
# Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
|
26
27
|
# internal name for the Administrators group, which lets us work
|
@@ -29,6 +30,8 @@ module Ohai
|
|
29
30
|
BUILTIN_ADMINISTRATORS_SID = "S-1-5-32-544".freeze
|
30
31
|
|
31
32
|
def self.windows_root_group_name
|
33
|
+
warn "The 'windows_root_group_name' helper is deprecated and will be removed in Ohai 15. Please update your plugins to remove this helper method."
|
34
|
+
|
32
35
|
administrators_sid_result = FFI::MemoryPointer.new(:pointer)
|
33
36
|
convert_result = Win32.convert_string_sid_to_sid(BUILTIN_ADMINISTRATORS_SID, administrators_sid_result)
|
34
37
|
last_win32_error = Win32.get_last_error
|
data/lib/ohai/version.rb
CHANGED
@@ -21,6 +21,7 @@ require_relative "../../spec_helper.rb"
|
|
21
21
|
describe Ohai::System, "plugin openstack" do
|
22
22
|
|
23
23
|
let(:plugin) { get_plugin("openstack") }
|
24
|
+
let(:default_timeout) { 2 }
|
24
25
|
|
25
26
|
before(:each) do
|
26
27
|
allow(plugin).to receive(:hint?).with("openstack").and_return(false)
|
@@ -38,7 +39,7 @@ describe Ohai::System, "plugin openstack" do
|
|
38
39
|
context "and the metadata service is not available" do
|
39
40
|
before do
|
40
41
|
allow(plugin).to receive(:can_socket_connect?)
|
41
|
-
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
42
|
+
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
|
42
43
|
.and_return(false)
|
43
44
|
plugin[:dmi] = dmi_data
|
44
45
|
plugin.run
|
@@ -77,7 +78,7 @@ describe Ohai::System, "plugin openstack" do
|
|
77
78
|
it "sets openstack provider attribute to dreamhost" do
|
78
79
|
plugin["etc"] = { "passwd" => { "dhc-user" => {} } }
|
79
80
|
allow(plugin).to receive(:can_socket_connect?)
|
80
|
-
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
81
|
+
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
|
81
82
|
.and_return(false)
|
82
83
|
plugin[:dmi] = { system: { all_records: [ { Manufacturer: "OpenStack Foundation" } ] } }
|
83
84
|
plugin.run
|
@@ -89,7 +90,7 @@ describe Ohai::System, "plugin openstack" do
|
|
89
90
|
context "and the metadata service is not available" do
|
90
91
|
before do
|
91
92
|
allow(plugin).to receive(:can_socket_connect?)
|
92
|
-
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
93
|
+
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
|
93
94
|
.and_return(false)
|
94
95
|
allow(plugin).to receive(:hint?).with("openstack").and_return(true)
|
95
96
|
plugin.run
|
@@ -102,6 +103,23 @@ describe Ohai::System, "plugin openstack" do
|
|
102
103
|
it "doesn't set metadata attributes" do
|
103
104
|
expect(plugin[:openstack][:instance_id]).to be_nil
|
104
105
|
end
|
106
|
+
context "when timout was set" do
|
107
|
+
let(:override_timout) { 10 }
|
108
|
+
before do
|
109
|
+
Ohai::Config.ohai[:openstack_metadata_timeout] = override_timout
|
110
|
+
end
|
111
|
+
after do
|
112
|
+
Ohai::Config.ohai[:openstack_metadata_timeout] = nil
|
113
|
+
end
|
114
|
+
|
115
|
+
it "overwrite timout by setting" do
|
116
|
+
allow(plugin).to receive(:can_socket_connect?)
|
117
|
+
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, override_timout)
|
118
|
+
.and_return(false)
|
119
|
+
allow(plugin).to receive(:hint?).with("openstack").and_return(true)
|
120
|
+
plugin.run
|
121
|
+
end
|
122
|
+
end
|
105
123
|
end
|
106
124
|
|
107
125
|
context "and the metadata service is available" do
|
@@ -196,7 +214,7 @@ EOM
|
|
196
214
|
before do
|
197
215
|
allow(plugin).to receive(:hint?).with("openstack").and_return(true)
|
198
216
|
allow(plugin).to receive(:can_socket_connect?)
|
199
|
-
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80)
|
217
|
+
.with(Ohai::Mixin::Ec2Metadata::EC2_METADATA_ADDR, 80, default_timeout)
|
200
218
|
.and_return(true)
|
201
219
|
|
202
220
|
allow(Net::HTTP).to receive(:start)
|
@@ -17,7 +17,6 @@
|
|
17
17
|
#
|
18
18
|
|
19
19
|
require_relative "../../spec_helper.rb"
|
20
|
-
require "ohai/util/win32/group_helper"
|
21
20
|
|
22
21
|
describe Ohai::System, "root_group" do
|
23
22
|
before(:each) do
|
@@ -78,11 +77,20 @@ describe Ohai::System, "root_group" do
|
|
78
77
|
end
|
79
78
|
|
80
79
|
describe "windows platform" do
|
81
|
-
|
80
|
+
|
81
|
+
let(:wmi) { double("wmi", { query: "" }) }
|
82
|
+
|
83
|
+
before(:each) do
|
84
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
|
82
85
|
allow(@plugin).to receive(:collect_os).and_return(:windows)
|
83
|
-
|
86
|
+
end
|
87
|
+
it "should return the group Administrators" do
|
88
|
+
expect(wmi)
|
89
|
+
.to receive(:query)
|
90
|
+
.with("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
|
91
|
+
.and_return("Administrators")
|
92
|
+
|
84
93
|
@plugin.run
|
85
|
-
expect(@plugin[:root_group]).to eq("administrators")
|
86
94
|
end
|
87
95
|
end
|
88
96
|
end
|
@@ -0,0 +1,226 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Nimesh Pathi <nimesh.patni@msystechnologies.com>
|
3
|
+
# Copyright:: Copyright (c) 2018 Chef Software, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require_relative "../../../spec_helper.rb"
|
20
|
+
require "wmi-lite/wmi"
|
21
|
+
|
22
|
+
describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
|
23
|
+
let(:plugin) { get_plugin("windows/filesystem") }
|
24
|
+
|
25
|
+
let(:success) { true }
|
26
|
+
|
27
|
+
let(:logical_disks_instances) do
|
28
|
+
[
|
29
|
+
{
|
30
|
+
"caption" => "C:",
|
31
|
+
"deviceid" => "C:",
|
32
|
+
"size" => "10000000",
|
33
|
+
"filesystem" => "NTFS",
|
34
|
+
"freespace" => "100000",
|
35
|
+
"name" => "C:",
|
36
|
+
"volumename " => "",
|
37
|
+
},
|
38
|
+
{
|
39
|
+
"caption" => "D:",
|
40
|
+
"deviceid" => "D:",
|
41
|
+
"size" => "10000000",
|
42
|
+
"filesystem" => "FAT32",
|
43
|
+
"freespace" => "100000",
|
44
|
+
"name" => "D:"
|
45
|
+
# Lets not pass "volumename" for this drive
|
46
|
+
}
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
let(:encryptable_volume_instances) do
|
51
|
+
[
|
52
|
+
{
|
53
|
+
"conversionstatus" => 0,
|
54
|
+
"driveletter" => "C:",
|
55
|
+
},
|
56
|
+
{
|
57
|
+
"conversionstatus" => 2,
|
58
|
+
"driveletter" => "D:",
|
59
|
+
}
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:wmi_exception) do
|
64
|
+
namespace = "Exception while testing"
|
65
|
+
exception = WIN32OLERuntimeError.new(namespace)
|
66
|
+
WmiLite::WmiException.new(exception, :ConnectServer, @namespace)
|
67
|
+
end
|
68
|
+
|
69
|
+
before(:each) do
|
70
|
+
allow(plugin).to receive(:collect_os).and_return(:windows)
|
71
|
+
end
|
72
|
+
|
73
|
+
describe "#logical_properties" do
|
74
|
+
let(:disks) { logical_disks_instances }
|
75
|
+
let(:logical_props) { %i{kb_size kb_available kb_used percent_used mount fs_type volume_name} }
|
76
|
+
|
77
|
+
it "Returns a mash" do
|
78
|
+
expect(plugin.logical_properties(disks)).to be_a(Mash)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "Returns an empty mash when blank array is passed" do
|
82
|
+
expect(plugin.logical_properties([])).to be_a(Mash)
|
83
|
+
expect(plugin.logical_properties([])).to be_empty
|
84
|
+
end
|
85
|
+
|
86
|
+
it "Returns properties without values when there is no disk information" do
|
87
|
+
data = plugin.logical_properties([{}])
|
88
|
+
expect(data[nil].symbolize_keys.keys).to eq(logical_props)
|
89
|
+
expect(data[nil]["kb_used"]).to eq(0)
|
90
|
+
expect(data[nil]["fs_type"]).to be_empty
|
91
|
+
end
|
92
|
+
|
93
|
+
it "Refines required logical properties out of given instance" do
|
94
|
+
data = plugin.logical_properties(disks)
|
95
|
+
expect(data["C:"].symbolize_keys.keys).to eq(logical_props)
|
96
|
+
expect(data["D:"].symbolize_keys.keys).to eq(logical_props)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "Calculates logical properties out of given instance" do
|
100
|
+
data = plugin.logical_properties(disks)
|
101
|
+
expect(data["C:"]["kb_used"]).to eq(data["D:"]["kb_used"]).and eq(9900)
|
102
|
+
expect(data["C:"]["percent_used"]).to eq(data["D:"]["percent_used"]).and eq(99)
|
103
|
+
expect(data["C:"]["fs_type"]).to eq("ntfs")
|
104
|
+
expect(data["D:"]["fs_type"]).to eq("fat32")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#logical_info" do
|
109
|
+
it "Returns an empty mash when wmi namespace does not exists" do
|
110
|
+
allow(WmiLite::Wmi).to receive(:new).and_raise(wmi_exception)
|
111
|
+
expect(plugin.logical_info).to be_a(Mash)
|
112
|
+
expect(plugin.logical_info).to be_empty
|
113
|
+
end
|
114
|
+
|
115
|
+
it "Returns an empty mash when Win32_LogicalDisk could not be processed" do
|
116
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(success)
|
117
|
+
allow(success)
|
118
|
+
.to receive(:instances_of)
|
119
|
+
.with("Win32_LogicalDisk")
|
120
|
+
.and_raise(wmi_exception)
|
121
|
+
expect(plugin.logical_info).to be_a(Mash)
|
122
|
+
expect(plugin.logical_info).to be_empty
|
123
|
+
end
|
124
|
+
|
125
|
+
it "Returns a Mash loaded with logical details" do
|
126
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(success)
|
127
|
+
allow(success)
|
128
|
+
.to receive(:instances_of)
|
129
|
+
.with("Win32_LogicalDisk")
|
130
|
+
.and_return(logical_disks_instances)
|
131
|
+
expect(plugin.logical_info).to be_a(Mash)
|
132
|
+
expect(plugin.logical_info).not_to be_empty
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#encryption_properties" do
|
137
|
+
let(:disks) { encryptable_volume_instances }
|
138
|
+
let(:encryption_props) { [:encryption_status] }
|
139
|
+
|
140
|
+
it "Returns a mash" do
|
141
|
+
expect(plugin.encryption_properties(disks)).to be_a(Mash)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "Returns an empty mash when blank array is passed" do
|
145
|
+
expect(plugin.encryption_properties([])).to be_a(Mash)
|
146
|
+
expect(plugin.encryption_properties([])).to be_empty
|
147
|
+
end
|
148
|
+
|
149
|
+
it "Returns properties without values when there is no disk information" do
|
150
|
+
data = plugin.encryption_properties([{}])
|
151
|
+
expect(data[nil].symbolize_keys.keys).to eq(encryption_props)
|
152
|
+
expect(data[nil]["encryption_status"]).to be_empty
|
153
|
+
end
|
154
|
+
|
155
|
+
it "Refines required encryption properties out of given instance" do
|
156
|
+
data = plugin.encryption_properties(disks)
|
157
|
+
expect(data["C:"].symbolize_keys.keys).to eq(encryption_props)
|
158
|
+
expect(data["D:"].symbolize_keys.keys).to eq(encryption_props)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "Calculates encryption properties out of given instance" do
|
162
|
+
data = plugin.encryption_properties(disks)
|
163
|
+
expect(data["C:"]["encryption_status"]).to eq("FullyDecrypted")
|
164
|
+
expect(data["D:"]["encryption_status"]).to eq("EncryptionInProgress")
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#encryptable_info" do
|
169
|
+
it "Returns an empty mash when wmi namespace does not exists" do
|
170
|
+
allow(WmiLite::Wmi).to receive(:new).and_raise(wmi_exception)
|
171
|
+
expect(plugin.encryptable_info).to be_a(Mash)
|
172
|
+
expect(plugin.encryptable_info).to be_empty
|
173
|
+
end
|
174
|
+
|
175
|
+
it "Returns an empty mash when Win32_EncryptableVolume could not be processed" do
|
176
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(success)
|
177
|
+
allow(success)
|
178
|
+
.to receive(:instances_of)
|
179
|
+
.with("Win32_EncryptableVolume")
|
180
|
+
.and_raise(wmi_exception)
|
181
|
+
expect(plugin.encryptable_info).to be_a(Mash)
|
182
|
+
expect(plugin.encryptable_info).to be_empty
|
183
|
+
end
|
184
|
+
|
185
|
+
it "Returns a Mash loaded with encryption details" do
|
186
|
+
allow(WmiLite::Wmi).to receive(:new).and_return(success)
|
187
|
+
allow(success)
|
188
|
+
.to receive(:instances_of)
|
189
|
+
.with("Win32_EncryptableVolume")
|
190
|
+
.and_return(encryptable_volume_instances)
|
191
|
+
expect(plugin.encryptable_info).to be_a(Mash)
|
192
|
+
expect(plugin.encryptable_info).not_to be_empty
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe "#merge_info" do
|
197
|
+
let(:info1) do
|
198
|
+
{ "drive1" => { "x" => 10, "y" => "test1" },
|
199
|
+
"drive2" => { "x" => 20, "z" => "test2" } }
|
200
|
+
end
|
201
|
+
let(:info2) do
|
202
|
+
{ "drive1" => { "k" => 10, "l" => "test1" },
|
203
|
+
"drive2" => { "l" => 20, "m" => "test2" } }
|
204
|
+
end
|
205
|
+
let(:info3) { { "drive1" => { "o" => 10, "p" => "test1" } } }
|
206
|
+
let(:info4) { { "drive2" => { "q" => 10, "r" => "test1" } } }
|
207
|
+
|
208
|
+
it "Returns an empty mash when no info is passed" do
|
209
|
+
expect(plugin.merge_info([])).to be_a(Mash)
|
210
|
+
expect(plugin.merge_info([])).to be_empty
|
211
|
+
end
|
212
|
+
|
213
|
+
it "Merges all the various properties of filesystems" do
|
214
|
+
expect(plugin.merge_info([info1, info2, info3, info4]))
|
215
|
+
.to eq("drive1" => { "x" => 10, "y" => "test1", "k" => 10, "l" => "test1", "o" => 10, "p" => "test1" },
|
216
|
+
"drive2" => { "x" => 20, "z" => "test2", "l" => 20, "m" => "test2", "q" => 10, "r" => "test1" })
|
217
|
+
end
|
218
|
+
|
219
|
+
it "Does not affect any core information after processing" do
|
220
|
+
expect(plugin.merge_info([info3, info4])).to eq("drive1" => { "o" => 10, "p" => "test1" },
|
221
|
+
"drive2" => { "q" => 10, "r" => "test1" })
|
222
|
+
expect(info3).to eq("drive1" => { "o" => 10, "p" => "test1" })
|
223
|
+
expect(info4).to eq("drive2" => { "q" => 10, "r" => "test1" })
|
224
|
+
end
|
225
|
+
end
|
226
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 14.
|
4
|
+
version: 14.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Jacob
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: systemu
|
@@ -511,6 +511,7 @@ files:
|
|
511
511
|
- spec/unit/plugins/virtualbox_spec.rb
|
512
512
|
- spec/unit/plugins/vmware_spec.rb
|
513
513
|
- spec/unit/plugins/windows/cpu_spec.rb
|
514
|
+
- spec/unit/plugins/windows/filesystem_spec.rb
|
514
515
|
- spec/unit/plugins/windows/fips_spec.rb
|
515
516
|
- spec/unit/plugins/windows/kernel_spec.rb
|
516
517
|
- spec/unit/plugins/windows/memory_spec.rb
|