diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2015-05-15 11:46:43 +0200 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2015-05-15 12:00:56 +0200 |
commit | 98624f84437384854803be51cf10235f5e818982 (patch) | |
tree | 8e327f989ae949cf607f8c18d2fab6d05e8de977 | |
parent | c55710a83de248f73f0b0ca09e456c4221249548 (diff) | |
download | NetworkManager-98624f84437384854803be51cf10235f5e818982.tar.gz |
tests: allow running the link test without a writeable sysfs
This fixes the test run in a container/our NETNS/NEWUSER test jail.
-rw-r--r-- | src/platform/tests/test-common.c | 17 | ||||
-rw-r--r-- | src/platform/tests/test-link.c | 80 |
2 files changed, 58 insertions, 39 deletions
diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index 2d37fb837d..81f7cbdc73 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -325,12 +325,17 @@ main (int argc, char **argv) g_error ("mount(\"/sys/devices\") failed with %s (%d)", strerror (errsv), errsv); } if (mount (NULL, "/sys/devices", "sysfs", MS_REMOUNT, NULL) != 0) { - errsv = errno; - g_error ("remount(\"/sys/devices\") failed with %s (%d)", strerror (errsv), errsv); - } - if (mount ("/sys/devices/devices", "/sys/devices", "sysfs", MS_BIND, NULL) != 0) { - errsv = errno; - g_error ("mount(\"/sys\") failed with %s (%d)", strerror (errsv), errsv); + /* Read-write remount failed. Never mind, we're probably just a root in + * our user NS. */ + if (umount ("/sys/devices") != 0) { + errsv = errno; + g_error ("umount(\"/sys/devices\") failed with %s (%d)", strerror (errsv), errsv); + } + } else { + if (mount ("/sys/devices/devices", "/sys/devices", "sysfs", MS_BIND, NULL) != 0) { + errsv = errno; + g_error ("mount(\"/sys\") failed with %s (%d)", strerror (errsv), errsv); + } } } diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index bbd42946af..12f0bd555a 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -16,6 +16,12 @@ #define VLAN_FLAGS 0 #define MTU 1357 +static gboolean +sysfs_writable (void) +{ + return (access ("/sys", W_OK) == 0); +} + static void test_bogus(void) { @@ -216,18 +222,22 @@ test_slave (int master, int type, SignalData *master_changed) accept_signal (link_changed); accept_signal (master_changed); - /* Set slave option */ - switch (type) { - case NM_LINK_TYPE_BRIDGE: - g_assert (nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, "priority", "789")); - no_error (); - value = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex, "priority"); - no_error (); - g_assert_cmpstr (value, ==, "789"); - g_free (value); - break; - default: - break; + if (sysfs_writable ()) { + /* Set slave option */ + switch (type) { + case NM_LINK_TYPE_BRIDGE: + g_assert (nm_platform_slave_set_option (NM_PLATFORM_GET, ifindex, "priority", "789")); + no_error (); + value = nm_platform_slave_get_option (NM_PLATFORM_GET, ifindex, "priority"); + no_error (); + g_assert_cmpstr (value, ==, "789"); + g_free (value); + break; + default: + break; + } + } else { + g_test_skip ("Skipping slave option test: can not write sysfs"); } /* Release */ @@ -291,27 +301,31 @@ test_software (NMLinkType link_type, const char *link_typename) g_assert (nm_platform_link_uses_arp (NM_PLATFORM_GET, ifindex)); accept_signal (link_changed); - /* Set master option */ - switch (link_type) { - case NM_LINK_TYPE_BRIDGE: - g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "789")); - no_error (); - value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay"); - no_error (); - g_assert_cmpstr (value, ==, "789"); - g_free (value); - break; - case NM_LINK_TYPE_BOND: - g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup")); - no_error (); - value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "mode"); - no_error (); - /* When reading back, the output looks slightly different. */ - g_assert (g_str_has_prefix (value, "active-backup")); - g_free (value); - break; - default: - break; + if (sysfs_writable ()) { + /* Set master option */ + switch (link_type) { + case NM_LINK_TYPE_BRIDGE: + g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "789")); + no_error (); + value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay"); + no_error (); + g_assert_cmpstr (value, ==, "789"); + g_free (value); + break; + case NM_LINK_TYPE_BOND: + g_assert (nm_platform_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup")); + no_error (); + value = nm_platform_master_get_option (NM_PLATFORM_GET, ifindex, "mode"); + no_error (); + /* When reading back, the output looks slightly different. */ + g_assert (g_str_has_prefix (value, "active-backup")); + g_free (value); + break; + default: + break; + } + } else { + g_test_skip ("Skipping master option test: can not write sysfs"); } /* Enslave and release */ |