Skip to content

Commit a45b77c

Browse files
committed
Plumb transceiver error through API as a string
1 parent 07706cb commit a45b77c

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

dpd/src/transceivers/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,12 @@ impl QsfpDevice {
9494
}
9595

9696
/// The cause of a fault on a transceiver.
97-
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)]
97+
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
9898
#[serde(rename_all = "snake_case")]
9999
pub enum FaultReason {
100-
/// An error occurred accessing the transceiver.
101-
Failed,
100+
/// An error occurred accessing the transceiver, with details about the
101+
/// failure.
102+
Failed { details: String },
102103
/// Power was enabled, but did not come up in the requisite time.
103104
PowerTimeout,
104105
/// Power was enabled and later lost.

dpd/src/transceivers/tofino_impl.rs

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,8 +1109,16 @@ impl Switch {
11091109
port.as_qsfp_mut().unwrap().transceiver =
11101110
Some(Transceiver::Faulted(FaultReason::DisabledBySp));
11111111
} else if status.failures.modules.is_set(index).unwrap() {
1112+
let details = status
1113+
.failures
1114+
.errors
1115+
.get(usize::from(index))
1116+
.map(|err| err.to_string())
1117+
.unwrap_or_else(|| String::from("Unknown error"));
11121118
port.as_qsfp_mut().unwrap().transceiver =
1113-
Some(Transceiver::Faulted(FaultReason::Failed));
1119+
Some(Transceiver::Faulted(FaultReason::Failed {
1120+
details,
1121+
}));
11141122
} else {
11151123
// At this point, the transceiver is present, and so we
11161124
// _can_ check it for support. To do so requires that it be
@@ -1201,7 +1209,13 @@ impl Switch {
12011209
let new_transceiver = if unsupported.is_set(index).unwrap() {
12021210
Transceiver::Unsupported
12031211
} else if new_modules.failed.is_set(index).unwrap() {
1204-
Transceiver::Faulted(FaultReason::Failed)
1212+
let details = status
1213+
.failures
1214+
.errors
1215+
.get(usize::from(index))
1216+
.map(|err| err.to_string())
1217+
.unwrap_or_else(|| String::from("Unknown error"));
1218+
Transceiver::Faulted(FaultReason::Failed { details })
12051219
} else {
12061220
continue;
12071221
};
@@ -1327,11 +1341,28 @@ impl Switch {
13271341
transceiver.in_reset = None;
13281342
transceiver.interrupt_pending = None;
13291343
}
1330-
} else if power.failures.modules.is_set(index).unwrap()
1331-
|| vendor_info.failures.modules.is_set(index).unwrap()
1332-
{
1344+
} else if power.failures.modules.is_set(index).unwrap() {
1345+
let details = power
1346+
.failures
1347+
.errors
1348+
.get(usize::from(index))
1349+
.map(|err| err.to_string())
1350+
.unwrap_or_else(|| String::from("Unknown error"));
1351+
port_lock.lock().await.as_qsfp_mut().unwrap().transceiver =
1352+
Some(Transceiver::Faulted(FaultReason::Failed {
1353+
details,
1354+
}));
1355+
} else if vendor_info.failures.modules.is_set(index).unwrap() {
1356+
let details = vendor_info
1357+
.failures
1358+
.errors
1359+
.get(usize::from(index))
1360+
.map(|err| err.to_string())
1361+
.unwrap_or_else(|| String::from("Unknown error"));
13331362
port_lock.lock().await.as_qsfp_mut().unwrap().transceiver =
1334-
Some(Transceiver::Faulted(FaultReason::Failed));
1363+
Some(Transceiver::Faulted(FaultReason::Failed {
1364+
details,
1365+
}));
13351366
}
13361367
}
13371368

openapi/dpd.json

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5594,11 +5594,25 @@
55945594
"description": "The cause of a fault on a transceiver.",
55955595
"oneOf": [
55965596
{
5597-
"description": "An error occurred accessing the transceiver.",
5598-
"type": "string",
5599-
"enum": [
5597+
"description": "An error occurred accessing the transceiver, with details about the failure.",
5598+
"type": "object",
5599+
"properties": {
5600+
"failed": {
5601+
"type": "object",
5602+
"properties": {
5603+
"details": {
5604+
"type": "string"
5605+
}
5606+
},
5607+
"required": [
5608+
"details"
5609+
]
5610+
}
5611+
},
5612+
"required": [
56005613
"failed"
5601-
]
5614+
],
5615+
"additionalProperties": false
56025616
},
56035617
{
56045618
"description": "Power was enabled, but did not come up in the requisite time.",

swadm/src/switchport.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,13 @@ fn print_faulted_transceiver_row(
364364
port_id: &PortId,
365365
reason: &types::FaultReason,
366366
) -> anyhow::Result<()> {
367-
writeln!(tw, "{}\tfaulted ({:?})\t\t\t\t\t\t\t", port_id, reason)
367+
let reason = match reason {
368+
types::FaultReason::Failed { details } => details.as_str(),
369+
types::FaultReason::PowerTimeout => "Power timeout",
370+
types::FaultReason::PowerLost => "Power lost",
371+
types::FaultReason::DisabledBySp => "Disabled by SP",
372+
};
373+
writeln!(tw, "{}\tfaulted ({})\t\t\t\t\t\t\t", port_id, reason)
368374
.map_err(|e| e.into())
369375
}
370376

0 commit comments

Comments
 (0)