-
Notifications
You must be signed in to change notification settings - Fork 40
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
[sled-agent] address EarlyNetworkConfig issues from 20231130 dogfood mupdate #4636
Merged
sunshowers
merged 2 commits into
main
from
sunshowers/spr/sled-agent-address-earlynetworkconfig-issues-from-20231130-dogfood-mupdate
Dec 7, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
2023-11-30 mupdate failing blob,{"generation":15,"schema_version":1,"body":{"ntp_servers":[],"rack_network_config":{"rack_subnet":"fd00:1122:3344:100::/56","infra_ip_first":"0.0.0.0","infra_ip_last":"0.0.0.0","ports":[{"routes":[],"addresses":[],"switch":"switch1","port":"qsfp0","uplink_port_speed":"speed100_g","uplink_port_fec":"none","bgp_peers":[]},{"routes":[],"addresses":["172.20.15.53/29"],"switch":"switch1","port":"qsfp18","uplink_port_speed":"speed100_g","uplink_port_fec":"rs","bgp_peers":[{"asn":65002,"port":"qsfp18","addr":"172.20.15.51","hold_time":6,"idle_hold_time":6,"delay_open":0,"connect_retry":3,"keepalive":2}]},{"routes":[],"addresses":["172.20.15.45/29"],"switch":"switch0","port":"qsfp18","uplink_port_speed":"speed100_g","uplink_port_fec":"rs","bgp_peers":[{"asn":65002,"port":"qsfp18","addr":"172.20.15.43","hold_time":6,"idle_hold_time":6,"delay_open":0,"connect_retry":3,"keepalive":2}]},{"routes":[],"addresses":[],"switch":"switch0","port":"qsfp0","uplink_port_speed":"speed100_g","uplink_port_fec":"none","bgp_peers":[]}],"bgp":[{"asn":65002,"originate":["172.20.26.0/24"]},{"asn":65002,"originate":["172.20.26.0/24"]}]}}} | ||
2023-12-06 config,{"generation":20,"schema_version":1,"body":{"ntp_servers":["ntp.example.com"],"rack_network_config":{"rack_subnet":"ff01::/32","infra_ip_first":"127.0.0.1","infra_ip_last":"127.1.0.1","ports":[{"routes":[{"destination":"10.1.9.32/16","nexthop":"10.1.9.32"}],"addresses":["2001:db8::/96"],"switch":"switch0","port":"foo","uplink_port_speed":"speed200_g","uplink_port_fec":"firecode","bgp_peers":[{"asn":65000,"port":"bar","addr":"1.2.3.4","hold_time":20,"idle_hold_time":50,"delay_open":null,"connect_retry":30,"keepalive":10}],"autoneg":true}],"bgp":[{"asn":20000,"originate":["192.168.0.0/24"]}]}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Tests that EarlyNetworkConfig deserializes across versions. | ||
|
||
use std::net::Ipv4Addr; | ||
|
||
use bootstore::schemes::v0 as bootstore; | ||
use omicron_common::api::{ | ||
external::SwitchLocation, | ||
internal::shared::{ | ||
BgpConfig, BgpPeerConfig, PortConfigV1, PortFec, PortSpeed, | ||
RackNetworkConfig, RouteConfig, | ||
}, | ||
}; | ||
use omicron_sled_agent::bootstrap::early_networking::{ | ||
EarlyNetworkConfig, EarlyNetworkConfigBody, | ||
}; | ||
use omicron_test_utils::dev::test_setup_log; | ||
|
||
const BLOB_PATH: &str = "tests/data/early_network_blobs.txt"; | ||
|
||
/// Test that previous and current versions of `EarlyNetworkConfig` blobs | ||
/// deserialize correctly. | ||
#[test] | ||
fn early_network_blobs_deserialize() { | ||
let logctx = test_setup_log("early_network_blobs_deserialize"); | ||
|
||
let (current_desc, current_config) = current_config_example(); | ||
assert!( | ||
!current_desc.contains(',') && !current_desc.contains('\n'), | ||
"current_desc must not contain commas or newlines" | ||
); | ||
|
||
// Read old blobs as newline-delimited JSON. | ||
let mut known_blobs = std::fs::read_to_string(BLOB_PATH) | ||
.expect("error reading early_network_blobs.txt"); | ||
let mut current_blob_is_known = false; | ||
for (blob_idx, line) in known_blobs.lines().enumerate() { | ||
let blob_lineno = blob_idx + 1; | ||
let (blob_desc, blob_json) = | ||
line.split_once(',').unwrap_or_else(|| { | ||
panic!( | ||
"error parsing early_network_blobs.txt \ | ||
line {blob_lineno}: missing comma", | ||
); | ||
}); | ||
|
||
// Attempt to deserialize this blob. | ||
let config = serde_json::from_str::<EarlyNetworkConfig>(blob_json) | ||
.unwrap_or_else(|error| { | ||
panic!( | ||
"error deserializing early_network_blobs.txt \ | ||
\"{blob_desc}\" (line {blob_lineno}): {error}", | ||
); | ||
}); | ||
|
||
// Does this config match the current config? | ||
if blob_desc == current_desc { | ||
assert_eq!( | ||
config, current_config, | ||
"early_network_blobs.txt line {}: {} does not match current config", | ||
blob_lineno, blob_desc | ||
); | ||
current_blob_is_known = true; | ||
} | ||
|
||
// Now attempt to put this blob into a bootstore config, and deserialize that. | ||
let network_config = bootstore::NetworkConfig { | ||
generation: config.generation, | ||
blob: blob_json.to_owned().into(), | ||
}; | ||
let config2 = EarlyNetworkConfig::deserialize_bootstore_config( | ||
&logctx.log, | ||
&network_config, | ||
).unwrap_or_else(|error| { | ||
panic!( | ||
"error deserializing early_network_blobs.txt \ | ||
\"{blob_desc}\" (line {blob_lineno}) as bootstore config: {error}", | ||
); | ||
}); | ||
|
||
assert_eq!( | ||
config, config2, | ||
"early_network_blobs.txt line {}: {} does not match deserialization \ | ||
as bootstore config", | ||
blob_lineno, blob_desc | ||
); | ||
} | ||
|
||
// If the current blob was not covered, add it to the list of known blobs. | ||
if !current_blob_is_known { | ||
let current_blob_json = serde_json::to_string(¤t_config).unwrap(); | ||
let current_blob = format!("{},{}", current_desc, current_blob_json); | ||
known_blobs.push_str(¤t_blob); | ||
known_blobs.push('\n'); | ||
} | ||
|
||
expectorate::assert_contents(BLOB_PATH, &known_blobs); | ||
|
||
logctx.cleanup_successful(); | ||
} | ||
|
||
/// Returns a current version of the EarlyNetworkConfig blob, along with a | ||
/// short description of the current version. The values can be arbitrary, but | ||
/// this should be a nontrivial blob where no vectors are empty. | ||
/// | ||
/// The goal is that if the definition of `EarlyNetworkConfig` changes in the | ||
/// future, older blobs can still be deserialized correctly. | ||
fn current_config_example() -> (&'static str, EarlyNetworkConfig) { | ||
// NOTE: the description must not contain commas or newlines. | ||
let description = "2023-12-06 config"; | ||
let config = EarlyNetworkConfig { | ||
generation: 20, | ||
schema_version: 1, | ||
body: EarlyNetworkConfigBody { | ||
ntp_servers: vec!["ntp.example.com".to_owned()], | ||
rack_network_config: Some(RackNetworkConfig { | ||
rack_subnet: "ff01::0/32".parse().unwrap(), | ||
infra_ip_first: Ipv4Addr::new(127, 0, 0, 1), | ||
infra_ip_last: Ipv4Addr::new(127, 1, 0, 1), | ||
ports: vec![PortConfigV1 { | ||
routes: vec![RouteConfig { | ||
destination: "10.1.9.32/16".parse().unwrap(), | ||
nexthop: "10.1.9.32".parse().unwrap(), | ||
}], | ||
addresses: vec!["2001:db8::/96".parse().unwrap()], | ||
switch: SwitchLocation::Switch0, | ||
port: "foo".to_owned(), | ||
uplink_port_speed: PortSpeed::Speed200G, | ||
uplink_port_fec: PortFec::Firecode, | ||
bgp_peers: vec![BgpPeerConfig { | ||
asn: 65000, | ||
port: "bar".to_owned(), | ||
addr: Ipv4Addr::new(1, 2, 3, 4), | ||
hold_time: Some(20), | ||
idle_hold_time: Some(50), | ||
delay_open: None, | ||
connect_retry: Some(30), | ||
keepalive: Some(10), | ||
}], | ||
autoneg: true, | ||
}], | ||
bgp: vec![BgpConfig { | ||
asn: 20000, | ||
originate: vec!["192.168.0.0/24".parse().unwrap()], | ||
}], | ||
}), | ||
}, | ||
}; | ||
|
||
(description, config) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
mod commands; | ||
mod early_network; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW: for little parsers like this, I really like using nom.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah definitely if it's a bit more complex than this. In this case I figured it was just splitting by comma.