Skip to content

Commit

Permalink
Don't force-attach devinfo tree when detecting if system is a Gimlet (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker authored Feb 23, 2023
1 parent 3faa9e7 commit cb3d713
Showing 1 changed file with 1 addition and 21 deletions.
22 changes: 1 addition & 21 deletions sled-agent/src/hardware/illumos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,35 +43,15 @@ enum Error {
const GIMLET_ROOT_NODE_NAME: &str = "Oxide,Gimlet";

/// Return true if the host system is an Oxide Gimlet.
#[cfg(not(test))]
pub fn is_gimlet() -> anyhow::Result<bool> {
let mut device_info = DevInfo::new_force_load()?;
let mut device_info = DevInfo::new()?;
let mut node_walker = device_info.walk_node();
let Some(root) = node_walker.next().transpose()? else {
anyhow::bail!("No nodes in device tree");
};
Ok(root.node_name() == GIMLET_ROOT_NODE_NAME)
}

/// Return true if the host system is an Oxide Gimlet.
//
// TODO-testing: This assumes we never test on real Gimlets. That's likely to be
// a bad assumption in the long-term. For now, however, we catch permissions
// errors and return `Ok(false)`, on the assumption that (1) either you're not a
// Gimlet, so that's the correct answer or (2) if you are on a Gimlet, you are
// root or have configured the right permissions anyway.
#[cfg(test)]
pub fn is_gimlet() -> anyhow::Result<bool> {
let Ok(mut device_info) = DevInfo::new_force_load() else {
return Ok(false);
};
let mut node_walker = device_info.walk_node();
let Ok(Some(root)) = node_walker.next().transpose() else {
return Ok(false);
};
Ok(root.node_name() == GIMLET_ROOT_NODE_NAME)
}

// A snapshot of information about the underlying Tofino device
#[derive(Copy, Clone)]
struct TofinoSnapshot {
Expand Down

0 comments on commit cb3d713

Please sign in to comment.