ifcfg-rh: fix up s390 CTC adapter reading and writing (bgo #647578) (rh #641986)

This commit is contained in:
Dan Williams 2011-04-12 15:38:47 -05:00
parent 38d3f0b181
commit d90e6423c8
3 changed files with 145 additions and 4 deletions

View file

@ -3077,6 +3077,11 @@ make_wired_setting (shvarFile *ifcfg,
}
g_free (value);
value = svGetValue (ifcfg, "CTCPROT", FALSE);
if (value && strlen (value))
nm_setting_wired_add_s390_option (s_wired, "ctcprot", value);
g_free (value);
nettype = svGetValue (ifcfg, "NETTYPE", FALSE);
if (nettype && strlen (nettype)) {
if (!strcmp (nettype, "qeth") || !strcmp (nettype, "lcs") || !strcmp (nettype, "ctc"))
@ -3084,6 +3089,7 @@ make_wired_setting (shvarFile *ifcfg,
else
PLUGIN_WARN (IFCFG_PLUGIN_NAME, " warning: unknown s390 NETTYPE '%s'", nettype);
}
g_free (nettype);
value = svGetValue (ifcfg, "OPTIONS", FALSE);
if (value && strlen (value)) {
@ -3106,8 +3112,6 @@ make_wired_setting (shvarFile *ifcfg,
}
g_free (value);
g_free (nettype);
if (!nm_controlled && !*unmanaged) {
/* If NM_CONTROLLED=no but there wasn't a MAC address or z/VM
* subchannels, notify the user that the device cannot be unmanaged.
@ -3332,6 +3336,12 @@ connection_from_file (const char *filename,
}
g_free (device);
} else {
/* Check for IBM s390 CTC devices and call them Ethernet */
if (g_strcmp0 (type, "CTC") == 0) {
g_free (type);
type = g_strdup (TYPE_ETHERNET);
}
}
nmc = svGetValue (parsed, "NM_CONTROLLED", FALSE);

View file

@ -10154,6 +10154,131 @@ test_write_wired_qeth_dhcp (void)
g_object_unref (reread);
}
static void
test_write_wired_ctc_dhcp (void)
{
NMConnection *connection;
NMConnection *reread;
NMSettingConnection *s_con;
NMSettingWired *s_wired;
NMSettingIP4Config *s_ip4;
NMSettingIP6Config *s_ip6;
char *uuid;
GPtrArray *subchans;
gboolean success;
GError *error = NULL;
char *testfile = NULL;
char *unmanaged = NULL;
char *keyfile = NULL;
char *routefile = NULL;
char *route6file = NULL;
gboolean ignore_error = FALSE;
shvarFile *ifcfg;
char *tmp;
connection = nm_connection_new ();
g_assert (connection);
/* Connection setting */
s_con = (NMSettingConnection *) nm_setting_connection_new ();
g_assert (s_con);
nm_connection_add_setting (connection, NM_SETTING (s_con));
uuid = nm_utils_uuid_generate ();
g_object_set (s_con,
NM_SETTING_CONNECTION_ID, "Test Write Wired ctc Static",
NM_SETTING_CONNECTION_UUID, uuid,
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
NULL);
g_free (uuid);
/* Wired setting */
s_wired = (NMSettingWired *) nm_setting_wired_new ();
g_assert (s_wired);
nm_connection_add_setting (connection, NM_SETTING (s_wired));
subchans = g_ptr_array_sized_new (2);
g_ptr_array_add (subchans, "0.0.600");
g_ptr_array_add (subchans, "0.0.601");
g_object_set (s_wired,
NM_SETTING_WIRED_S390_SUBCHANNELS, subchans,
NM_SETTING_WIRED_S390_NETTYPE, "ctc",
NULL);
g_ptr_array_free (subchans, TRUE);
nm_setting_wired_add_s390_option (s_wired, "ctcprot", "0");
/* IP4 setting */
s_ip4 = (NMSettingIP4Config *) nm_setting_ip4_config_new ();
g_assert (s_ip4);
nm_connection_add_setting (connection, NM_SETTING (s_ip4));
g_object_set (s_ip4, NM_SETTING_IP4_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NULL);
/* IP6 setting */
s_ip6 = (NMSettingIP6Config *) nm_setting_ip6_config_new ();
g_assert (s_ip6);
nm_connection_add_setting (connection, NM_SETTING (s_ip6));
g_object_set (s_ip6, NM_SETTING_IP6_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE, NULL);
/* Verify */
success = nm_connection_verify (connection, &error);
g_assert_no_error (error);
g_assert (success);
/* Save the ifcfg */
success = writer_new_connection (connection,
TEST_SCRATCH_DIR "/network-scripts/",
&testfile,
&error);
g_assert_no_error (error);
g_assert (success);
g_assert (testfile != NULL);
/* Ensure the CTCPROT item gets written out as it's own option */
ifcfg = svNewFile (testfile);
g_assert (ifcfg);
tmp = svGetValue (ifcfg, "CTCPROT", TRUE);
g_assert (tmp);
g_assert_cmpstr (tmp, ==, "0");
/* And that it's not in the generic OPTIONS string */
tmp = svGetValue (ifcfg, "OPTIONS", TRUE);
g_assert (tmp == NULL);
svCloseFile (ifcfg);
/* re-read the connection for comparison */
reread = connection_from_file (testfile,
NULL,
TYPE_ETHERNET,
NULL,
&unmanaged,
&keyfile,
&routefile,
&route6file,
&error,
&ignore_error);
unlink (testfile);
g_assert (reread);
success = nm_connection_verify (reread, &error);
g_assert_no_error (error);
g_assert (success);
success = nm_connection_compare (connection, reread, NM_SETTING_COMPARE_FLAG_EXACT);
g_assert (success);
if (route6file)
unlink (route6file);
g_free (testfile);
g_free (keyfile);
g_free (routefile);
g_free (route6file);
g_object_unref (connection);
g_object_unref (reread);
}
static void
test_write_permissions (void)
{
@ -10889,6 +11014,7 @@ int main (int argc, char **argv)
test_write_wifi_wpa_eap_ttls_mschapv2 ();
test_write_wifi_dynamic_wep_leap ();
test_write_wired_qeth_dhcp ();
test_write_wired_ctc_dhcp ();
test_write_permissions ();
test_write_wifi_wep_agent_keys ();

View file

@ -897,7 +897,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
NMSettingWired *s_wired;
const GByteArray *device_mac, *cloned_mac;
char *tmp;
const char *nettype, *portname, *s390_key, *s390_val;
const char *nettype, *portname, *ctcprot, *s390_key, *s390_val;
guint32 mtu, num_opts, i;
const GPtrArray *s390_subchannels;
GString *str;
@ -964,6 +964,11 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
if (portname)
svSetValue (ifcfg, "PORTNAME", portname, FALSE);
svSetValue (ifcfg, "CTCPROT", NULL, FALSE);
ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot");
if (ctcprot)
svSetValue (ifcfg, "CTCPROT", ctcprot, FALSE);
svSetValue (ifcfg, "OPTIONS", NULL, FALSE);
num_opts = nm_setting_wired_get_num_s390_options (s_wired);
if (s390_subchannels && num_opts) {
@ -972,7 +977,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
nm_setting_wired_get_s390_option (s_wired, i, &s390_key, &s390_val);
/* portname is handled separately */
if (!strcmp (s390_key, "portname"))
if (!strcmp (s390_key, "portname") || !strcmp (s390_key, "ctcprot"))
continue;
if (str->len)