Skip to content

Commit 3c58a05

Browse files
qmonnetFredi-raspall
authored andcommitted
fix(vpcpeering): Do not insert peering with duplicate name
When we try to insert a peering with a name that already exists for another peering in a VpcPeeringTable, this results in an error, but it also results in the peering being inserted anyway, as we only detect the name collision when inserting (and we do not implement rollback). As a consequence, we keep an incorrect peering entry in the table. This can cause unexpected collisions on prefixes when trying to add subsequent, legitimate peerings to the table, for example. Instead of inserting unconditionally, let's check first for the existence of the peering name in the table. Fixes: e45c0ef (feat(mgmt): define external model) Signed-off-by: Quentin Monnet <[email protected]>
1 parent 6648e73 commit 3c58a05

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mgmt/src/models/external/overlay/vpcpeering.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,11 @@ impl VpcPeeringTable {
313313
peering.validate()?;
314314
self.validate_peering_addition(&peering)?;
315315

316+
// First look for an existing entry, to avoid inserting a duplicate peering
317+
if self.0.contains_key(&peering.name) {
318+
return Err(ApiError::DuplicateVpcPeeringId(peering.name.clone()));
319+
}
320+
316321
if let Some(peering) = self.0.insert(peering.name.to_owned(), peering) {
317322
Err(ConfigError::DuplicateVpcPeeringId(peering.name.clone()))
318323
} else {
@@ -772,18 +777,13 @@ mod tests {
772777
.as_range(prefix_v4("6.0.0.0/16")),
773778
)
774779
.expect("Failed to add expose");
775-
/*
776-
// This test does insert the peering in the table even though we get an error, which makes
777-
// the subsequent test fail because of overlapping prefixes. Will be fixed in the next
778-
// commit.
779780
let peering3 = VpcPeering::new("test_peering1", manifest3.clone(), manifest4.clone());
780781
assert_eq!(
781782
table.add(peering3),
782783
Err(ConfigError::DuplicateVpcPeeringId(
783784
"test_peering1".to_string()
784785
))
785786
);
786-
*/
787787

788788
let peering4 = VpcPeering::new("test_peering4", manifest3.clone(), manifest4.clone());
789789
assert_eq!(table.add(peering4), Ok(()));

0 commit comments

Comments
 (0)