summaryrefslogtreecommitdiff
path: root/libnm-util/tests
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2013-11-29 13:13:41 +0100
committerThomas Haller <thaller@redhat.com>2014-06-30 18:35:46 +0200
commit2deaa5397a879a31c8ec0ca34553c0a97eaea69b (patch)
tree262f14267e96682c25a1ea59a319bc964be4d3c5 /libnm-util/tests
parentde5656a5707a5d2b23ec3f2738476ad59d9edd04 (diff)
downloadNetworkManager-2deaa5397a879a31c8ec0ca34553c0a97eaea69b.tar.gz
libnm-util: normalize virtual_iface_name in NMSettings
Some type-specific NMSetting implementations (bond, bridge, team, vlan) have their own 'interface-name' property. This property will be deprecated in favour of 'interface-name' in NMSettingConnection. Change verify() and normalize() to check that the redundant values match and repair/normalize the properties. Force the virtual interface name of the type-specific setting to be equal to NMSettingConnection:interface_name. This way, the depreacted field stays valid and backward compatible. NMSettingInfiniband is special, because it does not have a backing property for the interface name, although it implements get_virtual_iface_name(). To account for this, some special handling is needed in order not to change the behaviour of get_virtual_iface_name(). Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'libnm-util/tests')
-rw-r--r--libnm-util/tests/test-general.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/libnm-util/tests/test-general.c b/libnm-util/tests/test-general.c
index df62dd9344..02a2a00d94 100644
--- a/libnm-util/tests/test-general.c
+++ b/libnm-util/tests/test-general.c
@@ -2527,6 +2527,76 @@ test_connection_verify_sets_interface_name (void)
g_object_unref (con);
}
+/*
+ * Test normalization of interface-name
+ **/
+static void
+test_connection_normalize_virtual_iface_name (void)
+{
+ NMConnection *con;
+ NMSettingConnection *s_con;
+ NMSettingVlan *s_vlan;
+ NMSetting *setting;
+ GError *error = NULL;
+ gboolean success;
+ const char *IFACE_NAME = "iface";
+ const char *IFACE_VIRT = "iface-X";
+ gboolean modified = FALSE;
+
+ con = nm_connection_new ();
+
+ setting = nm_setting_ip4_config_new ();
+ g_object_set (setting,
+ NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
+ NULL);
+ nm_connection_add_setting (con, setting);
+
+ setting = nm_setting_ip6_config_new ();
+ g_object_set (setting,
+ NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
+ NM_SETTING_IP6_CONFIG_MAY_FAIL, TRUE,
+ NULL);
+ nm_connection_add_setting (con, setting);
+
+ s_con = (NMSettingConnection *) nm_setting_connection_new ();
+ g_object_set (G_OBJECT (s_con),
+ NM_SETTING_CONNECTION_ID, "test1",
+ NM_SETTING_CONNECTION_UUID, "22001632-bbb4-4616-b277-363dce3dfb5b",
+ NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME,
+ NM_SETTING_CONNECTION_INTERFACE_NAME, IFACE_NAME,
+ NULL);
+ s_vlan = (NMSettingVlan *) nm_setting_vlan_new ();
+ g_object_set (G_OBJECT (s_vlan),
+ NM_SETTING_VLAN_INTERFACE_NAME, IFACE_VIRT,
+ NM_SETTING_VLAN_PARENT, "eth0",
+ NULL);
+
+ nm_connection_add_setting (con, NM_SETTING (s_con));
+ nm_connection_add_setting (con, NM_SETTING (s_vlan));
+
+ g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
+ g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_VIRT);
+
+ /* for backward compatiblity, normalizes the interface name */
+ success = nm_connection_verify (con, &error);
+ g_assert (success && !error);
+
+ g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
+ g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_VIRT);
+
+ success = nm_connection_normalize (con, NULL, &modified, &error);
+ g_assert (success && !error);
+ g_assert (modified);
+
+ g_assert_cmpstr (nm_connection_get_interface_name (con), ==, IFACE_NAME);
+ g_assert_cmpstr (nm_setting_vlan_get_interface_name (s_vlan), ==, IFACE_NAME);
+
+ success = nm_connection_verify (con, &error);
+ g_assert (success && !error);
+
+ g_object_unref (con);
+}
+
NMTST_DEFINE ();
int main (int argc, char **argv)
@@ -2565,6 +2635,7 @@ int main (int argc, char **argv)
test_connection_replace_settings_from_connection ();
test_connection_new_from_hash ();
test_connection_verify_sets_interface_name ();
+ test_connection_normalize_virtual_iface_name ();
test_setting_connection_permissions_helpers ();
test_setting_connection_permissions_property ();