Allow extra option in the Open_vSwitch external_ids called
"ovn-cleanup-on-exit", this flag allows to specify whether
ovn-controller should cleanup the resources during exit. The
"--restart" exit flag still has priority over the new option in order
to keep the backward compatibility.

Reported-at: https://issues.redhat.com/browse/FDP-959
Signed-off-by: Ales Musil <amu...@redhat.com>
---
 NEWS                            |  4 +++
 controller/ovn-controller.8.xml |  7 ++++
 controller/ovn-controller.c     | 21 ++++++++++--
 tests/ovn-controller.at         | 57 +++++++++++++++++++++++++++++++++
 4 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index d1767e5b3..7023bbfe3 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,9 @@
 Post v25.03.0
 -------------
+   - Added support for "ovn-cleanup-on-exit" config option in Open_vSwitch
+     external-ids, this option allows to specify if ovn-controller should
+     perform cleanup when exiting. The "--restart" exit has always priority
+     to keep the backward compatibility.
 
 OVN v25.03.0 - xx xxx xxxx
 --------------------------
diff --git a/controller/ovn-controller.8.xml b/controller/ovn-controller.8.xml
index eace2c5cf..31f790875 100644
--- a/controller/ovn-controller.8.xml
+++ b/controller/ovn-controller.8.xml
@@ -423,6 +423,13 @@
           See the <code>ovn-nb</code>(5) for more details.
         </p>
       </dd>
+
+      <dt><code>external_ids:ovn-cleanup-on-exit</code></dt>
+      <dd>
+        The boolean flag indicates if ovn-controller should perform cleanup on
+        exit. In order to keep backward compatibility the
+        <code>--restart</code> exit flag has priority over this flag.
+      </dd>
     </dl>
 
     <p>
diff --git a/controller/ovn-controller.c b/controller/ovn-controller.c
index 081411cba..56fa0e540 100644
--- a/controller/ovn-controller.c
+++ b/controller/ovn-controller.c
@@ -884,6 +884,16 @@ get_transport_zones(const struct ovsrec_open_vswitch_table 
*ovs_table)
                                          "ovn-transport-zones", "");
 }
 
+static bool
+get_ovn_cleanup_on_exit(const struct ovsrec_open_vswitch_table *ovs_table)
+{
+    const struct ovsrec_open_vswitch *cfg =
+        ovsrec_open_vswitch_table_first(ovs_table);
+    const char *chassis_id = get_ovs_chassis_id(ovs_table);
+    return get_chassis_external_id_value_bool(&cfg->external_ids, chassis_id,
+                                              "ovn-cleanup-on-exit", true);
+}
+
 static void
 ctrl_register_ovs_idl(struct ovsdb_idl *ovs_idl)
 {
@@ -6522,8 +6532,15 @@ loop_done:
     engine_set_context(NULL);
     engine_cleanup();
 
+
+    const struct ovsrec_open_vswitch_table *ovs_table =
+        ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);
+    bool restart = exit_args.restart || !get_ovn_cleanup_on_exit(ovs_table);
+    VLOG_INFO("Exiting ovn-controller, resource cleanup: %s",
+              restart ? "False (--restart)" : "True");
+
     /* It's time to exit.  Clean up the databases if we are not restarting */
-    if (!exit_args.restart) {
+    if (!restart) {
         bool done = !ovsdb_idl_has_ever_connected(ovnsb_idl_loop.idl);
         while (!done) {
             update_sb_db(ovs_idl_loop.idl, ovnsb_idl_loop.idl,
@@ -6537,8 +6554,6 @@ loop_done:
 
             const struct ovsrec_bridge_table *bridge_table
                 = ovsrec_bridge_table_get(ovs_idl_loop.idl);
-            const struct ovsrec_open_vswitch_table *ovs_table
-                = ovsrec_open_vswitch_table_get(ovs_idl_loop.idl);
 
             const struct sbrec_port_binding_table *port_binding_table
                 = sbrec_port_binding_table_get(ovnsb_idl_loop.idl);
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
index 6561e177f..517dde1c0 100644
--- a/tests/ovn-controller.at
+++ b/tests/ovn-controller.at
@@ -3760,3 +3760,60 @@ AT_CHECK_UNQUOTED([grep "cookie=$hv3_cookie," 
phy_to_log_flows], [0], [dnl
 
 OVN_CLEANUP([hv1])
 AT_CLEANUP
+
+AT_SETUP([ovn-cntroller exit - Cleanup])
+ovn_start
+
+net_add n1
+sim_add hv1
+as hv1
+check ovs-vsctl add-br br-phys
+ovn_attach n1 br-phys 192.168.0.11 24 geneve,vxlan
+check ovn-nbctl --wait=hv sync
+
+start_controller() {
+    rm hv1/ovn-controller.log
+    start_daemon ovn-controller
+    check ovn-nbctl --wait=hv sync
+}
+
+# Stop ovn-controller, without any argument it will cleanup resources.
+check ovn-appctl -t ovn-controller exit
+check grep -q "Exiting ovn-controller, resource cleanup: True" 
hv1/ovn-controller.log
+
+# Stop ovn-controller without cleanup.
+start_controller
+check ovn-appctl -t ovn-controller exit --restart
+check grep -q "Exiting ovn-controller, resource cleanup: False (--restart)" 
hv1/ovn-controller.log
+
+# Set cleanup on exit.
+check ovs-vsctl set open . external-ids:ovn-cleanup-on_exit=true
+
+# Stop ovn-controller, without any argument it will cleanup resources.
+start_controller
+check ovn-appctl -t ovn-controller exit
+check grep -q "Exiting ovn-controller, resource cleanup: True" 
hv1/ovn-controller.log
+
+# Stop ovn-controller, --restart flag has priority over external-ids, no 
cleanup.
+start_controller
+check ovn-appctl -t ovn-controller exit --restart
+check grep -q "Exiting ovn-controller, resource cleanup: False (--restart)" 
hv1/ovn-controller.log
+
+# Set cleanup on exit to false.
+check ovs-vsctl set open . external-ids:ovn-cleanup-on-exit=false
+
+# Stop ovn-controller, without any argument it won't cleanup due to the 
external-ids.
+start_controller
+check ovn-appctl -t ovn-controller exit
+check grep -q "Exiting ovn-controller, resource cleanup: False (--restart)" 
hv1/ovn-controller.log
+
+# Stop ovn-controller without cleanup.
+start_controller
+check ovn-appctl -t ovn-controller exit --restart
+check grep -q "Exiting ovn-controller, resource cleanup: False (--restart)" 
hv1/ovn-controller.log
+
+# Start the controller so the test cleanup routing doesn't get stuck.
+start_controller
+
+OVN_CLEANUP([hv1])
+AT_CLEANUP
-- 
2.48.1

_______________________________________________
dev mailing list
d...@openvswitch.org
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to