Skip to content

Plumb transceiver error through API as a string #43

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dpd/src/transceivers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ impl QsfpDevice {
}

/// The cause of a fault on a transceiver.
#[derive(Clone, Copy, Debug, Deserialize, JsonSchema, Serialize)]
#[derive(Clone, Debug, Deserialize, JsonSchema, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum FaultReason {
/// An error occurred accessing the transceiver.
Failed,
/// An error occurred accessing the transceiver, with details about the
/// failure.
Failed { details: String },
/// Power was enabled, but did not come up in the requisite time.
PowerTimeout,
/// Power was enabled and later lost.
Expand Down
43 changes: 37 additions & 6 deletions dpd/src/transceivers/tofino_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,8 +1109,16 @@ impl Switch {
port.as_qsfp_mut().unwrap().transceiver =
Some(Transceiver::Faulted(FaultReason::DisabledBySp));
} else if status.failures.modules.is_set(index).unwrap() {
let details = status
.failures
.errors
.get(usize::from(index))
.map(|err| err.to_string())
.unwrap_or_else(|| String::from("Unknown error"));
port.as_qsfp_mut().unwrap().transceiver =
Some(Transceiver::Faulted(FaultReason::Failed));
Some(Transceiver::Faulted(FaultReason::Failed {
details,
}));
} else {
// At this point, the transceiver is present, and so we
// _can_ check it for support. To do so requires that it be
Expand Down Expand Up @@ -1201,7 +1209,13 @@ impl Switch {
let new_transceiver = if unsupported.is_set(index).unwrap() {
Transceiver::Unsupported
} else if new_modules.failed.is_set(index).unwrap() {
Transceiver::Faulted(FaultReason::Failed)
let details = status
.failures
.errors
.get(usize::from(index))
.map(|err| err.to_string())
.unwrap_or_else(|| String::from("Unknown error"));
Transceiver::Faulted(FaultReason::Failed { details })
} else {
continue;
};
Expand Down Expand Up @@ -1327,11 +1341,28 @@ impl Switch {
transceiver.in_reset = None;
transceiver.interrupt_pending = None;
}
} else if power.failures.modules.is_set(index).unwrap()
|| vendor_info.failures.modules.is_set(index).unwrap()
{
} else if power.failures.modules.is_set(index).unwrap() {
let details = power
.failures
.errors
.get(usize::from(index))
.map(|err| err.to_string())
.unwrap_or_else(|| String::from("Unknown error"));
port_lock.lock().await.as_qsfp_mut().unwrap().transceiver =
Some(Transceiver::Faulted(FaultReason::Failed {
details,
}));
} else if vendor_info.failures.modules.is_set(index).unwrap() {
let details = vendor_info
.failures
.errors
.get(usize::from(index))
.map(|err| err.to_string())
.unwrap_or_else(|| String::from("Unknown error"));
port_lock.lock().await.as_qsfp_mut().unwrap().transceiver =
Some(Transceiver::Faulted(FaultReason::Failed));
Some(Transceiver::Faulted(FaultReason::Failed {
details,
}));
}
}

Expand Down
22 changes: 18 additions & 4 deletions openapi/dpd.json
Original file line number Diff line number Diff line change
Expand Up @@ -5594,11 +5594,25 @@
"description": "The cause of a fault on a transceiver.",
"oneOf": [
{
"description": "An error occurred accessing the transceiver.",
"type": "string",
"enum": [
"description": "An error occurred accessing the transceiver, with details about the failure.",
"type": "object",
"properties": {
"failed": {
"type": "object",
"properties": {
"details": {
"type": "string"
}
},
"required": [
"details"
]
}
},
"required": [
"failed"
]
],
"additionalProperties": false
},
{
"description": "Power was enabled, but did not come up in the requisite time.",
Expand Down
8 changes: 7 additions & 1 deletion swadm/src/switchport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,13 @@ fn print_faulted_transceiver_row(
port_id: &PortId,
reason: &types::FaultReason,
) -> anyhow::Result<()> {
writeln!(tw, "{}\tfaulted ({:?})\t\t\t\t\t\t\t", port_id, reason)
let reason = match reason {
types::FaultReason::Failed { details } => details.as_str(),
types::FaultReason::PowerTimeout => "Power timeout",
types::FaultReason::PowerLost => "Power lost",
types::FaultReason::DisabledBySp => "Disabled by SP",
};
writeln!(tw, "{}\tfaulted ({})\t\t\t\t\t\t\t", port_id, reason)
.map_err(|e| e.into())
}

Expand Down