diff options
author | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-03 22:10:35 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2020-07-03 22:10:35 +0200 |
commit | fbac6217b101a18ef36adcaea189ce86951dfe8b (patch) | |
tree | e5fa0d554a797c5bcefdcd714e53e02494f8f2b4 | |
parent | 79f70bf5d62213e7e6ce2c5e15fdf6981dc19ef0 (diff) | |
parent | 5fa97d77962042b786208949271d127dd6eeb596 (diff) | |
download | NetworkManager-fbac6217b101a18ef36adcaea189ce86951dfe8b.tar.gz |
initrd: merge branch 'bg/initrd-bootif'
https://bugzilla.redhat.com/show_bug.cgi?id=1853277
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/562
-rw-r--r-- | src/initrd/nm-initrd-generator.c | 31 | ||||
-rw-r--r-- | src/initrd/nmi-cmdline-reader.c | 1 | ||||
-rw-r--r-- | src/initrd/tests/test-cmdline-reader.c | 41 |
3 files changed, 58 insertions, 15 deletions
diff --git a/src/initrd/nm-initrd-generator.c b/src/initrd/nm-initrd-generator.c index ac81dde03c..f984ed739c 100644 --- a/src/initrd/nm-initrd-generator.c +++ b/src/initrd/nm-initrd-generator.c @@ -130,22 +130,27 @@ main (int argc, char *argv[]) g_hash_table_foreach (connections, output_conn, connections_dir); g_hash_table_destroy (connections); - if (g_mkdir_with_parents (initrd_dir, 0755) != 0) { - errsv = errno; - _LOGW (LOGD_CORE, "%s: %s", initrd_dir, nm_strerror_native (errsv)); - return 1; - } + if (dump_to_stdout) { + if (hostname) + g_print ("\n*** Hostname '%s' ***\n", hostname); + } else { + if (g_mkdir_with_parents (initrd_dir, 0755) != 0) { + errsv = errno; + _LOGW (LOGD_CORE, "%s: %s", initrd_dir, nm_strerror_native (errsv)); + return 1; + } - if (hostname) { - gs_free char *hostname_file = NULL; - gs_free char *data = NULL; + if (hostname) { + gs_free char *hostname_file = NULL; + gs_free char *data = NULL; - hostname_file = g_strdup_printf ("%s/hostname", initrd_dir); - data = g_strdup_printf ("%s\n", hostname); + hostname_file = g_strdup_printf ("%s/hostname", initrd_dir); + data = g_strdup_printf ("%s\n", hostname); - if (!g_file_set_contents (hostname_file, data, strlen (data), &error)) { - _LOGW (LOGD_CORE, "%s: %s", hostname_file, error->message); - return 1; + if (!g_file_set_contents (hostname_file, data, strlen (data), &error)) { + _LOGW (LOGD_CORE, "%s: %s", hostname_file, error->message); + return 1; + } } } diff --git a/src/initrd/nmi-cmdline-reader.c b/src/initrd/nmi-cmdline-reader.c index e44841e683..b5fbf8305c 100644 --- a/src/initrd/nmi-cmdline-reader.c +++ b/src/initrd/nmi-cmdline-reader.c @@ -132,6 +132,7 @@ reader_get_default_connection (Reader *reader) NULL, NM_SETTING_WIRED_SETTING_NAME, NM_CONNECTION_MULTI_CONNECT_MULTIPLE); + nm_connection_add_setting (con, nm_setting_wired_new ()); reader->default_connection = con; } return reader->default_connection; diff --git a/src/initrd/tests/test-cmdline-reader.c b/src/initrd/tests/test-cmdline-reader.c index bd2104c595..c3e55998c6 100644 --- a/src/initrd/tests/test-cmdline-reader.c +++ b/src/initrd/tests/test-cmdline-reader.c @@ -1217,7 +1217,7 @@ test_rd_znet_no_ip (void) } static void -test_bootif (void) +test_bootif_ip (void) { gs_unref_hashtable GHashTable *connections = NULL; const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03", @@ -1255,6 +1255,42 @@ test_bootif (void) } static void +test_bootif_no_ip (void) +{ + gs_unref_hashtable GHashTable *connections = NULL; + const char *const*ARGV = NM_MAKE_STRV ("BOOTIF=00:53:AB:cd:02:03"); + NMConnection *connection; + NMSettingWired *s_wired; + NMSettingIPConfig *s_ip4; + NMSettingIPConfig *s_ip6; + gs_free char *hostname = NULL; + + connections = nmi_cmdline_reader_parse (TEST_INITRD_DIR "/sysfs", ARGV, &hostname); + g_assert (connections); + g_assert_cmpint (g_hash_table_size (connections), ==, 1); + g_assert_cmpstr (hostname, ==, NULL); + + connection = g_hash_table_lookup (connections, "default_connection"); + g_assert (connection); + nmtst_assert_connection_verifies_without_normalization (connection); + g_assert_cmpstr (nm_connection_get_id (connection), ==, "Wired Connection"); + + s_wired = nm_connection_get_setting_wired (connection); + g_assert_cmpstr (nm_setting_wired_get_mac_address (s_wired), ==, "00:53:AB:CD:02:03"); + g_assert (s_wired); + + 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 (nm_setting_ip_config_get_may_fail (s_ip4)); + + 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 (nm_setting_ip_config_get_may_fail (s_ip6)); +} + +static void test_bootif_hwtype (void) { gs_unref_hashtable GHashTable *connections = NULL; @@ -1410,7 +1446,8 @@ int main (int argc, char **argv) g_test_add_func ("/initrd/cmdline/rd_znet", test_rd_znet); g_test_add_func ("/initrd/cmdline/rd_znet/legacy", test_rd_znet_legacy); g_test_add_func ("/initrd/cmdline/rd_znet/no_ip", test_rd_znet_no_ip); - g_test_add_func ("/initrd/cmdline/bootif", test_bootif); + g_test_add_func ("/initrd/cmdline/bootif/ip", test_bootif_ip); + g_test_add_func ("/initrd/cmdline/bootif/no_ip", test_bootif_no_ip); g_test_add_func ("/initrd/cmdline/bootif/hwtype", test_bootif_hwtype); g_test_add_func ("/initrd/cmdline/bootif/off", test_bootif_off); |