nexus-db-queries: replace BgpPeerConfig with BgpPeerFromDb#10086
nexus-db-queries: replace BgpPeerConfig with BgpPeerFromDb#10086jgallagher wants to merge 1 commit intomainfrom
BgpPeerConfig with BgpPeerFromDb#10086Conversation
`BgpPeerConfig` was a type that contained mostly database-flavored types (`SqlU16` and friends) but had most of the same fields as the external API's `BgpPeer` type (while having no relation to the external API's `BgpPeerConfig`). This change replaces the datastore `BgpPeerConfig` with `BgpPeerFromDb`, which wraps an external API `BgpPeer` and adds the two extra fields we need in the `sync_switch_configuration` background task. The rest of the changes are fallout from that; mostly we get to get rid of a lot of `.map(|x| x.0)` or `.map(From::from)` conversions that the bg task had to do to go from "database-flavored types" to "API-flavored types". Part of #9832.
| // we can compare the rest of the struct at once, since | ||
| // `db_peer.inner.bgp_config` is always populated with an ID. | ||
| peer.bgp_config = NameOrId::Id(db_peer.bgp_config_id); | ||
| assert_eq!(peer, db_peer.inner); |
There was a problem hiding this comment.
It looks like the test failing in CI is because these two disagree on the value of interface_name:
interface_name: Name("qsfp0")
interface_name: Name("phy0")
I don't think I changed the behavior here - it looks like the test as written before omitted checking this field. Was that intentional, and there's a reason they're different? Or is the fact that they're different a bug that's just now surfacing?
There was a problem hiding this comment.
I think this mismatch is also present on main. SwitchPortBgpPeerConfig takes an explicit interface_name: Name argument:
omicron/nexus/db-model/src/switch_port.rs
Lines 780 to 786 in afe86cb
and it ignores p.interface_name (the interface name inside the networking_types::BgpPeer it's given). When we call this from do_switch_port_settings_create(), we pass the link_name, not the interface_name:
omicron/nexus/db-queries/src/db/datastore/switch_port.rs
Lines 1503 to 1508 in afe86cb
That explains why when we query this BGP config back after inserting it, we see an interface name of phy0 (the link name), not qsfp0 (the interface name inside the BgpPeer struct, which is ignored AFAICT).
I don't know what to make of this, though. Bug? Not bug just surprising behavior? More complex than either of those?
The
BgpPeerConfigexported bynexus-db-querieswas a type that contained mostly database-flavored types (SqlU16and friends) but had most of the same fields as the external API'sBgpPeertype (while having no relation to the external API'sBgpPeerConfig). This change replaces the datastoreBgpPeerConfigwithBgpPeerFromDb, which wraps an external APIBgpPeerand adds the two extra fields we need in thesync_switch_configurationbackground task.The rest of the changes are fallout from that; mostly we get to get rid of a lot of
.map(|x| x.0)or.map(From::from)conversions that the bg task had to do to go from "database-flavored types" to "API-flavored types".Part of #9832.