]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: add a test for interface alias handling
authorVincent Bernat <vincent@bernat.im>
Fri, 15 Jun 2018 05:27:38 +0000 (07:27 +0200)
committerVincent Bernat <vincent@bernat.im>
Sat, 16 Jun 2018 15:08:28 +0000 (17:08 +0200)
src/daemon/priv-linux.c
tests/integration/fixtures/namespaces.py
tests/integration/test_basic.py

index 3e4b89ce1cb294bbfa3ecc5e8c028b95bedb03ac..e96606e8fa9b4ddb5b33c887bb436c463dd54b0d 100644 (file)
@@ -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);
index e278bce1c46af689e1a45922a2df83a7c03f7877..7548f2ed8debc77ca923f2b01ca65c6e2b78e82c 100644 (file)
@@ -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:
index ae41504003c5d46e9a409491eda2da69f458e2b0..0e1d53918bb8669e7ddc990dd53711cebf07851c 100644 (file)
@@ -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'