Commit 189ee9d3a2 for frr

commit 189ee9d3a2baae3e1a0d6d0a0242d030b3ff9db6
Author: Lincoln Thurlow <lincoln@isi.edu>
Date:   Tue Dec 1 09:58:59 2026 -0800

    tests: check pathd after PCE restarts

    The pathd PCEP steering topotest does not check that pathd recovers
    when its PCE restarts.

    This commit adds a test that stops the mock PCE, flaps rt1's link
    while the session is down, and starts a new mock PCE, twice. Each
    time, pathd must open a new session and bring back the two base
    policies and their steering routes. Each mock PCE polls its own
    command file, so a new one does not replay the last one's commands.

    Signed-off-by: Lincoln Thurlow <lincoln@isi.edu>

diff --git a/tests/topotests/pathd_pcep_steering_topo1/test_pathd_pcep_steering_topo1.py b/tests/topotests/pathd_pcep_steering_topo1/test_pathd_pcep_steering_topo1.py
index 2bdd63da77..a65742d602 100644
--- a/tests/topotests/pathd_pcep_steering_topo1/test_pathd_pcep_steering_topo1.py
+++ b/tests/topotests/pathd_pcep_steering_topo1/test_pathd_pcep_steering_topo1.py
@@ -125,6 +125,17 @@ def teardown_module():

 # The running mock PCE
 PCE_PROC = [None]
+# Bumped on every PCE restart so each PCE instance polls a fresh
+# command file instead of replaying the previous instance's history.
+PCE_GEN = [0]
+
+
+def pce_command_file():
+    "The current PCE instance's command file"
+
+    tgen = get_topogen()
+    suffix = "" if PCE_GEN[0] == 0 else "_{}".format(PCE_GEN[0])
+    return os.path.join(tgen.logdir, "rt1", "pce_commands" + suffix)


 def start_pce():
@@ -132,7 +143,6 @@ def start_pce():

     tgen = get_topogen()
     pce_log = os.path.join(tgen.logdir, "rt1", "mock_pce.log")
-    pce_commands = os.path.join(tgen.logdir, "rt1", "pce_commands")
     PCE_PROC[0] = tgen.gears["rt1"].popen(
         [
             sys.executable,
@@ -146,7 +156,7 @@ def start_pce():
             "--pcc-address6",
             "2001:db8::1",
             "--command-file",
-            pce_commands,
+            pce_command_file(),
             "--log",
             pce_log,
         ],
@@ -321,8 +331,7 @@ def test_steering_route_reinstalled_on_policy_up():
 def pce_command(line):
     "Append one command line for the mock PCE to act on"

-    tgen = get_topogen()
-    with open(os.path.join(tgen.logdir, "rt1", "pce_commands"), "a") as cmds:
+    with open(pce_command_file(), "a") as cmds:
         cmds.write(line + "\n")


@@ -680,6 +689,78 @@ def test_steering_route_failed_replace():
     assert result is None, "sibling not removed: {}".format(result)


+def test_pce_restart():
+    "Kill and restart the PCE; policies must re-establish"
+
+    tgen = get_topogen()
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    for round_num in range(2):
+        logger.info("killing the PCE (round %d)", round_num)
+        kill_pce()
+
+        # Flap the link while the session is down: the policy status
+        # reports this fires have no session to be sent on, which is
+        # exactly the path that used to leak the formatted messages.
+        tgen.gears["rt2"].vtysh_cmd(
+            """
+            configure terminal
+             interface eth-rt1
+              shutdown
+            """
+        )
+        check = lambda: check_steering_route(False)
+        _, result = topotest.run_and_expect(check, None, count=60, wait=1)
+        assert result is None, "policy did not go down: {}".format(result)
+
+        tgen.gears["rt2"].vtysh_cmd(
+            """
+            configure terminal
+             interface eth-rt1
+              no shutdown
+            """
+        )
+        _, result = topotest.run_and_expect(
+            check_label_installed, None, count=60, wait=1
+        )
+        assert result is None, "link did not come back: {}".format(result)
+
+        logger.info("restarting the PCE (round %d)", round_num)
+        initiated = mock_pce_log_text().count("INITIATE-SENT")
+        PCE_GEN[0] += 1
+        start_pce()
+
+        # The new instance only initiates its two base policies once
+        # pathd has connected to it and completed state sync, so this
+        # proves a fresh session rather than policies kept from the old.
+        def check_new_session():
+            sent = mock_pce_log_text().count("INITIATE-SENT") - initiated
+            if sent < 2:
+                return "new PCE sent {} of 2 base policies".format(sent)
+            return None
+
+        _, result = topotest.run_and_expect(check_new_session, None, count=120, wait=1)
+        if result is not None:
+            print_pce_log()
+        assert result is None, "PCE session did not re-establish: {}".format(result)
+
+        # Whether pathd kept or timed out the old policies, it must
+        # converge back to exactly the two of them Active.
+        check = lambda: check_policy_count(2)
+        _, result = topotest.run_and_expect(check, None, count=90, wait=1)
+        if result is not None:
+            print_pce_log()
+        assert result is None, "policies did not re-establish: {}".format(result)
+
+    # The steering routes must have survived the whole exercise.
+    check = lambda: check_steering_route(True)
+    _, result = topotest.run_and_expect(check, None, count=60, wait=1)
+    if result is not None:
+        print_pce_log()
+    assert result is None, "steering route missing after restarts: {}".format(result)
+
+
 def test_steering_route_withdrawn_on_policy_delete():
     "The PCE deletes the last policy per endpoint; the steering route goes"