about summary refs log tree commit diff
path: root/src/initrd/tests/test-cmdline-reader.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/initrd/tests/test-cmdline-reader.c')
-rw-r--r--src/initrd/tests/test-cmdline-reader.c101
1 files changed, 93 insertions, 8 deletions
diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c
index 8951e491..b2b06e27 100644
--- a/src/initrd/tests/test-cmdline-reader.c
+++ b/src/initrd/tests/test-cmdline-reader.c
@@ -264,7 +264,7 @@ test_if_ip6_manual (void)
 }
 
 static void
-test_multiple (void)
+test_multiple_merge (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
 	const char *const*ARGV = NM_MAKE_STRV ("ip=192.0.2.2:::::eth0",
@@ -307,6 +307,37 @@ test_multiple (void)
 }
 
 static void
+test_multiple_bootdev (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("nameserver=1.2.3.4",
+	                                       "ip=eth3:auto6",
+	                                       "ip=eth4:dhcp",
+	                                       "bootdev=eth4");
+	NMConnection *connection;
+	NMSettingIPConfig *s_ip4;
+	NMSettingIPConfig *s_ip6;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
+
+	connection = g_hash_table_lookup (connections, "eth3");
+	g_assert (connection);
+	s_ip6 = nm_connection_get_setting_ip6_config (connection);
+	g_assert (s_ip6);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
+
+	connection = g_hash_table_lookup (connections, "eth4");
+	g_assert (connection);
+	s_ip4 = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip4);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip4), ==, NM_SETTING_IP4_CONFIG_METHOD_AUTO);
+	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip4), ==, 1);
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip4, 0), ==, "1.2.3.4");
+}
+
+static void
 test_bootdev (void)
 {
 	gs_unref_hashtable GHashTable *connections = NULL;
@@ -358,16 +389,16 @@ test_some_more (void)
 	g_assert (connections);
 	g_assert_cmpint (g_hash_table_size (connections), ==, 2);
 
-	connection = g_hash_table_lookup (connections, "default_connection");
+	connection = g_hash_table_lookup (connections, "eth1");
 	g_assert (connection);
 	nmtst_assert_connection_verifies_without_normalization (connection);
 
 	s_con = nm_connection_get_setting_connection (connection);
 	g_assert (s_con);
 	g_assert_cmpstr (nm_setting_connection_get_connection_type (s_con), ==, NM_SETTING_WIRED_SETTING_NAME);
-	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "Wired Connection");
+	g_assert_cmpstr (nm_setting_connection_get_id (s_con), ==, "eth1");
 	g_assert_cmpstr (nm_setting_connection_get_interface_name (s_con), ==, "eth1");
-	g_assert_cmpint (nm_setting_connection_get_multi_connect (s_con), ==, NM_CONNECTION_MULTI_CONNECT_MULTIPLE);
+	g_assert_cmpint (nm_setting_connection_get_multi_connect (s_con), ==, NM_CONNECTION_MULTI_CONNECT_SINGLE);
 
 	s_wired = nm_connection_get_setting_wired (connection);
 	g_assert (s_wired);
@@ -409,7 +440,8 @@ test_some_more (void)
 	s_ip6 = nm_connection_get_setting_ip6_config (connection);
 	g_assert (s_ip6);
 	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_AUTO);
-	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 0);
+	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip6), ==, 1);
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip6, 0), ==, "2001:db8:3::53");
 	g_assert_cmpint (nm_setting_ip_config_get_num_routes (s_ip6), ==, 1);
 	g_assert (!nm_setting_ip_config_get_gateway (s_ip6));
 	ip_route = nm_setting_ip_config_get_route (s_ip6, 0);
@@ -991,7 +1023,7 @@ test_bootif (void)
 
 	s_ip6 = nm_connection_get_setting_ip6_config (connection);
 	g_assert (s_ip6);
-	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
 	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
 }
 
@@ -1027,7 +1059,7 @@ test_bootif_hwtype (void)
 
 	s_ip6 = nm_connection_get_setting_ip6_config (connection);
 	g_assert (s_ip6);
-	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_DISABLED);
+	g_assert_cmpstr (nm_setting_ip_config_get_method (s_ip6), ==, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
 	g_assert (!nm_setting_ip_config_get_ignore_auto_dns (s_ip6));
 
 	connection = g_hash_table_lookup (connections, "bootif_connection");
@@ -1052,6 +1084,57 @@ test_bootif_hwtype (void)
 	g_assert (nm_setting_ip_config_get_may_fail (s_ip6));
 }
 
+/* Check that nameservers are assigned to all existing
+ * connections that support the specific IPv4/IPv6 address
+ * family.
+ */
+static void
+test_nameserver (void)
+{
+	gs_unref_hashtable GHashTable *connections = NULL;
+	const char *const*ARGV = NM_MAKE_STRV ("nameserver=1.1.1.1",
+	                                       "ip=eth0:dhcp",
+	                                       "ip=eth1:auto6",
+	                                       "ip=10.11.12.13::10.11.12.1:24:foo.example.com:eth2:none",
+	                                       "nameserver=1.0.0.1",
+	                                       "nameserver=[2606:4700:4700::1111]");
+	NMConnection *connection;
+	NMSettingIPConfig *s_ip;
+
+	connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV);
+	g_assert (connections);
+	g_assert_cmpint (g_hash_table_size (connections), ==, 3);
+
+	connection = g_hash_table_lookup (connections, "eth0");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	s_ip = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip);
+	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip), ==, 2);
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip, 0), ==, "1.1.1.1");
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip, 1), ==, "1.0.0.1");
+
+	connection = g_hash_table_lookup (connections, "eth1");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	s_ip = nm_connection_get_setting_ip6_config (connection);
+	g_assert (s_ip);
+	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip), ==, 1);
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip, 0), ==, "2606:4700:4700::1111");
+
+	connection = g_hash_table_lookup (connections, "eth2");
+	g_assert (connection);
+	nmtst_assert_connection_verifies_without_normalization (connection);
+
+	s_ip = nm_connection_get_setting_ip4_config (connection);
+	g_assert (s_ip);
+	g_assert_cmpint (nm_setting_ip_config_get_num_dns (s_ip), ==, 2);
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip, 0), ==, "1.1.1.1");
+	g_assert_cmpstr (nm_setting_ip_config_get_dns (s_ip, 1), ==, "1.0.0.1");
+}
+
 static void
 test_bootif_off (void)
 {
@@ -1075,7 +1158,9 @@ int main (int argc, char **argv)
 	g_test_add_func ("/initrd/cmdline/if_auto_with_mtu_and_mac", test_if_auto_with_mtu_and_mac);
 	g_test_add_func ("/initrd/cmdline/if_ip4_manual", test_if_ip4_manual);
 	g_test_add_func ("/initrd/cmdline/if_ip6_manual", test_if_ip6_manual);
-	g_test_add_func ("/initrd/cmdline/multiple", test_multiple);
+	g_test_add_func ("/initrd/cmdline/multiple/merge", test_multiple_merge);
+	g_test_add_func ("/initrd/cmdline/multiple/bootdev", test_multiple_bootdev);
+	g_test_add_func ("/initrd/cmdline/nameserver", test_nameserver);
 	g_test_add_func ("/initrd/cmdline/some_more", test_some_more);
 	g_test_add_func ("/initrd/cmdline/bootdev", test_bootdev);
 	g_test_add_func ("/initrd/cmdline/bond", test_bond);