diff options
author | Thomas Haller <thaller@redhat.com> | 2016-02-19 01:06:28 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2016-02-20 00:19:09 +0100 |
commit | 6635e54d613304c3b319d822d6ae1a93d016e968 (patch) | |
tree | 7d58a573cf408dff8a2a9a3c60ebc55fab940a4d /src/platform/tests | |
parent | 94d6aaac70ecec4baca6a072d32825287f8ee109 (diff) | |
download | NetworkManager-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')
-rw-r--r-- | src/platform/tests/test-general.c | 4 | ||||
-rw-r--r-- | src/platform/tests/test-link.c | 44 | ||||
-rw-r--r-- | src/platform/tests/test-nmp-object.c | 4 |
3 files changed, 47 insertions, 5 deletions
diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c index f342e5653e..66f72fa570 100644 --- a/src/platform/tests/test-general.c +++ b/src/platform/tests/test-general.c @@ -18,12 +18,12 @@ * Copyright (C) 2015 Red Hat, Inc. */ -#include "nm-platform-utils.h" +#include "nm-default.h" #include <linux/rtnetlink.h> +#include "nm-platform-utils.h" #include "nm-linux-platform.h" -#include "nm-default.h" #include "nm-test-utils.h" 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); } } diff --git a/src/platform/tests/test-nmp-object.c b/src/platform/tests/test-nmp-object.c index 3b44abb8d6..d77170b364 100644 --- a/src/platform/tests/test-nmp-object.c +++ b/src/platform/tests/test-nmp-object.c @@ -223,9 +223,7 @@ test_cache_link (void) GUdevDevice *udev_device_3 = g_list_nth_data (global.udev_devices, 0); NMPCacheOpsType ops_type; - cache = nmp_cache_new (); - - nmp_cache_use_udev_set (cache, g_rand_int_range (nmtst_get_rand (), 0, 2)); + cache = nmp_cache_new (nmtst_get_rand_int () % 2); /* if we have a link, and don't set is_in_netlink, adding it has no effect. */ obj1 = nmp_object_new (NMP_OBJECT_TYPE_LINK, (NMPlatformObject *) &pl_link_2); |