From 0a7b08968d313a7dcd55ba8b50365fe20c301aff Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Mon, 9 Oct 2017 20:55:38 +0200 Subject: [PATCH] libnm-core: normalize "tx_hash" when comparing team config teamd adds the "tx_hash" property for "lacp" and "loadbalance" runners when not present. Do the same so that our original configuration matches with the one reported by teamd. https://bugzilla.redhat.com/show_bug.cgi?id=1497333 --- libnm-core/nm-utils.c | 11 +++++++++++ libnm-core/tests/test-general.c | 16 ++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/libnm-core/nm-utils.c b/libnm-core/nm-utils.c index b3c3fc5d68..7e96184340 100644 --- a/libnm-core/nm-utils.c +++ b/libnm-core/nm-utils.c @@ -4355,6 +4355,7 @@ _nm_utils_team_config_equal (const char *conf1, gboolean port_config) { json_t *json1 = NULL, *json2 = NULL, *json; + json_t *array, *name; gs_free char *dump1 = NULL, *dump2 = NULL; json_t *value, *property; json_error_t jerror; @@ -4394,6 +4395,16 @@ _nm_utils_team_config_equal (const char *conf1, property = json_object (); json_object_set_new (property, "name", json_string ("roundrobin")); json_object_set_new (json, "runner", property); + } else if ( (name = json_object_get (property, "name")) + && NM_IN_STRSET (json_string_value (name), "lacp", "loadbalance")) { + /* Add default tx_hash when missing */ + if (!json_object_get (property, "tx_hash")) { + array = json_array (); + json_array_append_new (array, json_string ("eth")); + json_array_append_new (array, json_string ("ipv4")); + json_array_append_new (array, json_string ("ipv6")); + json_object_set_new (property, "tx_hash", array); + } } } } diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c index 8c4d120d11..5f4540c57a 100644 --- a/libnm-core/tests/test-general.c +++ b/libnm-core/tests/test-general.c @@ -5562,10 +5562,26 @@ test_nm_utils_team_config_equal (void) "{ \"runner\" : { \"name\" : \"random\"} }", FALSE, TRUE); + _team_config_equal_check ("{ \"runner\" : { \"name\" : \"loadbalance\"} }", + "{ \"runner\" : { \"name\" : \"loadbalance\"} }", + FALSE, + TRUE); _team_config_equal_check ("{ \"runner\" : { \"name\" : \"random\"}, \"ports\" : { \"eth0\" : {} } }", "{ \"runner\" : { \"name\" : \"random\"}, \"ports\" : { \"eth1\" : {} } }", FALSE, TRUE); + _team_config_equal_check ("{ \"runner\" : { \"name\" : \"lacp\"} }", + "{ \"runner\" : { \"name\" : \"lacp\", \"tx_hash\" : [ \"eth\", \"ipv4\", \"ipv6\" ] } }", + FALSE, + TRUE); + _team_config_equal_check ("{ \"runner\" : { \"name\" : \"roundrobin\"} }", + "{ \"runner\" : { \"name\" : \"roundrobin\", \"tx_hash\" : [ \"eth\", \"ipv4\", \"ipv6\" ] } }", + FALSE, + FALSE); + _team_config_equal_check ("{ \"runner\" : { \"name\" : \"lacp\"} }", + "{ \"runner\" : { \"name\" : \"lacp\", \"tx_hash\" : [ \"eth\" ] } }", + FALSE, + FALSE); /* team port config */ _team_config_equal_check ("{ }",