Skip to content

Commit 5df14ee

Browse files
authored
bgp: remember to delete router from db (#516)
When the delete_router API endpoint was called, the router was not fully being deleted. "mgadm bgp config router list" would still display a router despite returning a 204 No Content indicating the operation was successful: ``` [trey@zebes:~/git/maghemite on main] % ./target/debug/mgadm bgp config router list [ Router { asn: 1, graceful_shutdown: false, id: 1, listen: "[::]:179", }, ] [trey@zebes:~/git/maghemite on main] % ./target/debug/mgadm bgp config router delete 1 [trey@zebes:~/git/maghemite on main] % ./target/debug/mgadm bgp config router list [ Router { asn: 1, graceful_shutdown: false, id: 1, listen: "[::]:179", }, ] ``` This is because the API handler would remove the router from the BgpContext struct, but not from the persistent sled db. This change ensures the router is removed from the sled db, not just the in-memory BgpContext data structure. Now the router gets deleted from the sled db, and mgadm properly reflects the running state: ``` [trey@zebes:~/git/maghemite on trey/fix_router_del] % ./target/debug/mgadm bgp config router list [ Router { asn: 1, graceful_shutdown: false, id: 1, listen: "[::]:179", }, ] [trey@zebes:~/git/maghemite on trey/fix_router_del] % ./target/debug/mgadm bgp config router delete 1 [trey@zebes:~/git/maghemite on trey/fix_router_del] % ./target/debug/mgadm bgp config router list [] ``` Signed-off-by: Trey Aspelund <t.k.aspelund@gmail.com>
1 parent 1732ed7 commit 5df14ee

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mgd/src/bgp_admin.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,13 @@ pub async fn delete_router(
146146
request: Query<AsnSelector>,
147147
) -> Result<HttpResponseUpdatedNoContent, HttpError> {
148148
let rq = request.into_inner();
149-
let mut routers = lock!(ctx.context().bgp.router);
149+
let ctx = ctx.context();
150+
let db = ctx.db.clone();
151+
152+
db.remove_bgp_router(rq.asn)
153+
.map_err(|e| HttpError::for_internal_error(format!("{e}")))?;
154+
155+
let mut routers = lock!(ctx.bgp.router);
150156
if let Some(r) = routers.remove(&rq.asn) {
151157
r.shutdown()
152158
};

0 commit comments

Comments
 (0)