diff mbox series

[ovs-dev,v2,2/5] northd: Use the same UUID for SB representation of Chassis_Template_Var.

Message ID 20241114074945.1278590-3-amusil@redhat.com
State Accepted
Headers show
Series Reuse UUID for SB rows if there is 1:1 mapping | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test fail github build: failed
ovsrobot/github-robot-_ovn-kubernetes fail github build: failed

Commit Message

Ales Musil Nov. 14, 2024, 7:49 a.m. UTC
The NB Chassis_Template_Var has exactly one corresponding row in SB database.
Use the NB UUID for the SB representation which makes the processing easier
and the link between the rows is obvious at first glance.

Signed-off-by: Ales Musil <amusil@redhat.com>
---
v2: Rebase on top of current main.
    Fix an issue with chassis not being reconciled.
---
 northd/northd.c     | 34 +++++++++++++++++++---------------
 tests/ovn-northd.at | 10 ++++++++++
 2 files changed, 29 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/northd/northd.c b/northd/northd.c
index 7b3ec5a85..efc7d0fd3 100644
--- a/northd/northd.c
+++ b/northd/northd.c
@@ -18499,37 +18499,41 @@  sync_template_vars(
     const struct nbrec_chassis_template_var_table *nbrec_ch_template_var_table,
     const struct sbrec_chassis_template_var_table *sbrec_ch_template_var_table)
 {
-    struct shash nb_tvs = SHASH_INITIALIZER(&nb_tvs);
-
     const struct nbrec_chassis_template_var *nb_tv;
     const struct sbrec_chassis_template_var *sb_tv;
 
-    NBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH (
-            nb_tv, nbrec_ch_template_var_table) {
-        shash_add(&nb_tvs, nb_tv->chassis, nb_tv);
-    }
-
     SBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH_SAFE (
             sb_tv, sbrec_ch_template_var_table) {
-        nb_tv = shash_find_and_delete(&nb_tvs, sb_tv->chassis);
+        nb_tv = nbrec_chassis_template_var_table_get_for_uuid(
+            nbrec_ch_template_var_table, &sb_tv->header_.uuid);
         if (!nb_tv) {
             sbrec_chassis_template_var_delete(sb_tv);
             continue;
         }
+
+        if (strcmp(sb_tv->chassis, nb_tv->chassis)) {
+            sbrec_chassis_template_var_set_chassis(sb_tv, nb_tv->chassis);
+        }
+
         if (!smap_equal(&sb_tv->variables, &nb_tv->variables)) {
-            sbrec_chassis_template_var_set_variables(sb_tv,
-                                                     &nb_tv->variables);
+            sbrec_chassis_template_var_set_variables(sb_tv, &nb_tv->variables);
         }
     }
 
-    struct shash_node *node;
-    SHASH_FOR_EACH (node, &nb_tvs) {
-        nb_tv = node->data;
-        sb_tv = sbrec_chassis_template_var_insert(ovnsb_txn);
+    NBREC_CHASSIS_TEMPLATE_VAR_TABLE_FOR_EACH (
+            nb_tv, nbrec_ch_template_var_table) {
+        const struct uuid *nb_uuid = &nb_tv->header_.uuid;
+        sb_tv = sbrec_chassis_template_var_table_get_for_uuid(
+            sbrec_ch_template_var_table, nb_uuid);
+        if (sb_tv) {
+            continue;
+        }
+
+        sb_tv = sbrec_chassis_template_var_insert_persist_uuid(ovnsb_txn,
+                                                               nb_uuid);
         sbrec_chassis_template_var_set_chassis(sb_tv, nb_tv->chassis);
         sbrec_chassis_template_var_set_variables(sb_tv, &nb_tv->variables);
     }
-    shash_destroy(&nb_tvs);
 }
 
 static void
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
index 681445c4d..73767d11b 100644
--- a/tests/ovn-northd.at
+++ b/tests/ovn-northd.at
@@ -10186,7 +10186,9 @@  check ovn-nbctl set Chassis_Template_Var hv2 variables:tv=v2
 AS_BOX([Ensure values are propagated to SB])
 check ovn-nbctl --wait=sb sync
 check_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1"
+check_column "$(fetch_column nb:Chassis_Template_Var _uuid chassis=\"hv1\")" sb:Chassis_Template_Var _uuid chassis="hv1"
 check_column "tv=v2" sb:Chassis_Template_Var variables chassis="hv2"
+check_column "$(fetch_column nb:Chassis_Template_Var _uuid chassis=\"hv2\")" sb:Chassis_Template_Var _uuid chassis="hv2"
 
 AS_BOX([Ensure SB is reconciled])
 check ovn-sbctl --all destroy Chassis_Template_Var
@@ -10194,6 +10196,14 @@  check ovn-nbctl --wait=sb sync
 check_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1"
 check_column "tv=v2" sb:Chassis_Template_Var variables chassis="hv2"
 
+AS_BOX([Ensure SB is reconciled - update])
+uuid=$(fetch_column nb:Chassis_Template_Var _uuid chassis="hv1")
+check ovn-sbctl set Chassis_Template_Var $uuid chassis="hv3"
+wait_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1"
+
+check ovn-sbctl set Chassis_Template_Var $uuid variables="tv=tv3"
+wait_column "tv=v1" sb:Chassis_Template_Var variables chassis="hv1"
+
 AS_BOX([Ensure SB is reconciled - deletion])
 check ovn-nbctl destroy Chassis_Template_Var hv1
 check ovn-nbctl --wait=sb sync