summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-12-01 13:03:23 +0100
committerThomas Haller <thaller@redhat.com>2014-12-04 17:02:22 +0100
commitb88715e05bc16c40ae68958c58aa86c2ad029a82 (patch)
tree48b5677a3005a3054cb2c983e65595e2cb69463a
parentb15994679882805f29403d9635bc0913f37e683d (diff)
downloadNetworkManager-b88715e05bc16c40ae68958c58aa86c2ad029a82.tar.gz
libnm: normalize missing connection UUID
Extend nm_connection_normalize() to add a connection UUID in case it is unset.
-rw-r--r--libnm-core/nm-connection.c19
-rw-r--r--libnm-core/nm-setting-connection.c18
-rw-r--r--libnm-core/tests/test-general.c20
3 files changed, 49 insertions, 8 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index a432baa48b..907713bd08 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -527,6 +527,24 @@ _nm_connection_find_base_type_setting (NMConnection *connection)
}
static gboolean
+_normalize_connection_uuid (NMConnection *self)
+{
+ NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
+ char *uuid;
+
+ g_assert (s_con);
+
+ if (nm_setting_connection_get_uuid (s_con))
+ return FALSE;
+
+ uuid = nm_utils_uuid_generate ();
+ g_object_set (s_con, NM_SETTING_CONNECTION_UUID, uuid, NULL);
+ g_free (uuid);
+
+ return TRUE;
+}
+
+static gboolean
_normalize_connection_type (NMConnection *self)
{
NMSettingConnection *s_con = nm_connection_get_setting_connection (self);
@@ -913,6 +931,7 @@ nm_connection_normalize (NMConnection *connection,
* We only do this, after verifying that the connection contains no un-normalizable
* errors, because in that case we rather fail without touching the settings. */
+ was_modified |= _normalize_connection_uuid (connection);
was_modified |= _normalize_connection_type (connection);
was_modified |= _normalize_connection_slave_type (connection);
was_modified |= _normalize_ip_config (connection, parameters);
diff --git a/libnm-core/nm-setting-connection.c b/libnm-core/nm-setting-connection.c
index 61293d88ab..01f5d423c1 100644
--- a/libnm-core/nm-setting-connection.c
+++ b/libnm-core/nm-setting-connection.c
@@ -777,14 +777,7 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
return FALSE;
}
- if (!priv->uuid) {
- g_set_error_literal (error,
- NM_CONNECTION_ERROR,
- NM_CONNECTION_ERROR_MISSING_PROPERTY,
- _("property is missing"));
- g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
- return FALSE;
- } else if (!nm_utils_is_uuid (priv->uuid)) {
+ if (priv->uuid && !nm_utils_is_uuid (priv->uuid)) {
g_set_error (error,
NM_CONNECTION_ERROR,
NM_CONNECTION_ERROR_INVALID_PROPERTY,
@@ -908,6 +901,15 @@ verify (NMSetting *setting, NMConnection *connection, GError **error)
/* *** errors above here should be always fatal, below NORMALIZABLE_ERROR *** */
+ if (!priv->uuid) {
+ g_set_error_literal (error,
+ NM_CONNECTION_ERROR,
+ NM_CONNECTION_ERROR_MISSING_PROPERTY,
+ _("property is missing"));
+ g_prefix_error (error, "%s.%s: ", NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_UUID);
+ return NM_SETTING_VERIFY_NORMALIZABLE_ERROR;
+ }
+
if (normerr_base_type) {
g_set_error (error,
NM_CONNECTION_ERROR,
diff --git a/libnm-core/tests/test-general.c b/libnm-core/tests/test-general.c
index 72b7765e09..990a5e0eea 100644
--- a/libnm-core/tests/test-general.c
+++ b/libnm-core/tests/test-general.c
@@ -3029,6 +3029,25 @@ test_setting_old_uuid (void)
g_assert (success == TRUE);
}
+/******************************************************************************/
+
+static void
+test_connection_normalize_uuid (void)
+{
+ gs_unref_object NMConnection *con = NULL;
+
+ con = nmtst_create_minimal_connection ("test1", NULL, NM_SETTING_WIRED_SETTING_NAME, NULL);
+
+ nmtst_assert_connection_verifies_and_normalizable (con);
+
+ g_object_set (nm_connection_get_setting_connection (con),
+ NM_SETTING_CONNECTION_UUID, NULL,
+ NULL);
+ nmtst_assert_connection_verifies_after_normalization (con, NM_CONNECTION_ERROR, NM_CONNECTION_ERROR_MISSING_PROPERTY);
+}
+
+/******************************************************************************/
+
/*
* Test normalization of interface-name
*/
@@ -3910,6 +3929,7 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/test_connection_replace_settings_bad", test_connection_replace_settings_bad);
g_test_add_func ("/core/general/test_connection_new_from_dbus", test_connection_new_from_dbus);
g_test_add_func ("/core/general/test_connection_normalize_virtual_iface_name", test_connection_normalize_virtual_iface_name);
+ g_test_add_func ("/core/general/test_connection_normalize_uuid", test_connection_normalize_uuid);
g_test_add_func ("/core/general/test_connection_normalize_type", test_connection_normalize_type);
g_test_add_func ("/core/general/test_connection_normalize_slave_type_1", test_connection_normalize_slave_type_1);
g_test_add_func ("/core/general/test_connection_normalize_slave_type_2", test_connection_normalize_slave_type_2);