Skip to content

Commit a8a2c6e

Browse files
committed
chore: class_fibrechannel: support optional attributes
Signed-off-by: machine424 <[email protected]>
1 parent 4b77c68 commit a8a2c6e

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

sysfs/class_fibrechannel.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) {
9393
name := filepath.Join(path, f)
9494
value, err := util.SysReadFile(name)
9595
if err != nil {
96+
// drivers can choose not to expose some attributes to sysfs.
97+
// See: https://github.com/prometheus/node_exporter/issues/2919.
98+
if os.IsNotExist(err) {
99+
continue
100+
}
96101
return nil, fmt.Errorf("failed to read file %q: %w", name, err)
97102
}
98103

sysfs/class_fibrechannel_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ func TestFibreChannelClass(t *testing.T) {
6464
FCPPacketAborts: 0x13,
6565
},
6666
},
67+
"host1": FibreChannelHost{
68+
Name: "host1",
69+
PortState: "Online",
70+
},
6771
}
6872

6973
if diff := cmp.Diff(want, got); diff != "" {

testdata/fixtures.ttar

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,6 +5068,17 @@ Lines: 1
50685068
Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux
50695069
Mode: 644
50705070
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5071+
Directory: fixtures/sys/class/fc_host/host1
5072+
Mode: 755
5073+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5074+
Path: fixtures/sys/class/fc_host/host1/port_state
5075+
Lines: 1
5076+
Online
5077+
Mode: 644
5078+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5079+
Directory: fixtures/sys/class/fc_host/host1/statistics
5080+
Mode: 755
5081+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50715082
Directory: fixtures/sys/class/infiniband
50725083
Mode: 755
50735084
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)