Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node['dmi']['system']['manufacturer'] missing #1414

Closed
zmscwx opened this issue Dec 20, 2019 · 14 comments
Closed

node['dmi']['system']['manufacturer'] missing #1414

zmscwx opened this issue Dec 20, 2019 · 14 comments

Comments

@zmscwx
Copy link

zmscwx commented Dec 20, 2019

Description

Software that depends on keys placed directly in node['dmi']['system'] (as opposed to node['dmi']['system']['all_records'][0]) is failing. This affects Ohai (the virtualization plugin, specifically), and by proxy chef-sugar.

Chef Version

15.5.x and later

Platform Version

EL6 and 7

Replication Case

Run chef-shell and check the contents of node['dmi']['system'] - node['dmi']['system']['manufacturer'] should be present.

Client Output

Expected:

# chef-shell
...
chef (15.4.45)> node['dmi']['system']
 => {"all_records"=>[{"record_id"=>"0x0001", "size"=>"1", "application_identifier"=>"System Information", "Manufacturer"=>"VMware, Inc.", "Product Name"=>"VMware Virtual Platform", "Version"=>"None", "Serial Number"=>"VMware-42 2e 6b 5a df 01 5f a7-79 60 2f 6c 6c 40 cd 73", "UUID"=>"5a6b2e42-01df-a75f-7960-2f6c6c40cd73", "Wake-up Type"=>"Power Switch", "SKU Number"=>"Not Specified", "Family"=>"Not Specified"}], "manufacturer"=>"VMware, Inc.", "product_name"=>"VMware Virtual Platform", "version"=>"None", "serial_number"=>"VMware-42 2e 6b 5a df 01 5f a7-79 60 2f 6c 6c 40 cd 73", "uuid"=>"5a6b2e42-01df-a75f-7960-2f6c6c40cd73", "wake_up_type"=>"Power Switch", "sku_number"=>"Not Specified", "family"=>"Not Specified"} 

Actual:

# chef-shell
...
chef (15.6.10)> node['dmi']['system']
 => {"all_records"=>[{"record_id"=>"0x0001", "size"=>"1", "application_identifier"=>"System Information", "Manufacturer"=>"VMware, Inc.", "Product Name"=>"VMware Virtual Platform", "Version"=>"None", "Serial Number"=>"VMware-42 2e 2a a1 1b 43 c1 1c-11 30 7f d3 01 b4 aa 3f", "UUID"=>"a12a2e42-431b-1cc1-1130-7fd301b4aa3f", "Wake-up Type"=>"Power Switch", "SKU Number"=>"Not Specified", "Family"=>"Not Specified"}]} 

Stacktrace

@tas50
Copy link
Contributor

tas50 commented Dec 20, 2019

@zmscwx Can you post the output of dmidecode on this host?

@tas50 tas50 transferred this issue from chef/chef Dec 20, 2019
@zmscwx
Copy link
Author

zmscwx commented Dec 20, 2019

I don't think the /full/ output would be feasible, since it's more than I can fit in my scrollback buffer. The pertinent bits are here:

"broken" system

# dmidecode | grep -i vmware
	Manufacturer: VMware, Inc.
	Product Name: VMware Virtual Platform
	Serial Number: VMware-42 XX XX XX XX XX XX XX-XX XX XX XX XX XX XX 3f
	Description: VMware SVGA II

"good" system

# dmidecode | grep -i vmware
	Manufacturer: VMware, Inc.
	Product Name: VMware Virtual Platform
	Serial Number: VMware-42 XX XX XX XX XX XX XX-XX XX XX XX XX XX XX 73
	Description: VMware SVGA II

@sshock
Copy link
Contributor

sshock commented Dec 29, 2019

