Skip to content

Commit 7b6eccc

Browse files
authored
chore: class_fibrechannel: support optional attributes (#607)
Signed-off-by: machine424 <[email protected]>
1 parent da53333 commit 7b6eccc

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,26 @@ func TestFibreChannelClass(t *testing.T) {
6464
FCPPacketAborts: 0x13,
6565
},
6666
},
67+
"host1": FibreChannelHost{
68+
Name: "host1",
69+
PortState: "Online",
70+
Counters: FibreChannelCounters{
71+
DumpedFrames: 0,
72+
ErrorFrames: ^uint64(0),
73+
InvalidCRCCount: 0x20,
74+
RXFrames: 0x30,
75+
RXWords: 0x40,
76+
TXFrames: 0x50,
77+
TXWords: 0x60,
78+
SecondsSinceLastReset: 0x70,
79+
InvalidTXWordCount: 0x80,
80+
LinkFailureCount: 0x90,
81+
LossOfSyncCount: 0x100,
82+
LossOfSignalCount: 0x110,
83+
NosCount: 0x120,
84+
FCPPacketAborts: 0x130,
85+
},
86+
},
6787
}
6888

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

testdata/fixtures.ttar

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5068,6 +5068,87 @@ 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5082+
Path: fixtures/sys/class/fc_host/host1/statistics/dumped_frames
5083+
Lines: 1
5084+
0x0
5085+
Mode: 644
5086+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5087+
Path: fixtures/sys/class/fc_host/host1/statistics/error_frames
5088+
Lines: 1
5089+
0xffffffffffffffff
5090+
Mode: 644
5091+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5092+
Path: fixtures/sys/class/fc_host/host1/statistics/fcp_packet_aborts
5093+
Lines: 1
5094+
0x130
5095+
Mode: 644
5096+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5097+
Path: fixtures/sys/class/fc_host/host1/statistics/invalid_crc_count
5098+
Lines: 1
5099+
0x20
5100+
Mode: 644
5101+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5102+
Path: fixtures/sys/class/fc_host/host1/statistics/invalid_tx_word_count
5103+
Lines: 1
5104+
0x80
5105+
Mode: 644
5106+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5107+
Path: fixtures/sys/class/fc_host/host1/statistics/link_failure_count
5108+
Lines: 1
5109+
0x90
5110+
Mode: 644
5111+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5112+
Path: fixtures/sys/class/fc_host/host1/statistics/loss_of_signal_count
5113+
Lines: 1
5114+
0x110
5115+
Mode: 644
5116+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5117+
Path: fixtures/sys/class/fc_host/host1/statistics/loss_of_sync_count
5118+
Lines: 1
5119+
0x100
5120+
Mode: 644
5121+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5122+
Path: fixtures/sys/class/fc_host/host1/statistics/nos_count
5123+
Lines: 1
5124+
0x120
5125+
Mode: 644
5126+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5127+
Path: fixtures/sys/class/fc_host/host1/statistics/rx_frames
5128+
Lines: 1
5129+
0x30
5130+
Mode: 644
5131+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5132+
Path: fixtures/sys/class/fc_host/host1/statistics/rx_words
5133+
Lines: 1
5134+
0x40
5135+
Mode: 644
5136+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5137+
Path: fixtures/sys/class/fc_host/host1/statistics/seconds_since_last_reset
5138+
Lines: 1
5139+
0x70
5140+
Mode: 644
5141+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5142+
Path: fixtures/sys/class/fc_host/host1/statistics/tx_frames
5143+
Lines: 1
5144+
0x50
5145+
Mode: 644
5146+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
5147+
Path: fixtures/sys/class/fc_host/host1/statistics/tx_words
5148+
Lines: 1
5149+
0x60
5150+
Mode: 644
5151+
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50715152
Directory: fixtures/sys/class/infiniband
50725153
Mode: 755
50735154
# ttar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

0 commit comments

Comments
 (0)