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
This commit is contained in:
Beniamino Galvani 2017-10-09 20:55:38 +02:00
parent 5c2c7d37c3
commit 0a7b08968d
2 changed files with 27 additions and 0 deletions

View file

@ -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);
}
}
}
}

View file

@ -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 ("{ }",