@zmscwx I think it would be helpful if you could paste the entire output of dmidecode, since the most likely reason for those to be missing is if dmidecode were returning multiple results for System Information (but that didn't match).

Alternatively, run ohai directly to get the dmi system section of the json. E.g., on my system I did this and it is working as expected:

git clone [email protected]:chef/ohai.git
cd ohai
bundle
rvmsudo bin/ohai dmi/system

{"all_records"=>
  [{"record_id"=>"0x0001",
    "size"=>"1",
    "application_identifier"=>"System Information",
    "Manufacturer"=>"Shuttle Inc.",
    "Product Name"=>"DS61",
    "Version"=>"V1.0",
    "Serial Number"=>"To be filled by O.E.M.",
    "UUID"=>"03000200-0400-0500-0006-000700080009",
    "Wake-up Type"=>"Power Switch",
    "SKU Number"=>"1.0",
    "Family"=>"D"}],
 "manufacturer"=>"Shuttle Inc.",
 "product_name"=>"DS61",
 "version"=>"V1.0",
 "serial_number"=>"To be filled by O.E.M.",
 "uuid"=>"03000200-0400-0500-0006-000700080009",
 "wake_up_type"=>"Power Switch",
 "sku_number"=>"1.0",
 "family"=>"D"}

@zmscwx
Copy link
Author

zmscwx commented Dec 30, 2019

@sshock I can confirm that /ohai/ works as intended - it's specifically in the context of the Chef run that dmi.system appears to be getting clobbered. You can see even in my simple repro case that I had to resort to using chef-shell.

To be perfectly clear, ohai dmi/system returned (my test instances got clobbered over the holidays...) the expected output on both instances. That leads me to believe that this issue doesn't lie within ohai, rather it's something to do with attribute filtering inside of chef/chef (?).

If you still think the full output of dmidecode would be useful, I'll be glad to upload it. Let me know, and I'll spin up some more test instances.

@sshock
Copy link
Contributor

sshock commented Dec 30, 2019

@zmscwx Oh, I didn't realize it is working fine for you with just ohai. In that case I don't think we need to see the full output of dmidecode, but at least the (working) output from ohai dmi/system might be helpful.

@tas50 Do you want to transfer this back to chef/chef

@zmscwx
Copy link
Author

zmscwx commented Jan 13, 2020

Sorry - I must have missed that last response. Here's the chef-shell output - Note that when compared with the ohai output below, "node['dmi']['system']['manufacturer']" is missing.

chef (15.6.19)> pp node['dmi']['system']
{"all_records"=>
  [{"record_id"=>"0x0001",
    "size"=>"1",
    "application_identifier"=>"System Information",
    "Manufacturer"=>"VMware, Inc.",
    "Product Name"=>"VMware Virtual Platform",
    "Version"=>"None",
    "Serial Number"=>"VMware-42 2e 37 e6 f9 58 36 58-0c f2 6b 30 d4 0d 19 6e",
    "UUID"=>"e6372e42-58f9-5836-0cf2-6b30d40d196e",
    "Wake-up Type"=>"Power Switch",
    "SKU Number"=>"Not Specified",
    "Family"=>"Not Specified"}]}

vs.

$ sudo ohai dmi/system
{
  "all_records": [
    {
      "record_id": "0x0001",
      "size": "1",
      "application_identifier": "System Information",
      "Manufacturer": "VMware, Inc.",
      "Product Name": "VMware Virtual Platform",
      "Version": "None",
      "Serial Number": "VMware-42 2e 37 e6 f9 58 36 58-0c f2 6b 30 d4 0d 19 6e",
      "UUID": "e6372e42-58f9-5836-0cf2-6b30d40d196e",
      "Wake-up Type": "Power Switch",
      "SKU Number": "Not Specified",
      "Family": "Not Specified"
    }
  ],
  "manufacturer": "VMware, Inc.",
  "product_name": "VMware Virtual Platform",
  "version": "None",
  "serial_number": "VMware-42 2e 37 e6 f9 58 36 58-0c f2 6b 30 d4 0d 19 6e",
  "uuid": "e6372e42-58f9-5836-0cf2-6b30d40d196e",
  "wake_up_type": "Power Switch",
  "sku_number": "Not Specified",
  "family": "Not Specified"
}

@Sliim
Copy link

Sliim commented Jan 16, 2020

I have the same issue and I think this is caused by :
https://github.com/chef/ohai/blob/v15.7.3/lib/ohai/common/dmi.rb#L120

Added a debug log to print records.class.to_s and we get:

  • In ohai:
    • records.class.to_s == Mash
  • In chef-client:
    • records.class.to_s == ChefUtils::Mash

The dmi plugin retrieve same informations with dmidecode from ohai and chef-client but the Ohai::Common::DMI.convenience_keys method don't process records due to invalid class name in chef-client run.

@zmscwx
Copy link
Author

zmscwx commented Jan 16, 2020

Interesting. Would updating chef/ohai to use records.class.kind_of? Mash be the more correct approach?

@Sliim
Copy link

Sliim commented Jan 16, 2020

This patch looks to fix the issue:

diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
index c7f8a5e1..12c166c5 100644
--- a/lib/ohai/common/dmi.rb
+++ b/lib/ohai/common/dmi.rb
@@ -116,13 +116,14 @@ module Ohai
       # for multiple occurrences of same type, copy to top level all fields and values that are common to all records
       def convenience_keys(dmi)
         dmi.each do |type, records|
+          Ohai::Log.debug("OHAI DEBUG: RECORDS/CLASS: #{records.class.to_s}")
           in_common = Mash.new
-          next unless records.class.to_s == "Mash"
+          next unless ['Mash', 'ChefUtils::Mash'].include?(records.class.to_s)
           next unless records.key?("all_records")
 
           records[:all_records].each do |record|
             record.each do |field, value|
-              next if value.class.to_s == "Mash"
+              next if ['Mash', 'ChefUtils::Mash'].include?(value.class.to_s)
               next if field.to_s == "application_identifier"
               next if field.to_s == "size"
               next if field.to_s == "record_id"

@Sliim
Copy link

Sliim commented Jan 16, 2020

@zmscwx your approach looks better, this also fix the issue:

diff --git a/lib/ohai/common/dmi.rb b/lib/ohai/common/dmi.rb
index c7f8a5e1..140af937 100644
--- a/lib/ohai/common/dmi.rb
+++ b/lib/ohai/common/dmi.rb
@@ -116,13 +116,14 @@ module Ohai
       # for multiple occurrences of same type, copy to top level all fields and values that are common to all records
       def convenience_keys(dmi)
         dmi.each do |type, records|
+          Ohai::Log.debug("OHAI DEBUG: RECORDS/CLASS: #{records.class.to_s}")
           in_common = Mash.new
-          next unless records.class.to_s == "Mash"
+          next unless records.kind_of? Mash
           next unless records.key?("all_records")
 
           records[:all_records].each do |record|
             record.each do |field, value|
-              next if value.class.to_s == "Mash"
+              next if value.kind_of? Mash
               next if field.to_s == "application_identifier"
               next if field.to_s == "size"
               next if field.to_s == "record_id"

@zmscwx
Copy link
Author

zmscwx commented Jan 20, 2020

@sshock @tas50 do either of you have input on this approach (using kind_of? in chef/ohai)? My gut says that since many other projects depend on Ohai, changes should be approached with caution.

@tas50
Copy link
Contributor

tas50 commented Jan 20, 2020

We really should have been using kind_of (or is_a) the whole time. This approach seems entirely appropriate to me. Thanks for digging into this.

#1423

@zmscwx zmscwx closed this as completed Jan 20, 2020
@zmscwx
Copy link
Author

zmscwx commented Jan 20, 2020

gladly! thank you for the quick turnaround.

@Sliim
Copy link

Sliim commented Jan 20, 2020

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants