tests: Use errno value rather than a specific int
[vpp.git] / test / test_snort.py
1 from asfframework import VppTestRunner
2 from framework import VppTestCase
3 import unittest
4 from config import config
5
6
7 @unittest.skipIf("snort" in config.excluded_plugins, "Exclude snort plugin test")
8 class TestSnort(VppTestCase):
9     """Simple Snort plugin test"""
10
11     @classmethod
12     def setUpClass(cls):
13         super(TestSnort, cls).setUpClass()
14         try:
15             cls.create_pg_interfaces(range(2))
16             for i in cls.pg_interfaces:
17                 i.config_ip4().resolve_arp()
18                 i.admin_up()
19         except Exception:
20             cls.tearDownClass()
21             raise
22
23     @classmethod
24     def tearDownClass(cls):
25         for i in cls.pg_interfaces:
26             i.unconfig_ip4()
27             i.admin_down()
28         super(TestSnort, cls).tearDownClass()
29
30     def test_snort_cli(self):
31         # TODO: add a test with packets
32         # { cli command : part of the expected reply }
33         commands_replies = {
34             "snort create-instance name snortTest queue-size 16 on-disconnect drop": "",
35             "snort create-instance name snortTest2 queue-size 16 on-disconnect pass": "",
36             "snort attach instance snortTest interface pg0 output": "",
37             "snort attach instance snortTest2 interface pg1 input": "",
38             "show snort instances": "snortTest",
39             "show snort interfaces": "pg0",
40             "show snort clients": "number of clients",
41             "show snort mode": "input mode: interrupt",
42             "snort mode polling": "",
43             "snort mode interrupt": "",
44             "snort detach interface pg0": "",
45             "snort detach interface pg1": "",
46         }
47
48         for command, reply in commands_replies.items():
49             actual_reply = self.vapi.cli(command)
50             self.assertIn(reply, actual_reply)
51
52
53 if __name__ == "__main__":
54     unittest.main(testRunner=VppTestRunner)