Steven | e8fa620 | 2017-08-30 14:36:45 -0700 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner |
| 6 | |
| 7 | from vpp_vhost_interface import VppVhostInterface |
| 8 | |
| 9 | |
| 10 | class TesVhostInterface(VppTestCase): |
| 11 | """Vhost User Test Case |
| 12 | |
| 13 | """ |
| 14 | |
| 15 | def test_vhost(self): |
| 16 | """ Vhost User add/delete interface test """ |
| 17 | self.logger.info("Vhost User add interfaces") |
| 18 | |
| 19 | # create interface 1 (VirtualEthernet0/0/0) |
| 20 | vhost_if1 = VppVhostInterface(self, sock_filename='/tmp/sock1') |
| 21 | vhost_if1.add_vpp_config() |
| 22 | vhost_if1.admin_up() |
| 23 | |
| 24 | # create interface 2 (VirtualEthernet0/0/1) |
| 25 | vhost_if2 = VppVhostInterface(self, sock_filename='/tmp/sock2') |
| 26 | vhost_if2.add_vpp_config() |
| 27 | vhost_if2.admin_up() |
| 28 | |
| 29 | # verify both interfaces in the show |
| 30 | ifs = self.vapi.cli("show interface") |
| 31 | self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1) |
| 32 | self.assertNotEqual(ifs.find('VirtualEthernet0/0/1'), -1) |
| 33 | |
| 34 | # verify they are in the dump also |
| 35 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 36 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 37 | self.assertTrue(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 38 | |
| 39 | # delete VirtualEthernet0/0/1 |
| 40 | self.logger.info("Deleting VirtualEthernet0/0/1") |
| 41 | vhost_if2.remove_vpp_config() |
| 42 | |
| 43 | self.logger.info("Verifying VirtualEthernet0/0/1 is deleted") |
| 44 | |
| 45 | ifs = self.vapi.cli("show interface") |
| 46 | # verify VirtualEthernet0/0/0 still in the show |
| 47 | self.assertNotEqual(ifs.find('VirtualEthernet0/0/0'), -1) |
| 48 | |
| 49 | # verify VirtualEthernet0/0/1 not in the show |
| 50 | self.assertEqual(ifs.find('VirtualEthernet0/0/1'), -1) |
| 51 | |
| 52 | # verify VirtualEthernet0/0/1 is not in the dump |
| 53 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 54 | self.assertFalse(vhost_if2.is_interface_config_in_dump(if_dump)) |
| 55 | |
| 56 | # verify VirtualEthernet0/0/0 is still in the dump |
| 57 | self.assertTrue(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 58 | |
| 59 | # delete VirtualEthernet0/0/0 |
| 60 | self.logger.info("Deleting VirtualEthernet0/0/0") |
| 61 | vhost_if1.remove_vpp_config() |
| 62 | |
| 63 | self.logger.info("Verifying VirtualEthernet0/0/0 is deleted") |
| 64 | |
| 65 | # verify VirtualEthernet0/0/0 not in the show |
| 66 | ifs = self.vapi.cli("show interface") |
| 67 | self.assertEqual(ifs.find('VirtualEthernet0/0/0'), -1) |
| 68 | |
| 69 | # verify VirtualEthernet0/0/0 is not in the dump |
| 70 | if_dump = self.vapi.sw_interface_vhost_user_dump() |
| 71 | self.assertFalse(vhost_if1.is_interface_config_in_dump(if_dump)) |
| 72 | |
| 73 | if __name__ == '__main__': |
| 74 | unittest.main(testRunner=VppTestRunner) |