From c3e1290e36ece6144ecf776e873edbfd02294a53 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 11 Jan 2023 19:54:46 +0100 Subject: [PATCH] ovs: ensure existing "external-ids" get updated during reapply "mutate" with operation "insert" does not update existing entries. Delete them first. Otherwise, a reapply that only change the value of an external-ids entry does not work. Note that https://www.rfc-editor.org/rfc/rfc7047 says about "": If is "insert", then each of the key-value pairs in the map in is added to only if its key is not already present. The required type of is slightly relaxed, in that it may have fewer than the minimum number of elements specified by the column's type. Fixes: 7055539c9f7b ('core/ovs: support setting OVS external-ids') (cherry picked from commit d219527dbaf3abb9e53be3b7fafc2519c2652e64) --- src/core/devices/ovs/nm-ovsdb.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/devices/ovs/nm-ovsdb.c b/src/core/devices/ovs/nm-ovsdb.c index d3e858a19c..b9f59104bf 100644 --- a/src/core/devices/ovs/nm-ovsdb.c +++ b/src/core/devices/ovs/nm-ovsdb.c @@ -714,26 +714,27 @@ _j_create_external_ids_array_update(const char *connection_uuid, mutations = json_array(); + array = json_array(); if (exid_old) { - array = NULL; g_hash_table_iter_init(&iter, exid_old); while (g_hash_table_iter_next(&iter, (gpointer *) &key, NULL)) { - if (nm_g_hash_table_contains(exid_new, key)) - continue; - if (NM_STR_HAS_PREFIX(key, NM_OVS_EXTERNAL_ID_NM_PREFIX)) - continue; - - if (!array) - array = json_array(); - json_array_append_new(array, json_string(key)); } - if (array) { - json_array_append_new( - mutations, - json_pack("[s, s, [s, o]]", "external_ids", "delete", "set", array)); + } + if (exid_new) { + g_hash_table_iter_init(&iter, exid_new); + while (g_hash_table_iter_next(&iter, (gpointer *) &key, NULL)) { + if (nm_g_hash_table_contains(exid_old, key)) + continue; + json_array_append_new(array, json_string(key)); } } + if (!nm_g_hash_table_contains(exid_old, NM_OVS_EXTERNAL_ID_NM_PREFIX) + && !nm_g_hash_table_contains(exid_new, NM_OVS_EXTERNAL_ID_NM_PREFIX)) { + json_array_append_new(array, json_string(NM_OVS_EXTERNAL_ID_NM_PREFIX)); + } + json_array_append_new(mutations, + json_pack("[s, s, [s, o]]", "external_ids", "delete", "set", array)); array = json_array();