Fix CDP failure in make test 28/16428/2
authorLijian.Zhang <Lijian.Zhang@arm.com>
Mon, 10 Dec 2018 10:08:02 +0000 (02:08 -0800)
committerDamjan Marion <dmarion@me.com>
Wed, 12 Dec 2018 00:35:27 +0000 (00:35 +0000)
Once the hostname is longer than 15 bytes,
the name of device in the output of show cdp command will be truncated,
and CDP test case will fail with below message.

==============================================================================
FAIL: test_send_cdp_packet (test_cdp.TestCDP)
------------------------------------------------------------------------------
Traceback (most recent call last):
File "vpp/test/test_cdp.py", line 92, in test_send_cdp_packet
    "CDP received invalid device id")
File "vpp/test/framework.py", line 804, in assert_equal
    self.assertEqual(real_value, expected_value, msg)
AssertionError: Invalid CDP received invalid device id: net-x86-supermi does not match expected value net-x86-supermicro-02

Change-Id: Ia32b92c6cd1bb6070adcee3ec45e38399ec382a7
Signed-off-by: Lijian Zhang <Lijian.Zhang@arm.com>
src/plugins/cdp/cdp_input.c
test/test_cdp.py

index a27113d..946aaf7 100644 (file)
@@ -437,7 +437,7 @@ format_cdp_neighbors (u8 * s, va_list * va)
   vnet_hw_interface_t *hw;
 
   s = format (s,
-             "%=25s %=15s %=25s %=10s\n",
+             "%=25s %=25s %=25s %=10s\n",
              "Our Port", "Peer System", "Peer Port", "Last Heard");
 
   /* *INDENT-OFF* */
@@ -446,7 +446,7 @@ format_cdp_neighbors (u8 * s, va_list * va)
     hw = vnet_get_sup_hw_interface (vnm, n->sw_if_index);
 
     if (n->disabled == 0)
-      s = format (s, "%=25s %=15s %=25s %=10.1f\n",
+      s = format (s, "%=25s %=25s %=25s %=10.1f\n",
                   hw->name, n->device_name, n->port_id,
                   n->last_heard);
   }));
index ac42bf0..e8ced7c 100644 (file)
@@ -86,9 +86,10 @@ class TestCDP(VppTestCase):
         self.assertTrue(neighbors, "CDP didn't register neighbor")
 
         port, system = neighbors[0]
+        length = min(len(system), len(self.device_id))
 
         self.assert_equal(port, self.port_id, "CDP received invalid port id")
-        self.assert_equal(system, self.device_id,
+        self.assert_equal(system[:length], self.device_id[:length],
                           "CDP received invalid device id")
 
     def test_cdp_underflow_tlv(self):