tests: add a test for connection_compatible() for wired devices
Allow setting MAC address and S390 subchannels for ethernet devices in testing NM service.
This commit is contained in:
@@ -100,6 +100,29 @@ add_device (const char *method, const char *ifname, char **out_path)
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
add_wired_device (const char *method, const char *ifname, char **out_path)
|
||||||
|
{
|
||||||
|
const char *empty[] = { NULL };
|
||||||
|
GError *error = NULL;
|
||||||
|
GVariant *ret;
|
||||||
|
|
||||||
|
ret = g_dbus_proxy_call_sync (sinfo->proxy,
|
||||||
|
method,
|
||||||
|
g_variant_new ("(ss^as)", ifname, "/", empty),
|
||||||
|
G_DBUS_CALL_FLAGS_NO_AUTO_START,
|
||||||
|
3000,
|
||||||
|
NULL,
|
||||||
|
&error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
g_assert (ret);
|
||||||
|
g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
|
||||||
|
if (out_path)
|
||||||
|
g_variant_get (ret, "(o)", out_path);
|
||||||
|
g_variant_unref (ret);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@@ -168,7 +191,7 @@ test_device_added (void)
|
|||||||
g_assert (devices == NULL);
|
g_assert (devices == NULL);
|
||||||
|
|
||||||
/* Tell the test service to add a new device */
|
/* Tell the test service to add a new device */
|
||||||
add_device ("AddWiredDevice", "eth0", NULL);
|
add_wired_device ("AddWiredDevice", "eth0", NULL);
|
||||||
|
|
||||||
g_signal_connect (client,
|
g_signal_connect (client,
|
||||||
"device-added",
|
"device-added",
|
||||||
@@ -731,8 +754,8 @@ test_devices_array (void)
|
|||||||
/*************************************/
|
/*************************************/
|
||||||
/* Add some devices */
|
/* Add some devices */
|
||||||
add_device ("AddWifiDevice", "wlan0", &paths[0]);
|
add_device ("AddWifiDevice", "wlan0", &paths[0]);
|
||||||
add_device ("AddWiredDevice", "eth0", &paths[1]);
|
add_wired_device ("AddWiredDevice", "eth0", &paths[1]);
|
||||||
add_device ("AddWiredDevice", "eth1", &paths[2]);
|
add_wired_device ("AddWiredDevice", "eth1", &paths[2]);
|
||||||
info.quit_count = 3;
|
info.quit_count = 3;
|
||||||
|
|
||||||
g_signal_connect (client,
|
g_signal_connect (client,
|
||||||
|
@@ -149,22 +149,53 @@ timeout (gpointer user_data)
|
|||||||
return G_SOURCE_REMOVE;
|
return G_SOURCE_REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
NMDevice *
|
static GVariant *
|
||||||
nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client,
|
call_add_wired_device (GDBusProxy *proxy, const char *ifname, const char *hwaddr,
|
||||||
const char *method, const char *ifname)
|
const char **subchannels, GError **error)
|
||||||
|
{
|
||||||
|
const char *empty[] = { NULL };
|
||||||
|
|
||||||
|
if (!hwaddr)
|
||||||
|
hwaddr = "/";
|
||||||
|
if (!subchannels)
|
||||||
|
subchannels = empty;
|
||||||
|
|
||||||
|
return g_dbus_proxy_call_sync (proxy,
|
||||||
|
"AddWiredDevice",
|
||||||
|
g_variant_new ("(ss^as)", ifname, hwaddr, subchannels),
|
||||||
|
G_DBUS_CALL_FLAGS_NO_AUTO_START,
|
||||||
|
3000,
|
||||||
|
NULL,
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static GVariant *
|
||||||
|
call_add_device (GDBusProxy *proxy, const char *method, const char *ifname, GError **error)
|
||||||
|
{
|
||||||
|
return g_dbus_proxy_call_sync (proxy,
|
||||||
|
method,
|
||||||
|
g_variant_new ("(s)", ifname),
|
||||||
|
G_DBUS_CALL_FLAGS_NO_AUTO_START,
|
||||||
|
3000,
|
||||||
|
NULL,
|
||||||
|
error);
|
||||||
|
}
|
||||||
|
|
||||||
|
static NMDevice *
|
||||||
|
add_device_common (NMTestServiceInfo *sinfo, NMClient *client,
|
||||||
|
const char *method, const char *ifname,
|
||||||
|
const char *hwaddr, const char **subchannels)
|
||||||
{
|
{
|
||||||
AddDeviceInfo info;
|
AddDeviceInfo info;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GVariant *ret;
|
GVariant *ret;
|
||||||
guint timeout_id;
|
guint timeout_id;
|
||||||
|
|
||||||
ret = g_dbus_proxy_call_sync (sinfo->proxy,
|
if (g_strcmp0 (method, "AddWiredDevice") == 0)
|
||||||
method,
|
ret = call_add_wired_device (sinfo->proxy, ifname, hwaddr, subchannels, &error);
|
||||||
g_variant_new ("(s)", ifname),
|
else
|
||||||
G_DBUS_CALL_FLAGS_NO_AUTO_START,
|
ret = call_add_device (sinfo->proxy, method, ifname, &error);
|
||||||
3000,
|
|
||||||
NULL,
|
|
||||||
&error);
|
|
||||||
g_assert_no_error (error);
|
g_assert_no_error (error);
|
||||||
g_assert (ret);
|
g_assert (ret);
|
||||||
g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
|
g_assert_cmpstr (g_variant_get_type_string (ret), ==, "(o)");
|
||||||
@@ -186,3 +217,18 @@ nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client,
|
|||||||
|
|
||||||
return info.device;
|
return info.device;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NMDevice *
|
||||||
|
nm_test_service_add_device (NMTestServiceInfo *sinfo, NMClient *client,
|
||||||
|
const char *method, const char *ifname)
|
||||||
|
{
|
||||||
|
return add_device_common (sinfo, client, method, ifname, NULL, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
NMDevice *
|
||||||
|
nm_test_service_add_wired_device (NMTestServiceInfo *sinfo, NMClient *client,
|
||||||
|
const char *ifname, const char *hwaddr,
|
||||||
|
const char **subchannels)
|
||||||
|
{
|
||||||
|
return add_device_common (sinfo, client, "AddWiredDevice", ifname, hwaddr, subchannels);
|
||||||
|
}
|
||||||
|
@@ -36,3 +36,10 @@ NMDevice *nm_test_service_add_device (NMTestServiceInfo *info,
|
|||||||
NMClient *client,
|
NMClient *client,
|
||||||
const char *method,
|
const char *method,
|
||||||
const char *ifname);
|
const char *ifname);
|
||||||
|
|
||||||
|
NMDevice * nm_test_service_add_wired_device (NMTestServiceInfo *sinfo,
|
||||||
|
NMClient *client,
|
||||||
|
const char *ifname,
|
||||||
|
const char *hwaddr,
|
||||||
|
const char **subchannels);
|
||||||
|
|
||||||
|
@@ -1160,6 +1160,77 @@ test_activate_failed (void)
|
|||||||
g_clear_pointer (&sinfo, nm_test_service_cleanup);
|
g_clear_pointer (&sinfo, nm_test_service_cleanup);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
test_device_connection_compatibility (void)
|
||||||
|
{
|
||||||
|
NMClient *client;
|
||||||
|
NMDevice *device1, *device2;
|
||||||
|
NMConnection *conn;
|
||||||
|
NMSettingWired *s_wired;
|
||||||
|
GError *error = NULL;
|
||||||
|
const char *subchannels[] = { "0.0.8000", "0.0.8001", "0.0.8002", NULL };
|
||||||
|
const char *subchannels_2[] = { "0.0.8000", "0.0.8001", NULL };
|
||||||
|
const char *subchannels_x[] = { "0.0.8000", "0.0.8001", "0.0.800X", NULL };
|
||||||
|
const char *hw_addr1 = "52:54:00:ab:db:23";
|
||||||
|
const char *hw_addr2 = "52:54:00:ab:db:24";
|
||||||
|
|
||||||
|
sinfo = nm_test_service_init ();
|
||||||
|
client = nm_client_new (NULL, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
/* Create two devices */
|
||||||
|
device1 = nm_test_service_add_wired_device (sinfo, client, "eth0", hw_addr1, subchannels);
|
||||||
|
device2 = nm_test_service_add_wired_device (sinfo, client, "eth1", hw_addr2, NULL);
|
||||||
|
|
||||||
|
g_assert_cmpstr (nm_device_get_hw_address (device1), ==, hw_addr1);
|
||||||
|
g_assert_cmpstr (nm_device_get_hw_address (device2), ==, hw_addr2);
|
||||||
|
|
||||||
|
conn = nmtst_create_minimal_connection ("wired-matches", NULL,
|
||||||
|
NM_SETTING_WIRED_SETTING_NAME, NULL);
|
||||||
|
s_wired = nm_connection_get_setting_wired (conn);
|
||||||
|
nm_setting_wired_add_mac_blacklist_item (s_wired, "00:11:22:33:44:55");
|
||||||
|
|
||||||
|
/* device1 and conn are compatible */
|
||||||
|
g_object_set (s_wired,
|
||||||
|
NM_SETTING_WIRED_MAC_ADDRESS, hw_addr1,
|
||||||
|
NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels,
|
||||||
|
NULL);
|
||||||
|
nm_device_connection_compatible (device1, conn, &error);
|
||||||
|
g_assert_no_error (error);
|
||||||
|
|
||||||
|
/* device2 and conn differ in subchannels */
|
||||||
|
g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels_x, NULL);
|
||||||
|
nm_device_connection_compatible (device2, conn, &error);
|
||||||
|
g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION);
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
|
/* device1 and conn differ in subchannels - 2 in connection, 3 in device */
|
||||||
|
g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, subchannels_2, NULL);
|
||||||
|
nm_device_connection_compatible (device1, conn, &error);
|
||||||
|
g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION);
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
|
g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, NULL, NULL);
|
||||||
|
|
||||||
|
/* device2 and conn differ in MAC address */
|
||||||
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, "aa:bb:cc:dd:ee:ee", NULL);
|
||||||
|
nm_device_connection_compatible (device2, conn, &error);
|
||||||
|
g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION);
|
||||||
|
g_clear_error (&error);
|
||||||
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, NULL, NULL);
|
||||||
|
|
||||||
|
/* device1 is blacklisted in conn */
|
||||||
|
nm_setting_wired_add_mac_blacklist_item (s_wired, hw_addr1);
|
||||||
|
nm_device_connection_compatible (device1, conn, &error);
|
||||||
|
g_assert_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION);
|
||||||
|
g_clear_error (&error);
|
||||||
|
|
||||||
|
g_object_unref (conn);
|
||||||
|
g_object_unref (client);
|
||||||
|
|
||||||
|
g_clear_pointer (&sinfo, nm_test_service_cleanup);
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************/
|
/*******************************************************************/
|
||||||
|
|
||||||
NMTST_DEFINE ();
|
NMTST_DEFINE ();
|
||||||
@@ -1182,6 +1253,7 @@ main (int argc, char **argv)
|
|||||||
g_test_add_func ("/libnm/active-connections", test_active_connections);
|
g_test_add_func ("/libnm/active-connections", test_active_connections);
|
||||||
g_test_add_func ("/libnm/activate-virtual", test_activate_virtual);
|
g_test_add_func ("/libnm/activate-virtual", test_activate_virtual);
|
||||||
g_test_add_func ("/libnm/activate-failed", test_activate_failed);
|
g_test_add_func ("/libnm/activate-failed", test_activate_failed);
|
||||||
|
g_test_add_func ("/libnm/device-connection-compatibility", test_device_connection_compatibility);
|
||||||
|
|
||||||
return g_test_run ();
|
return g_test_run ();
|
||||||
}
|
}
|
||||||
|
@@ -207,14 +207,19 @@ PE_HW_ADDRESS = "HwAddress"
|
|||||||
PE_PERM_HW_ADDRESS = "PermHwAddress"
|
PE_PERM_HW_ADDRESS = "PermHwAddress"
|
||||||
PE_SPEED = "Speed"
|
PE_SPEED = "Speed"
|
||||||
PE_CARRIER = "Carrier"
|
PE_CARRIER = "Carrier"
|
||||||
|
PE_S390_SUBCHANNELS = "S390Subchannels"
|
||||||
|
|
||||||
class WiredDevice(Device):
|
class WiredDevice(Device):
|
||||||
def __init__(self, bus, iface):
|
def __init__(self, bus, iface, mac, subchannels):
|
||||||
Device.__init__(self, bus, iface, NM_DEVICE_TYPE_ETHERNET)
|
Device.__init__(self, bus, iface, NM_DEVICE_TYPE_ETHERNET)
|
||||||
self.add_dbus_interface(IFACE_WIRED, self.__get_props)
|
self.add_dbus_interface(IFACE_WIRED, self.__get_props)
|
||||||
|
|
||||||
|
if mac is None:
|
||||||
self.mac = random_mac()
|
self.mac = random_mac()
|
||||||
|
else:
|
||||||
|
self.mac = mac
|
||||||
self.carrier = False
|
self.carrier = False
|
||||||
|
self.s390_subchannels = subchannels
|
||||||
|
|
||||||
# Properties interface
|
# Properties interface
|
||||||
def __get_props(self):
|
def __get_props(self):
|
||||||
@@ -223,6 +228,7 @@ class WiredDevice(Device):
|
|||||||
props[PE_PERM_HW_ADDRESS] = self.mac
|
props[PE_PERM_HW_ADDRESS] = self.mac
|
||||||
props[PE_SPEED] = dbus.UInt32(100)
|
props[PE_SPEED] = dbus.UInt32(100)
|
||||||
props[PE_CARRIER] = self.carrier
|
props[PE_CARRIER] = self.carrier
|
||||||
|
props[PE_S390_SUBCHANNELS] = self.s390_subchannels
|
||||||
return props
|
return props
|
||||||
|
|
||||||
def __notify(self, propname):
|
def __notify(self, propname):
|
||||||
@@ -838,12 +844,12 @@ class NetworkManager(ExportedObj):
|
|||||||
def Quit(self):
|
def Quit(self):
|
||||||
mainloop.quit()
|
mainloop.quit()
|
||||||
|
|
||||||
@dbus.service.method(IFACE_TEST, in_signature='s', out_signature='o')
|
@dbus.service.method(IFACE_TEST, in_signature='ssas', out_signature='o')
|
||||||
def AddWiredDevice(self, ifname):
|
def AddWiredDevice(self, ifname, mac, subchannels):
|
||||||
for d in self.devices:
|
for d in self.devices:
|
||||||
if d.iface == ifname:
|
if d.iface == ifname:
|
||||||
raise PermissionDeniedException("Device already added")
|
raise PermissionDeniedException("Device already added")
|
||||||
dev = WiredDevice(self._bus, ifname)
|
dev = WiredDevice(self._bus, ifname, mac, subchannels)
|
||||||
self.add_device(dev)
|
self.add_device(dev)
|
||||||
return to_path(dev)
|
return to_path(dev)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user