diff options
author | Thomas Haller <thaller@redhat.com> | 2016-08-26 12:55:51 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-08-26 12:57:14 +0200 |
commit | 9f4ce4e2836e9079392e606eaeaedaf550e22d31 (patch) | |
tree | ac9b0b0c080c285adc1478ee004173ac6c56fd9e | |
parent | 1d909f422900af442f7946a2775564f4567ebe9e (diff) | |
parent | a82b7c8d5e5753ebdf92b285cfc3ed74208d8901 (diff) |
ifcfg-rh: merge branch 'th/ifcfg-rh-read-team-rh1367180'
https://bugzilla.redhat.com/show_bug.cgi?id=1367180
(cherry picked from commit cbbc8620a1442d1801e8ef2d0fd27a38fbadc4f8)
-rw-r--r-- | src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c | 4 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/reader.c | 57 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am | 6 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 (renamed from src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master) | 0 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 | 5 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 (renamed from src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port) | 0 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 | 4 | ||||
-rw-r--r-- | src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 28 |
8 files changed, 62 insertions, 42 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c index 82f2059854..184e95b2aa 100644 --- a/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c +++ b/src/settings/plugins/ifcfg-rh/nm-ifcfg-connection.c @@ -395,7 +395,9 @@ commit_changes (NMSettingsConnection *connection, */ filename = nm_settings_connection_get_filename (connection); if (filename) { - reread = connection_from_file (filename, NULL, NULL, NULL); + gs_free char *unhandled = NULL; + + reread = connection_from_file (filename, &unhandled, NULL, NULL); if (reread) { same = nm_connection_compare (NM_CONNECTION (connection), reread, diff --git a/src/settings/plugins/ifcfg-rh/reader.c b/src/settings/plugins/ifcfg-rh/reader.c index af5d291026..d1ea597a68 100644 --- a/src/settings/plugins/ifcfg-rh/reader.c +++ b/src/settings/plugins/ifcfg-rh/reader.c @@ -1621,26 +1621,29 @@ check_if_bond_slave (shvarFile *ifcfg, */ } -static void +static gboolean check_if_team_slave (shvarFile *ifcfg, NMSettingConnection *s_con) { - char *value; + gs_free char *value = NULL; - value = svGetValue (ifcfg, "DEVICETYPE", FALSE); - if (!value) - return; - if (strcasecmp (value, TYPE_TEAM_PORT)) { - g_free (value); - return; - } - g_free (value); value = svGetValue (ifcfg, "TEAM_MASTER", FALSE); if (!value) - return; + return FALSE; g_object_set (s_con, NM_SETTING_CONNECTION_MASTER, value, NULL); g_object_set (s_con, NM_SETTING_CONNECTION_SLAVE_TYPE, NM_SETTING_TEAM_SETTING_NAME, NULL); - g_free (value); + return TRUE; +} + +static void +check_if_slave (shvarFile *ifcfg, + NMSettingConnection *s_con) +{ + g_return_if_fail (NM_IS_SETTING_CONNECTION (s_con)); + + if (check_if_team_slave (ifcfg, s_con)) + return; + check_if_bond_slave (ifcfg, s_con); } typedef struct { @@ -3948,8 +3951,7 @@ wired_connection_from_ifcfg (const char *file, g_object_unref (connection); return NULL; } - check_if_bond_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); - check_if_team_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); nm_connection_add_setting (connection, con_setting); wired_setting = make_wired_setting (ifcfg, file, &s_8021x, error); @@ -4099,8 +4101,7 @@ infiniband_connection_from_ifcfg (const char *file, g_object_unref (connection); return NULL; } - check_if_bond_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); - check_if_team_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); nm_connection_add_setting (connection, con_setting); infiniband_setting = make_infiniband_setting (ifcfg, file, error); @@ -4599,8 +4600,6 @@ is_bond_device (const char *name, shvarFile *parsed) if (svGetValueBoolean (parsed, "BONDING_MASTER", FALSE)) return TRUE; - - /* XXX: Check for "bond[\d]+"? */ return FALSE; } @@ -4816,8 +4815,7 @@ vlan_connection_from_ifcfg (const char *file, g_object_unref (connection); return NULL; } - check_if_bond_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); - check_if_team_slave (ifcfg, NM_SETTING_CONNECTION (con_setting)); + check_if_slave (ifcfg, (NMSettingConnection *) con_setting); nm_connection_add_setting (connection, con_setting); vlan_setting = make_vlan_setting (ifcfg, file, error); @@ -4848,7 +4846,7 @@ create_unhandled_connection (const char *filename, shvarFile *ifcfg, NMSetting *s_con; char *value; - g_assert (out_spec != NULL); + nm_assert (out_spec && !*out_spec); connection = nm_simple_connection_new (); @@ -4963,8 +4961,7 @@ connection_from_file_full (const char *filename, const char *ifcfg_name = NULL; g_return_val_if_fail (filename != NULL, NULL); - if (out_unhandled) - g_return_val_if_fail (*out_unhandled == NULL, NULL); + g_return_val_if_fail (out_unhandled && !*out_unhandled, NULL); /* Non-NULL only for unit tests; normally use /etc/sysconfig/network */ if (!network_file) @@ -4982,8 +4979,6 @@ connection_from_file_full (const char *filename, return NULL; if (!svGetValueBoolean (parsed, "NM_CONTROLLED", TRUE)) { - g_assert (out_unhandled != NULL); - connection = create_unhandled_connection (filename, parsed, "unmanaged", out_unhandled); if (!connection) g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_FAILED, @@ -5011,6 +5006,16 @@ connection_from_file_full (const char *filename, type = g_strdup (TYPE_ETHERNET); g_free (devtype); } + if (!type) { + gs_free char *t = NULL; + + /* Team and TeamPort types are also accepted by the mere + * presense of TEAM_CONFIG/TEAM_MASTER. They don't require + * DEVICETYPE. */ + t = svGetValue (parsed, "TEAM_CONFIG", FALSE); + if (t) + type = g_strdup (TYPE_TEAM); + } if (!type) type = svGetValue (parsed, "TYPE", FALSE); @@ -5136,8 +5141,6 @@ connection_from_file_full (const char *filename, else if (!strcasecmp (type, TYPE_BRIDGE)) connection = bridge_connection_from_ifcfg (filename, parsed, error); else { - g_assert (out_unhandled != NULL); - connection = create_unhandled_connection (filename, parsed, "unrecognized", out_unhandled); if (!connection) PARSE_WARNING ("connection type was unrecognized but device was not uniquely identified; device may be managed"); diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am index fc759e6d32..7531ec0388 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/Makefile.am @@ -132,8 +132,10 @@ EXTRA_DIST = \ ifcfg-test-dcb-pgpct-not-100 \ ifcfg-test-fcoe-fabric \ ifcfg-test-fcoe-vn2vn \ - ifcfg-test-team-master \ - ifcfg-test-team-port \ + ifcfg-test-team-master-1 \ + ifcfg-test-team-master-2 \ + ifcfg-test-team-port-1 \ + ifcfg-test-team-port-2 \ ifcfg-test-team-port-empty-config \ ifcfg-test-vlan-trailing-spaces \ ifcfg-test-dns-options \ diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 index 7edc736af0..7edc736af0 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-1 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 new file mode 100644 index 0000000000..d01e37c552 --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-master-2 @@ -0,0 +1,5 @@ +DEVICE=team0 +ONBOOT=no +BOOTPROTO=dhcp +TEAM_CONFIG="{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }" + diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 index 966bec6777..966bec6777 100644 --- a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-1 diff --git a/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 new file mode 100644 index 0000000000..992510ee0a --- /dev/null +++ b/src/settings/plugins/ifcfg-rh/tests/network-scripts/ifcfg-test-team-port-2 @@ -0,0 +1,4 @@ +TYPE=Ethernet +TEAM_PORT_CONFIG="{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }" +DEVICE=p4p1 +TEAM_MASTER=team0 diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index b73f2f5f25..3e3f7ca4f5 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -67,11 +67,14 @@ _connection_from_file (const char *filename, { NMConnection *connection; GError *error = NULL; + char *unhandled_fallback = NULL; g_assert (!out_unhandled || !*out_unhandled); - connection = connection_from_file_test (filename, network_file, test_type, out_unhandled, &error); + connection = connection_from_file_test (filename, network_file, test_type, + out_unhandled ?: &unhandled_fallback, &error); g_assert_no_error (error); + g_assert (!unhandled_fallback); if (out_unhandled && *out_unhandled) nmtst_assert_connection_verifies (connection); @@ -89,13 +92,12 @@ _connection_from_file_fail (const char *filename, NMConnection *connection; GError *local = NULL; char *unhandled = NULL; - char **p_unhandled = (nmtst_get_rand_int () % 2) ? &unhandled : NULL; - connection = connection_from_file_test (filename, network_file, test_type, p_unhandled, &local); + connection = connection_from_file_test (filename, network_file, test_type, &unhandled, &local); g_assert (!connection); g_assert (local); - g_assert (!p_unhandled || !*p_unhandled); + g_assert (!unhandled); g_propagate_error (error, local); } @@ -8428,15 +8430,15 @@ test_write_fcoe_mode (gconstpointer user_data) } static void -test_read_team_master (void) +test_read_team_master (gconstpointer user_data) { + const char *const PATH_NAME = user_data; NMConnection *connection; NMSettingConnection *s_con; NMSettingTeam *s_team; const char *expected_config = "{ \"device\": \"team0\", \"link_watch\": { \"name\": \"ethtool\" } }"; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master", - NULL, TYPE_ETHERNET, NULL); + connection = _connection_from_file (PATH_NAME, NULL, TYPE_ETHERNET, NULL); g_assert_cmpstr (nm_connection_get_interface_name (connection), ==, "team0"); @@ -8544,15 +8546,15 @@ test_write_team_master (void) } static void -test_read_team_port (void) +test_read_team_port (gconstpointer user_data) { + const char *const PATH_NAME = user_data; NMConnection *connection; NMSettingConnection *s_con; NMSettingTeamPort *s_team_port; const char *expected_config = "{ \"p4p1\": { \"prio\": -10, \"sticky\": true } }"; - connection = _connection_from_file (TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port", - NULL, TYPE_ETHERNET, NULL); + connection = _connection_from_file (PATH_NAME, NULL, TYPE_ETHERNET, NULL); s_con = nm_connection_get_setting_connection (connection); g_assert (s_con); @@ -9046,9 +9048,11 @@ int main (int argc, char **argv) g_test_add_func (TPATH "bridge/write-component", test_write_bridge_component); g_test_add_func (TPATH "bridge/read-missing-stp", test_read_bridge_missing_stp); - g_test_add_func (TPATH "team/read-master", test_read_team_master); + g_test_add_data_func (TPATH "team/read-master-1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master-1", test_read_team_master); + g_test_add_data_func (TPATH "team/read-master-2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-master-2", test_read_team_master); g_test_add_func (TPATH "team/write-master", test_write_team_master); - g_test_add_func (TPATH "team/read-port", test_read_team_port); + g_test_add_data_func (TPATH "team/read-port-1", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-1", test_read_team_port); + g_test_add_data_func (TPATH "team/read-port-2", TEST_IFCFG_DIR"/network-scripts/ifcfg-test-team-port-2", test_read_team_port); g_test_add_func (TPATH "team/write-port", test_write_team_port); g_test_add_func (TPATH "team/read-port-empty-config", test_read_team_port_empty_config); |