team: merge branch 'th/team-invalid-config-rh1366300'

https://bugzilla.redhat.com/show_bug.cgi?id=1366300
This commit is contained in:
Thomas Haller
2016-08-24 10:58:41 +02:00
4 changed files with 66 additions and 12 deletions

View File

@@ -28,6 +28,7 @@
#include "nm-connection.h"
#include "nm-connection-private.h"
#include "nm-utils.h"
#include "nm-utils-private.h"
#include "nm-setting-private.h"
#include "nm-core-internal.h"
@@ -907,6 +908,38 @@ _normalize_wireless_mac_address_randomization (NMConnection *self, GHashTable *p
return FALSE;
}
static gboolean
_normalize_team_config (NMConnection *self, GHashTable *parameters)
{
NMSettingTeam *s_team = nm_connection_get_setting_team (self);
if (s_team) {
const char *config = nm_setting_team_get_config (s_team);
if (config && !_nm_utils_check_valid_json (config, NULL)) {
g_object_set (s_team, NM_SETTING_TEAM_CONFIG, NULL, NULL);
return TRUE;
}
}
return FALSE;
}
static gboolean
_normalize_team_port_config (NMConnection *self, GHashTable *parameters)
{
NMSettingTeamPort *s_team_port = nm_connection_get_setting_team_port (self);
if (s_team_port) {
const char *config = nm_setting_team_port_get_config (s_team_port);
if (config && !_nm_utils_check_valid_json (config, NULL)) {
g_object_set (s_team_port, NM_SETTING_TEAM_PORT_CONFIG, NULL, NULL);
return TRUE;
}
}
return FALSE;
}
/**
* nm_connection_verify:
* @connection: the #NMConnection to verify
@@ -1150,6 +1183,8 @@ nm_connection_normalize (NMConnection *connection,
was_modified |= _normalize_infiniband_mtu (connection, parameters);
was_modified |= _normalize_bond_mode (connection, parameters);
was_modified |= _normalize_wireless_mac_address_randomization (connection, parameters);
was_modified |= _normalize_team_config (connection, parameters);
was_modified |= _normalize_team_port_config (connection, parameters);
/* Verify anew. */
success = _nm_connection_verify (connection, error);

View File

@@ -87,16 +87,6 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
{
NMSettingTeamPortPrivate *priv = NM_SETTING_TEAM_PORT_GET_PRIVATE (setting);
if (priv->config) {
if (!_nm_utils_check_valid_json (priv->config, error)) {
g_prefix_error (error,
"%s.%s: ",
NM_SETTING_TEAM_PORT_SETTING_NAME,
NM_SETTING_TEAM_PORT_CONFIG);
return FALSE;
}
}
if (connection) {
NMSettingConnection *s_con;
const char *slave_type;
@@ -125,6 +115,26 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
}
if (priv->config) {
if (!_nm_utils_check_valid_json (priv->config, error)) {
g_prefix_error (error,
"%s.%s: ",
NM_SETTING_TEAM_PORT_SETTING_NAME,
NM_SETTING_TEAM_PORT_CONFIG);
/* for backward compatibility, we accept invalid json and normalize it */
if (!priv->config[0]) {
/* be more forgiving to "" and let it verify() as valid because
* at least anaconda used to write such configs */
return NM_SETTING_VERIFY_NORMALIZABLE;
}
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
}
/* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity.
* Take care to properly order statements with priv->config above. */
return TRUE;
}

View File

@@ -94,10 +94,19 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
"%s.%s: ",
NM_SETTING_TEAM_SETTING_NAME,
NM_SETTING_TEAM_CONFIG);
return FALSE;
/* for backward compatibility, we accept invalid json and normalize it */
if (!priv->config[0]) {
/* be more forgiving to "" and let it verify() as valid because
* at least anaconda used to write such configs */
return NM_SETTING_VERIFY_NORMALIZABLE;
}
return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
}
}
/* NOTE: normalizable/normalizable-errors must appear at the end with decreasing severity.
* Take care to properly order statements with priv->config above. */
return TRUE;
}

View File

@@ -575,7 +575,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason)
* have a PID, then we must fail.
*/
cfg = teamdctl_config_get_raw (priv->tdc);
if (cfg && strcmp (cfg, nm_setting_team_get_config (s_team)) == 0) {
if (cfg && nm_streq0 (cfg, nm_setting_team_get_config (s_team))) {
_LOGD (LOGD_TEAM, "using existing matching teamd config");
return NM_ACT_STAGE_RETURN_SUCCESS;
}