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
"<mutations>":

  If <mutator> is "insert", then each of the key-value pairs in
  the map in <value> is added to <column> only if its key is not
  already present.  The required type of <value> is slightly
  relaxed, in that it may have fewer than the minimum number of
  elements specified by the column's type.

Fixes: 7055539c9f ('core/ovs: support setting OVS external-ids')
This commit is contained in:
Thomas Haller 2023-01-11 19:54:46 +01:00
parent 2641af2cc9
commit d219527dba
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728

View file

@ -723,26 +723,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();