From 39619b91f96ecf599d5a262d038f3c67e5e7d7e9 Mon Sep 17 00:00:00 2001 From: machine424 Date: Mon, 19 Feb 2024 15:07:04 +0100 Subject: [PATCH] chore: class_fibrechannel: support optional attributes Signed-off-by: machine424 --- sysfs/class_fibrechannel.go | 5 +++++ sysfs/class_fibrechannel_test.go | 3 +++ testdata/fixtures.ttar | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/sysfs/class_fibrechannel.go b/sysfs/class_fibrechannel.go index d7e62784b..cb71f44c4 100644 --- a/sysfs/class_fibrechannel.go +++ b/sysfs/class_fibrechannel.go @@ -93,6 +93,11 @@ func (fs FS) parseFibreChannelHost(name string) (*FibreChannelHost, error) { name := filepath.Join(path, f) value, err := util.SysReadFile(name) if err != nil { + // drivers can choose not to expose some attributes to sysfs. + // See: https://github.com/prometheus/node_exporter/issues/2919. + if os.IsNotExist(err) { + continue + } return nil, fmt.Errorf("failed to read file %q: %w", name, err) } diff --git a/sysfs/class_fibrechannel_test.go b/sysfs/class_fibrechannel_test.go index 7181795c9..ef1d2d0e9 100644 --- a/sysfs/class_fibrechannel_test.go +++ b/sysfs/class_fibrechannel_test.go @@ -64,6 +64,9 @@ func TestFibreChannelClass(t *testing.T) { FCPPacketAborts: 0x13, }, }, + "host1": FibreChannelHost{ + Name: "host1", + }, } if diff := cmp.Diff(want, got); diff != "" { diff --git a/testdata/fixtures.ttar b/testdata/fixtures.ttar index 3fdfc5b45..aa6beda57 100644 --- a/testdata/fixtures.ttar +++ b/testdata/fixtures.ttar @@ -5068,6 +5068,12 @@ Lines: 1 Emulex SN1100E2P FV12.4.270.3 DV12.4.0.0. HN:gotest. OS:Linux Mode: 644 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/class/fc_host/host1 +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +Directory: fixtures/sys/class/fc_host/host1/statistics +Mode: 755 +# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Directory: fixtures/sys/class/infiniband Mode: 755 # ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -