]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
tests: add tests for modified/unmodified ports
authorVincent Bernat <vincent@bernat.im>
Mon, 12 Mar 2018 20:47:48 +0000 (21:47 +0100)
committerVincent Bernat <vincent@bernat.im>
Mon, 12 Mar 2018 20:47:48 +0000 (21:47 +0100)
src/daemon/lldpd.c
tests/integration/fixtures/network.py
tests/integration/test_lldpcli.py

index 583742776554154acfcf1752141a01b304212aac..0f962ebaac08376c75f889ec47d2175f1f2a9a09 100644 (file)
@@ -145,9 +145,14 @@ lldpd_get_hardware(struct lldpd *cfg, char *name, int index)
 {
        struct lldpd_hardware *hardware;
        TAILQ_FOREACH(hardware, &cfg->g_hardware, h_entries) {
-               if ((strcmp(hardware->h_ifname, name) == 0) &&
-                   (hardware->h_ifindex == index))
-                       break;
+               if (strcmp(hardware->h_ifname, name) == 0) {
+                       if (hardware->h_flags == 0) {
+                               hardware->h_ifindex = index;
+                               break;
+                       }
+                       if (hardware->h_ifindex == index)
+                               break;
+               }
        }
        return hardware;
 }
@@ -207,8 +212,8 @@ lldpd_port_is_modified(struct lldpd *cfg, struct lldpd_port *port)
        int ret = 0;
        len1 = lldpd_port_serialize_configuration(dflt, 0, &out1);
        len2 = lldpd_port_serialize_configuration(port, 0, &out2);
-       if (len1 == -1 || len2 == -1 || len1 != len2) goto end;
-       if (memcmp(out1, out2, len1)) goto end;
+       if (len1 == -1 || len2 == -1) goto end;
+       if (len1 == len2 && !memcmp(out1, out2, len1)) goto end;
        ret = 1;
  end:
        free(out1);
@@ -470,12 +475,16 @@ lldpd_cleanup(struct lldpd *cfg)
                                log_debug("localchassis", "do not delete %s, modified",
                                    hardware->h_ifname);
                        } else {
+                               log_debug("localchassis", "delete %s, unmodified",
+                                   hardware->h_ifname);
                                TRACE(LLDPD_INTERFACES_DELETE(hardware->h_ifname));
                                TAILQ_REMOVE(&cfg->g_hardware, hardware, h_entries);
                                lldpd_remote_cleanup(hardware, notify_clients_deletion, 1);
                                lldpd_hardware_cleanup(cfg, hardware);
                        }
                } else {
+                       log_debug("localchassis", "keep %s, still exists",
+                           hardware->h_ifname);
                        lldpd_remote_cleanup(hardware, notify_clients_deletion,
                            !(hardware->h_flags & IFF_RUNNING));
                }
index aa2a85c392298cb244ae920e36b4fc5d1f76f546..64785e88b063c1de31cb1901bbde293f2c21e6a4 100644 (file)
@@ -108,6 +108,14 @@ class LinksFactory(object):
         """Create a bond."""
         return self._bond_or_team("bond", name, *ifaces)
 
+    def dummy(self, name):
+        """Create a dummy interface."""
+        ipr = pyroute2.IPRoute()
+        ipr.link('add', ifname=name, kind='dummy')
+        idx = ipr.link_lookup(ifname=name)[0]
+        ipr.link('set', index=idx, state='up')
+        return idx
+
     def vlan(self, name, id, iface):
         """Create a VLAN."""
         ipr = pyroute2.IPRoute()
index aafafd6378b96d18d899e688acc64ecdd6dc6841..4a88dbf19927763cc027afde971e8f077f11b172 100644 (file)
@@ -389,9 +389,9 @@ def test_new_port_take_default(lldpd1, lldpd, lldpcli, namespaces, links):
 
 @pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
                     reason="Dot3 not supported")
-def test_port_keep_configuration(lldpd1, lldpd, lldpcli, namespaces, links):
-    links(namespaces(1), namespaces(2))
-    with namespaces(2):
+def test_port_keep_configuration_when_down(lldpd, lldpcli, namespaces, links):
+    with namespaces(1):
+        links.dummy('eth3')
         lldpd()
         result = lldpcli(*("configure ports eth3 dot3 power "
                            "pse supported enabled paircontrol powerpairs "
@@ -400,14 +400,60 @@ def test_port_keep_configuration(lldpd1, lldpd, lldpcli, namespaces, links):
         time.sleep(3)
         links.down('eth3')
         time.sleep(4)
+        # eth3 configuration is kept because the port still exists.
+        out = lldpcli("-f", "keyvalue", "show", "interfaces", "details")
+        assert out['lldp.eth3.port.power.device-type'] == 'PSE'
+
         links.up('eth3')
         time.sleep(4)
+        # eth3 configuration is unchanged
         out = lldpcli("-f", "keyvalue", "show", "interfaces", "details")
         assert out['lldp.eth3.port.power.device-type'] == 'PSE'
+
+
+@pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
+                    reason="Dot3 not supported")
+def test_port_keep_configuration_when_modified(lldpd, lldpcli,
+                                               namespaces, links):
     with namespaces(1):
-        out = lldpcli("-f", "keyvalue", "show", "neighbors", "details")
-        assert out['lldp.eth2.port.descr'] == 'eth3'
-        assert out['lldp.eth2.port.power.device-type'] == 'PSE'
+        links.dummy('eth3')
+        lldpd()
+        result = lldpcli(*("configure ports eth3 dot3 power "
+                           "pse supported enabled paircontrol powerpairs "
+                           "spare class class-3").split())
+        assert result.returncode == 0
+        time.sleep(3)
+        links.remove('eth3')
+        time.sleep(4)
+        # eth3 configuration is kept because the port was modified
+        out = lldpcli("-f", "keyvalue", "show", "interfaces", "details")
+        assert out['lldp.eth3.port.power.device-type'] == 'PSE'
+
+        links.dummy('eth3')
+        time.sleep(4)
+        # eth3 configuration is unchanged
+        out = lldpcli("-f", "keyvalue", "show", "interfaces", "details")
+        assert out['lldp.eth3.port.power.device-type'] == 'PSE'
+
+
+@pytest.mark.skipif('Dot3' not in pytest.config.lldpd.features,
+                    reason="Dot3 not supported")
+def test_port_forget_configuration_when_unmodified(lldpd, lldpcli,
+                                                   namespaces, links):
+    with namespaces(1):
+        links.dummy('eth3')
+        lldpd()
+        result = lldpcli(*("configure dot3 power "
+                           "pse supported enabled paircontrol powerpairs "
+                           "spare class class-3").split())
+        assert result.returncode == 0
+        time.sleep(3)
+        links.remove('eth3')
+        time.sleep(4)
+        # eth3 configuration was forgotten because it was the same as
+        # the default.
+        out = lldpcli("-f", "keyvalue", "show", "interfaces", "details")
+        assert 'lldp.eth3.port.power.device-type' not in out
 
 
 def test_watch(lldpd1, lldpd, lldpcli, namespaces, links):