Commit 9937f49a4e for frr

commit 9937f49a4e6e54ec8b9f955c5f00a3570293f925
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date:   Tue Nov 10 18:06:39 2026 +0100

    tests: cover a bfd peer keychain configured after the peer

    Nothing tests a BFD peer whose keychain is not configured yet, nor the
    removal of a keychain a peer still refers to.

    Before the peer leaf accepted it, the first step failed with:

    > % Configuration failed.
    >
    > Error type: validation
    > Error description: YANG error(s):
    >  Error: Invalid leafref value "kc2" - no target instance "/key-chain:key-chains/key-chain:key-chain/key-chain:name" with the same value.

    and, once accepted, removing the keychain left the session pointing to
    the freed keychain.

    Configure the rt1 peer with the kc2 keychain before kc2 exists, and
    check that the session stays up with the kc1 profile keychain. Then
    create kc2 and check that the peer uses it, remove it and check that
    the peer falls back to kc1 while bfdd is still running.

    Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>

diff --git a/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc1.ref b/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc1.ref
new file mode 100644
index 0000000000..bd01da76af
--- /dev/null
+++ b/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc1.ref
@@ -0,0 +1,15 @@
+[
+  {
+    "multihop": false,
+    "peer": "10.0.1.2",
+    "vrf": "default",
+    "interface": "eth-rt2",
+    "authentication": {
+      "enabled": true,
+      "key-chain-name": "kc1",
+      "key-algorithm-meticulous": true,
+      "cryptoName": "meticulous keyed-sha1"
+    },
+    "status": "up"
+  }
+]
diff --git a/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc2.ref b/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc2.ref
new file mode 100644
index 0000000000..ba14a39e7a
--- /dev/null
+++ b/tests/topotests/bfd_authentication_topo1/rt1/step5/show_bfd_peers_kc2.ref
@@ -0,0 +1,15 @@
+[
+  {
+    "multihop": false,
+    "peer": "10.0.1.2",
+    "vrf": "default",
+    "interface": "eth-rt2",
+    "authentication": {
+      "enabled": true,
+      "key-chain-name": "kc2",
+      "key-algorithm-meticulous": true,
+      "cryptoName": "meticulous keyed-sha1"
+    },
+    "status": "up"
+  }
+]
diff --git a/tests/topotests/bfd_authentication_topo1/test_bfd_authentication_topo1.py b/tests/topotests/bfd_authentication_topo1/test_bfd_authentication_topo1.py
index 8ac9ba8495..438b739dce 100644
--- a/tests/topotests/bfd_authentication_topo1/test_bfd_authentication_topo1.py
+++ b/tests/topotests/bfd_authentication_topo1/test_bfd_authentication_topo1.py
@@ -672,6 +672,74 @@ def test_bfd_authentication_sha1_auth_keychain1_meticulous_up():
     )


+def test_bfd_authentication_peer_keychain_not_configured_yet():
+    "Test BFD peer keychain not configured yet, profile keychain used"
+    logger.info("Test: BFD-AUTHEN peer keychain not configured yet")
+
+    tgen = get_topogen()
+    if not tgen.gears["rt1"].has_crypto_openssl():
+        pytest.skip("crypto-openssl disabled. skipping SHA1 test")
+
+    output = tgen.gears["rt1"].vtysh_cmd("""
+        configure terminal
+        bfd
+        peer 10.0.1.2 interface eth-rt2
+        authentication key-chain kc2
+        """)
+    assert "Configuration failed" not in output, (
+        "rt1 refuses a peer keychain not configured yet:\n" + output
+    )
+
+    # Verify BFD session stays up with the profile keychain
+    router_compare_json_output(
+        "rt1", "show bfd peers json", "step5/show_bfd_peers_kc1.ref", 20, 1
+    )
+
+
+def test_bfd_authentication_peer_keychain_configured():
+    "Test BFD peer keychain configured after the peer"
+    logger.info("Test: BFD-AUTHEN peer keychain configured after the peer")
+
+    tgen = get_topogen()
+    if not tgen.gears["rt1"].has_crypto_openssl():
+        pytest.skip("crypto-openssl disabled. skipping SHA1 test")
+
+    tgen.gears["rt1"].vtysh_cmd("""
+        configure terminal
+        key chain kc2
+        key 40
+        key-string mysecret123
+        cryptographic-algorithm hmac-sha-1
+        """)
+
+    # Verify BFD session is up with the peer keychain
+    router_compare_json_output(
+        "rt1", "show bfd peers json", "step5/show_bfd_peers_kc2.ref", 20, 1
+    )
+
+
+def test_bfd_authentication_peer_keychain_removed():
+    "Test BFD peer keychain removed, profile keychain used again"
+    logger.info("Test: BFD-AUTHEN peer keychain removed")
+
+    tgen = get_topogen()
+    if not tgen.gears["rt1"].has_crypto_openssl():
+        pytest.skip("crypto-openssl disabled. skipping SHA1 test")
+
+    tgen.gears["rt1"].vtysh_cmd("""
+        configure terminal
+        no key chain kc2
+        """)
+
+    # Verify BFD session is up with the profile keychain
+    router_compare_json_output(
+        "rt1", "show bfd peers json", "step5/show_bfd_peers_kc1.ref", 20, 1
+    )
+
+    if tgen.routers_have_failure():
+        pytest.fail(tgen.errors)
+
+
 def test_memory_leak():
     "Run the memory leak test and report results."
     tgen = get_topogen()