diff --git a/lib/ohai/plugins/linux/lspci.rb b/lib/ohai/plugins/linux/lspci.rb index f75a0f865..f3544e37f 100644 --- a/lib/ohai/plugins/linux/lspci.rb +++ b/lib/ohai/plugins/linux/lspci.rb @@ -51,10 +51,14 @@ def standard_array(devices, d_id, tag, line) case dev[0] when "Device" # There are two different Device tags - if ( tmp = dev[1].match(/(#{hh}:#{hh}.#{h})/) ) + if ( tmp = dev[1].match(/(#{hhhh}:)?(#{hh}:#{hh}\.#{h})/) ) # We have a device id d_id = tmp[0] # From now on we will need this id devices[d_id] = Mash.new + if tmp[1] + # We have a root complex + devices[d_id]["root_port"] = tmp[1][0..-2] + end else standard_form(devices, d_id, hhhh, "device", dev[1]) end diff --git a/spec/unit/plugins/linux/lspci_spec.rb b/spec/unit/plugins/linux/lspci_spec.rb index 6df3399ec..c3d9cf583 100644 --- a/spec/unit/plugins/linux/lspci_spec.rb +++ b/spec/unit/plugins/linux/lspci_spec.rb @@ -86,6 +86,14 @@ Driver: nvme Module: nvme NUMANode: 0 + + Device: 0005:00:00.0 + Class: PCI bridge [0604] + Vendor: Intel Corporation [8086] + Device: C620 Series Chipset Family PCI Express Root Port #1 [a190] + Rev: f9 + Driver: pcieport + NUMANode: 0 LSPCI allow(plugin).to receive(:shell_out).with("lspci -vnnmk").and_return( mock_shell_out(0, @stdout, "") @@ -96,7 +104,7 @@ it "lists all devices" do plugin.run expect(plugin[:pci].keys).to eq( - ["00:1f.3", "00:1f.4", "00:1f.6", "02:00.0", "04:00.0", "05:00.0"] + ["00:1f.3", "00:1f.4", "00:1f.6", "02:00.0", "04:00.0", "05:00.0", "0005:00:00.0"] ) end @@ -129,5 +137,11 @@ expect(plugin[:pci]["04:00.0"]["driver"]).to eq(["iwlwifi"]) expect(plugin[:pci]["04:00.0"]["module"]).to eq(["iwlwifi"]) end + + it "populates the root port field" do + plugin.run + expect(plugin[:pci]["0005:00:00.0"]["driver"]).to eq(["pcieport"]) + expect(plugin[:pci]["0005:00:00.0"]["root_port"]).to eq("0005") + end end end