From 08e05799dd7caa32bc429b43423cfbf5d0ef2c7e Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Fri, 15 Jun 2018 07:27:38 +0200 Subject: [PATCH] tests: add a test for interface alias handling --- src/daemon/priv-linux.c | 4 ++-- tests/integration/fixtures/namespaces.py | 16 ++++++++++++++++ tests/integration/test_basic.py | 9 +++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/daemon/priv-linux.c b/src/daemon/priv-linux.c index 3e4b89ce..e96606e8 100644 --- a/src/daemon/priv-linux.c +++ b/src/daemon/priv-linux.c @@ -188,9 +188,9 @@ asroot_iface_description_os(const char *name, const char *description) } if ((fp = fopen(file, "r+")) == NULL) { rc = errno; - free(file); - log_debug("privsep", "cannot open interface description for %s", + log_debug("privsep", "cannot open interface description for %s: %m", name); + free(file); return rc; } free(file); diff --git a/tests/integration/fixtures/namespaces.py b/tests/integration/fixtures/namespaces.py index e278bce1..7548f2ed 100644 --- a/tests/integration/fixtures/namespaces.py +++ b/tests/integration/fixtures/namespaces.py @@ -28,6 +28,21 @@ def keep_directory(): os.chdir(pwd) +def mount_sys(target="/sys"): + flags = [2 | 4 | 8] # MS_NOSUID | MS_NODEV | MS_NOEXEC + flags.append(1 << 18) # MS_PRIVATE + flags.append(1 << 19) # MS_SLAVE + for fl in flags: + ret = libc.mount(b"none", + target.encode('ascii'), + b"sysfs", + fl, + None) + if ret == -1: + e = ctypes.get_errno() + raise OSError(e, os.strerror(e)) + + class Namespace(object): """Combine several namespaces into one. @@ -112,6 +127,7 @@ class Namespace(object): # MS_REC | MS_PRIVATE 16384 | (1 << 18), None) + mount_sys() while True: try: diff --git a/tests/integration/test_basic.py b/tests/integration/test_basic.py index ae415040..0e1d5391 100644 --- a/tests/integration/test_basic.py +++ b/tests/integration/test_basic.py @@ -333,3 +333,12 @@ def test_port_status_disabled(lldpd, lldpcli, namespaces, links): assert out == {} +def test_set_interface_alias(lldpd1, lldpd, lldpcli, namespaces): + with namespaces(1): + lldpcli("configure", "system", "interface", "description") + with namespaces(2): + lldpd() + with namespaces(1): + ipr = pyroute2.IPRoute() + link = ipr.link('get', ifname='eth0')[0] + assert link.get_attr('IFLA_IFALIAS') == 'lldpd: connected to ns-2.example.com' -- 2.39.2