summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhillip Hellewell <sshock@gmail.com>2019-12-31 00:50:11 -0700
committerPhillip Hellewell <sshock@gmail.com>2019-12-31 01:11:49 -0700
commit9622d75b7974a5fb6a2bb3cc228ca51a6e454bd6 (patch)
treec7cd4b2d589a1dff346587a626b04a2904833c8f
parent37bd31de1fb9e138a25fcd3ddbcf8d16b52a46c7 (diff)
downloadohai-9622d75b7974a5fb6a2bb3cc228ca51a6e454bd6.tar.gz
Add windows drive type to filesystem plugin
Based on PR #1403, but conflicts are resolved (since the code got moved) and I included a few more specs. Signed-off-by: Phillip Hellewell <sshock@gmail.com>
-rw-r--r--lib/ohai/plugins/filesystem.rb6
-rw-r--r--spec/unit/plugins/windows/filesystem_spec.rb18
2 files changed, 23 insertions, 1 deletions
diff --git a/lib/ohai/plugins/filesystem.rb b/lib/ohai/plugins/filesystem.rb
index 483986b4..ca6e52b5 100644
--- a/lib/ohai/plugins/filesystem.rb
+++ b/lib/ohai/plugins/filesystem.rb
@@ -162,6 +162,9 @@ Ohai.plugin(:Filesystem) do
end
### Windows specific methods BEGINS
+ # Drive types
+ DRIVE_TYPE ||= %w{unknown no_root_dir removable local network cd ram}.freeze
+
# Volume encryption or decryption status
#
# @see https://docs.microsoft.com/en-us/windows/desktop/SecProv/getconversionstatus-win32-encryptablevolume#parameters
@@ -244,6 +247,9 @@ Ohai.plugin(:Filesystem) do
property[:percent_used] = (property[:kb_size] == 0 ? 0 : (property[:kb_used] * 100 / property[:kb_size]))
property[:mount] = mount
property[:fs_type] = disk["filesystem"].to_s.downcase
+ property[:drive_type] = disk["drivetype"].to_i
+ property[:drive_type_string] = DRIVE_TYPE[disk["drivetype"].to_i]
+ property[:drive_type_human] = disk["description"].to_s
property[:volume_name] = device
property[:device] = device
diff --git a/spec/unit/plugins/windows/filesystem_spec.rb b/spec/unit/plugins/windows/filesystem_spec.rb
index d3e17464..b1543603 100644
--- a/spec/unit/plugins/windows/filesystem_spec.rb
+++ b/spec/unit/plugins/windows/filesystem_spec.rb
@@ -31,6 +31,8 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
"deviceid" => "C:",
"size" => "10000000",
"filesystem" => "NTFS",
+ "drivetype" => 3,
+ "description" => "Local Fixed Disk",
"freespace" => "100000",
"name" => "C:",
# omit "volumename"; it will be added in (some) tests below
@@ -40,6 +42,8 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
"deviceid" => "D:",
"size" => "10000000",
"filesystem" => "FAT32",
+ "drivetype" => 2,
+ "description" => "Removable Disk",
"freespace" => "100000",
"name" => "D:",
# omit "volumename"; it will be added in (some) tests below
@@ -95,6 +99,9 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
it "returns disk information" do
{
"fs_type" => "ntfs",
+ "drive_type" => 3,
+ "drive_type_string" => "local",
+ "drive_type_human" => "Local Fixed Disk",
"volume_name" => "",
"encryption_status" => "FullyDecrypted",
}.each do |k, v|
@@ -104,6 +111,9 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
{
"fs_type" => "fat32",
+ "drive_type" => 2,
+ "drive_type_string" => "removable",
+ "drive_type_human" => "Removable Disk",
"volume_name" => "",
"encryption_status" => "EncryptionInProgress",
}.each do |k, v|
@@ -139,6 +149,9 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
it "returns disk information" do
{
"fs_type" => "ntfs",
+ "drive_type" => 3,
+ "drive_type_string" => "local",
+ "drive_type_human" => "Local Fixed Disk",
"volume_name" => "volume 0",
"encryption_status" => "FullyDecrypted",
}.each do |k, v|
@@ -148,6 +161,9 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
{
"fs_type" => "fat32",
+ "drive_type" => 2,
+ "drive_type_string" => "removable",
+ "drive_type_human" => "Removable Disk",
"volume_name" => "volume 1",
"encryption_status" => "EncryptionInProgress",
}.each do |k, v|
@@ -160,7 +176,7 @@ describe Ohai::System, "Windows Filesystem Plugin", :windows_only do
describe "#logical_properties" do
let(:disks) { logical_disks_instances }
- let(:logical_props) { %i{kb_size kb_available kb_used percent_used mount fs_type volume_name device} }
+ let(:logical_props) { %i{kb_size kb_available kb_used percent_used mount fs_type drive_type drive_type_string drive_type_human volume_name device} }
it "Returns a mash" do
expect(plugin.logical_properties(disks)).to be_a(Mash)