Skip to content

Commit

Permalink
MGS/wicket: Add support for PSC 1 (#6996)
Browse files Browse the repository at this point in the history
Need to test this on a rack with two PSCs before merging, but running
wicket locally I think this updates all the spots where the UI needs to
show PSC 1 and allow navigating to it.

Closes #6993.
  • Loading branch information
jgallagher authored Nov 15, 2024
1 parent c703b8c commit 4d21770
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 26 deletions.
12 changes: 5 additions & 7 deletions smf/mgs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ interface = "psc0"
ignition-target = 32
location = { switch0 = ["power", 0], switch1 = ["power", 0] }

# We have an ignition-target set aside for PSC1, but do not create an
# interface for it since we don't have a second PSC.
#[[switch.port]]
#kind = "switch-zone-interface"
#interface = "psc1"
#ignition-target = 33
#location = { switch0 = ["power", 1], switch1 = ["power", 1] }
[[switch.port]]
kind = "switch-zone-interface"
interface = "psc1"
ignition-target = 33
location = { switch0 = ["power", 1], switch1 = ["power", 1] }

[[switch.port]]
kind = "switch-zone-interface"
Expand Down
7 changes: 2 additions & 5 deletions wicket/src/state/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ pub static ALL_COMPONENT_IDS: Lazy<Vec<ComponentId>> = Lazy::new(|| {
(0..=31u8)
.map(ComponentId::Sled)
.chain((0..=1u8).map(ComponentId::Switch))
// Currently shipping racks don't have PSC 1.
.chain(std::iter::once(ComponentId::Psc(0)))
.chain((0..=1u8).map(ComponentId::Psc))
.collect()
});

Expand Down Expand Up @@ -239,9 +238,7 @@ impl ComponentId {
pub const MAX_SWITCH_ID: u8 = 1;

/// The maximum possible power shelf ID.
///
/// Currently shipping racks don't have PSC 1.
pub const MAX_PSC_ID: u8 = 0;
pub const MAX_PSC_ID: u8 = 1;

pub fn new_sled(slot: u8) -> Result<Self> {
if slot > Self::MAX_SLED_ID {
Expand Down
70 changes: 58 additions & 12 deletions wicket/src/state/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ impl RackState {
ComponentId::Sled(17)
}
}
// Skip over Psc(1) because it is always empty in currently shipping
// racks.
ComponentId::Psc(0) => ComponentId::Switch(1),
ComponentId::Psc(0) => ComponentId::Psc(1),
ComponentId::Psc(1) => ComponentId::Switch(1),
_ => unreachable!(),
};
}
Expand All @@ -84,9 +83,7 @@ impl RackState {
self.selected = match self.selected {
ComponentId::Sled(16 | 17) => ComponentId::Switch(1),
ComponentId::Sled(i) => ComponentId::Sled((30 + i) % 32),
// Skip over Psc(1) because it is always empty in currently shipping
// racks.
ComponentId::Switch(1) => ComponentId::Psc(0),
ComponentId::Switch(1) => ComponentId::Psc(1),
ComponentId::Switch(0) => {
if self.left_column {
ComponentId::Sled(14)
Expand All @@ -95,6 +92,7 @@ impl RackState {
}
}
ComponentId::Psc(0) => ComponentId::Switch(0),
ComponentId::Psc(1) => ComponentId::Psc(0),
_ => unreachable!(),
};
}
Expand All @@ -114,9 +112,8 @@ impl RackState {
ComponentId::Sled(15) => ComponentId::Switch(0),
ComponentId::Sled(i) => ComponentId::Sled((i + 1) % 32),
ComponentId::Switch(0) => ComponentId::Psc(0),
// Skip over Psc(1) because it is always empty in currently shipping
// racks.
ComponentId::Psc(0) => ComponentId::Switch(1),
ComponentId::Psc(0) => ComponentId::Psc(1),
ComponentId::Psc(1) => ComponentId::Switch(1),
ComponentId::Switch(1) => ComponentId::Sled(16),
_ => unreachable!(),
};
Expand All @@ -128,9 +125,8 @@ impl RackState {
ComponentId::Sled(16) => ComponentId::Switch(1),
ComponentId::Sled(0) => ComponentId::Sled(31),
ComponentId::Sled(i) => ComponentId::Sled(i - 1),
// Skip over Psc(1) because it is always empty in currently shipping
// racks.
ComponentId::Switch(1) => ComponentId::Psc(0),
ComponentId::Switch(1) => ComponentId::Psc(1),
ComponentId::Psc(1) => ComponentId::Psc(0),
ComponentId::Psc(0) => ComponentId::Switch(0),
ComponentId::Switch(0) => ComponentId::Sled(15),
_ => unreachable!(),
Expand All @@ -149,3 +145,53 @@ impl RackState {
self.log = Some(log);
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::state::ALL_COMPONENT_IDS;

#[test]
fn prev_next_are_opposites() {
let mut state = RackState::new();

for &id in ALL_COMPONENT_IDS.iter() {
state.selected = id;
state.next();
state.prev();
assert_eq!(
state.selected, id,
"prev is not inverse of next for {id:?}"
);
state.prev();
state.next();
assert_eq!(
state.selected, id,
"next is not inverse of prev for {id:?}"
);
}
}

#[test]
fn up_down_are_opposites() {
let mut state = RackState::new();

for &id in ALL_COMPONENT_IDS.iter() {
state.selected = id;
state.set_column();

state.down();
state.up();
assert_eq!(
state.selected, id,
"up is not inverse of down for {id:?}"
);
state.up();
state.down();
assert_eq!(
state.selected, id,
"down is not inverse of up for {id:?}"
);
}
}
}
3 changes: 1 addition & 2 deletions wicket/src/ui/widgets/rack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ impl<'a> Rack<'a> {
let inner = block.inner(power_shelf);
block.render(power_shelf, buf);

if i == 0 && presence == ComponentPresence::Present {
// Shipping racks only have one power shelf -- only show that one.
if presence == ComponentPresence::Present {
let width = inner.right() - inner.left();
let step = width / 6;
let border = (width - step * 6) / 2;
Expand Down

0 comments on commit 4d21770

Please sign in to comment.