diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index 2cb86dc98..1837942b4 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -201,13 +201,13 @@ OVS_WAIT_UNTIL([
 # This requires operator intervention and removal of the stale chassis and
 # chassis_private records.  Until that happens ovn-controller fails to
 # create the records due to constraint violation on the Encap table.
-sysid=${sysid}-foo
+new_sysid=${sysid}-foo
 current_remote=`ovs-vsctl get Open_vSwitch . external-ids:ovn-remote`
 if test X$HAVE_OPENSSL = Xyes; then
     # To change chassis name we need to change certificate with matching CN
     ovs-vsctl set-ssl \
-        $PKIDIR/testpki-${sysid}-privkey.pem \
-        $PKIDIR/testpki-${sysid}-cert.pem \
+        $PKIDIR/testpki-${new_sysid}-privkey.pem \
+        $PKIDIR/testpki-${new_sysid}-cert.pem \
         $PKIDIR/testpki-cacert.pem
     # force reconnect which makes OVN controller read the new certificates
     # TODO implement check for change of certificates in ovn-controller
@@ -221,8 +221,8 @@ if test X$HAVE_OPENSSL = Xyes; then
     OVS_WAIT_UNTIL([test x$(ovn-appctl -t ovn-controller debug/status) = "xrunning"])
 
 fi
-ovs-vsctl -- set Open_vSwitch . external-ids:hostname="${sysid}" \
-          -- set Open_vSwitch . external-ids:system-id="${sysid}" \
+ovs-vsctl -- set Open_vSwitch . external-ids:hostname="${new_sysid}" \
+          -- set Open_vSwitch . external-ids:system-id="${new_sysid}" \
           -- set Open_vSwitch . external-ids:ovn-remote="${current_remote}"
 
 OVS_WAIT_UNTIL([
@@ -233,13 +233,19 @@ OVS_WAIT_UNTIL([
 # to create new ones.
 check ovn-sbctl destroy chassis_private . -- destroy chassis .
 
-wait_row_count Chassis_Private 1 name=${sysid}
-wait_row_count Chassis 1 name=${sysid}
+wait_row_count Chassis_Private 1 name=${new_sysid}
+wait_row_count Chassis 1 name=${new_sysid}
 
 # Only one Chassis_Private/Chassis record should exist.
 wait_row_count Chassis_Private 1
 wait_row_count Chassis 1
 
+# Reset sys_id back so we can properly cleanup.
+ovs-vsctl -- set Open_vSwitch . external-ids:hostname="${sysid}" \
+          -- set Open_vSwitch . external-ids:system-id="${sysid}" \
+          -- set Open_vSwitch . external-ids:ovn-remote="${current_remote}"
+check ovn-sbctl destroy chassis_private . -- destroy chassis .
+
 # Gracefully terminate daemons
 # Ignore  following errors:
 # - Invalid ovn-bridge-mappings configuration: 'foo-mapping'
diff --git a/tests/ovn-macros.at b/tests/ovn-macros.at
index 02de7208d..61c9a2396 100644
--- a/tests/ovn-macros.at
+++ b/tests/ovn-macros.at
@@ -141,9 +141,9 @@ m4_define([CHECK_AFTER_RECOMPUTE], [
 m4_define([OVN_CLEANUP_CONTROLLER],[
     hv=$1
     sbox=$2
+    related_ports=$3
 
-    ovn-nbctl --wait=hv sync
-    as $sbox
+    CHECK_RELATED_PORTS_AFTER_RECOMPUTE([$hv], [$sbox], [$related_ports])
     if test "$hv" = "vtep"; then
         OVS_APP_EXIT_AND_WAIT([ovn-controller-vtep])
         OVS_APP_EXIT_AND_WAIT([ovs-vtep])
@@ -161,8 +161,9 @@ m4_define([OVN_CLEANUP_CONTROLLER],[
 m4_define([OVN_CLEANUP_SBOX],[
     sbox=$1
     error=$2
+    related_ports=$3
     echo "$sbox: clean up sandbox"
-    OVN_CLEANUP_CONTROLLER([$sbox], [$sbox])
+    OVN_CLEANUP_CONTROLLER([$sbox], [$sbox], [$related_ports])
     OVN_CLEANUP_VSWITCH([$sbox])
 
     # Check for errors in logs. Ignore following errors:
@@ -189,8 +190,9 @@ m4_define([OVN_CLEANUP_SBOX],[
 m4_define([OVN_CLEANUP],[
     m4_foreach([sbox_and_error], [$@], [
         sbox=$(echo "sbox_and_error" |sed -n '1p')
-        error=$(echo "sbox_and_error" | sed -n '2,$p')
-        OVN_CLEANUP_SBOX([$sbox], [$error])
+        error=$(echo "sbox_and_error"  | grep '/')
+        related_ports=$(echo "sbox_and_error" | sed -n '2,$p' | grep -v '/')
+        OVN_CLEANUP_SBOX([$sbox], [$error], [$related_ports])
     ])
 
     echo
diff --git a/tests/ovn.at b/tests/ovn.at
index 32114fffe..1ca15c9c5 100644
--- a/tests/ovn.at
+++ b/tests/ovn.at
@@ -16487,7 +16487,6 @@ AT_CHECK([test "${hv1_claims}" -le "${max_claims}"], [0], [])
 AT_CHECK([test "${hv2_claims}" -le "${max_claims}"], [0], [])
 
 check ovn-nbctl --wait=hv lsp-del lsp0
-
 CHECK_AFTER_RECOMPUTE([hv1], [hv1])
 
 OVN_CLEANUP([hv1],[hv2])
@@ -16792,7 +16791,11 @@ echo $expected_garp >> hv2/n1.expected
 OVN_CHECK_PACKETS([hv1/br-phys_n1-tx.pcap], [hv1/n1.expected])
 OVN_CHECK_PACKETS_CONTAIN([hv2/br-phys_n1-tx.pcap], [hv2/n1.expected])
 
-OVN_CLEANUP([hv1],[hv2])
+# ls0 is not local to hv1 anymore.
+# So public should not be a related_port.
+OVN_CLEANUP([hv1
+public
+],[hv2])
 
 AT_CLEANUP
 ])
@@ -24392,9 +24395,10 @@ m4_define([DVR_N_S_ARP_HANDLING],
    as hv4 ovs-appctl fdb/show br-phys
 
    # Expect some potential transaction errors for MAC_Binding
+   # Since router-to-underlay moved to hv3, ls-underlay is not local to hv1 anymore and ln3 should not be a related_port.
    OVN_CLEANUP([hv1
    /transaction error/d
-   ],[hv2
+ln3],[hv2
    /transaction error/d
    ],[hv3
    /transaction error/d
@@ -33169,7 +33173,14 @@ test_ip vif11 f00000000010 06ac10010001 $sip $dip vif-north3
 # Confirm that South to North traffic works fine.
 OVN_CHECK_PACKETS_REMOVE_BROADCAST([hv5/vif-north3-tx.pcap], [vif-north3.expected])
 
-OVN_CLEANUP([hv1],[hv2],[hv3],[hv4],[hv5])
+# Since DR-S1, DR-S2 and DR-S3 are gw-chassis on resp. hv2, hv3 and hv4,
+# S1, S2 and S3 should not be local datapaths on hv1, and their localnets
+# should not be related ports.
+OVN_CLEANUP([hv1
+ln1
+ln2
+ln3
+],[hv2],[hv3],[hv4],[hv5])
 AT_CLEANUP
 ])
 
@@ -36944,7 +36955,11 @@ OVS_WAIT_UNTIL([test `ovn-sbctl get Port_Binding lsp2 up` = 'false'])
 # Check ports are unbound
 wait_column "" Port_Binding chassis logical_port=lsp1
 wait_column "" Port_Binding chassis logical_port=lsp2
-OVN_CLEANUP([hv1])
+
+# ls1 should not be a local datapath in hv1 as vif1 iface-id has been removed.
+# Hence ln1 should not be a related port.
+OVN_CLEANUP([hv1
+ln1])
 AT_CLEANUP
 ])
 
