summaryrefslogtreecommitdiff
path: root/src/platform/tests/test-link.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-02-19 01:06:28 +0100
committerThomas Haller <thaller@redhat.com>2016-02-20 00:19:09 +0100
commit6635e54d613304c3b319d822d6ae1a93d016e968 (patch)
tree7d58a573cf408dff8a2a9a3c60ebc55fab940a4d /src/platform/tests/test-link.c
parent94d6aaac70ecec4baca6a072d32825287f8ee109 (diff)
downloadNetworkManager-th/platform-netns.tar.gz
platform: add network namespace support to platformth/platform-netns
Platform not only uses the netlink socket, but also sysfs, udev, ethtool, mii. To properly support network namespaces, we must switch the namespace as necessary. In case of udev, it is only supported on the main namespace.
Diffstat (limited to 'src/platform/tests/test-link.c')
-rw-r--r--src/platform/tests/test-link.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c
index 3fa5ad5001..cc9a832a61 100644
--- a/src/platform/tests/test-link.c
+++ b/src/platform/tests/test-link.c
@@ -23,6 +23,8 @@
#include <sched.h>
#include "nmp-object.h"
+#include "nmp-netns-utils.h"
+#include "nm-platform-utils.h"
#include "test-common.h"
#include "nm-test-utils.h"
@@ -1846,6 +1848,46 @@ again:
nmtstp_link_del (-1, ifindex_dummy0, IFACE_DUMMY0);
}
+/******************************************************************/
+
+static void
+test_netns_new (void)
+{
+ gs_unref_object NMPlatform *platform_1 = NULL;
+ gs_unref_object NMPlatform *platform_2 = NULL;
+ gs_unref_object NMPNetns *netns_2 = NULL;
+ char sbuf[100];
+
+ platform_1 = g_object_new (NM_TYPE_LINUX_PLATFORM, NULL);
+
+ netns_2 = nmp_netns_new ();
+ platform_2 = g_object_new (NM_TYPE_LINUX_PLATFORM, NULL);
+ nmp_netns_pop (netns_2);
+
+ g_assert_cmpint (nm_platform_link_dummy_add (platform_1, "dummy1_", NULL), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert_cmpint (nm_platform_link_dummy_add (platform_1, "dummy2a", NULL), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert_cmpint (nm_platform_link_dummy_add (platform_2, "dummy1_", NULL), ==, NM_PLATFORM_ERROR_SUCCESS);
+ g_assert_cmpint (nm_platform_link_dummy_add (platform_2, "dummy2b", NULL), ==, NM_PLATFORM_ERROR_SUCCESS);
+
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_1, "/sys/devices/virtual/net/dummy1_/ifindex"), ==, nm_sprintf_buf (sbuf, "%d", nm_platform_link_get_by_ifname (platform_1, "dummy1_")->ifindex));
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_1, "/sys/devices/virtual/net/dummy2a/ifindex"), ==, nm_sprintf_buf (sbuf, "%d", nm_platform_link_get_by_ifname (platform_1, "dummy2a")->ifindex));
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_1, "/sys/devices/virtual/net/dummy2b/ifindex"), ==, NULL);
+
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_2, "/sys/devices/virtual/net/dummy1_/ifindex"), ==, nm_sprintf_buf (sbuf, "%d", nm_platform_link_get_by_ifname (platform_2, "dummy1_")->ifindex));
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_2, "/sys/devices/virtual/net/dummy2a/ifindex"), ==, NULL);
+ g_assert_cmpstr (nm_platform_sysctl_get (platform_2, "/sys/devices/virtual/net/dummy2b/ifindex"), ==, nm_sprintf_buf (sbuf, "%d", nm_platform_link_get_by_ifname (platform_2, "dummy2b")->ifindex));
+
+ g_assert ( nmp_utils_ethtool_get_driver_info ("dummy1_", NULL, NULL, NULL));
+ g_assert ( nmp_utils_ethtool_get_driver_info ("dummy2a", NULL, NULL, NULL));
+ g_assert (!nmp_utils_ethtool_get_driver_info ("dummy2b", NULL, NULL, NULL));
+
+ g_assert (nm_platform_netns_push (platform_2, NULL));
+
+ g_assert ( nmp_utils_ethtool_get_driver_info ("dummy1_", NULL, NULL, NULL));
+ g_assert (!nmp_utils_ethtool_get_driver_info ("dummy2a", NULL, NULL, NULL));
+ g_assert ( nmp_utils_ethtool_get_driver_info ("dummy2b", NULL, NULL, NULL));
+}
+
/*****************************************************************************/
void
@@ -1894,5 +1936,7 @@ setup_tests (void)
g_test_add_func ("/link/nl-bugs/veth", test_nl_bugs_veth);
g_test_add_func ("/link/nl-bugs/spurious-newlink", test_nl_bugs_spuroius_newlink);
g_test_add_func ("/link/nl-bugs/spurious-dellink", test_nl_bugs_spuroius_dellink);
+
+ g_test_add_func ("/general/netns/new", test_netns_new);
}
}