tests: disable broken wireguard tests on vpp_debug image
[vpp.git] / test / test_api_trace.py
1 import os
2 import unittest
3 from framework import VppTestCase, VppTestRunner
4 from vpp_papi import VppEnum
5 import json
6
7
8 class TestJsonApiTrace(VppTestCase):
9     """JSON API trace related tests"""
10
11     @classmethod
12     def setUpClass(cls):
13         super(TestJsonApiTrace, cls).setUpClass()
14
15     def setUp(self):
16         self.vapi.cli("api trace free")
17         self.vapi.cli("api trace on")
18         self.vapi.cli("api trace tx on")
19
20     @classmethod
21     def tearDownClass(cls):
22         super(TestJsonApiTrace, cls).tearDownClass()
23
24     def test_json_api_trace_save(self):
25         self.vapi.show_version()
26
27         fname = "test_api_trace-%d.json" % self.vpp.pid
28         tmp_api_trace = "/tmp/%s" % fname
29         fpath = "%s/%s" % (self.tempdir, fname)
30         self.vapi.cli("api trace save-json {}".format(fname))
31         os.rename(tmp_api_trace, fpath)
32         with open(fpath, encoding="utf-8") as f:
33             s = f.read()
34         trace = json.loads(s)
35         found = False
36         for o in trace:
37             if o["_msgname"] == "show_version":
38                 found = True
39                 break
40         self.assertTrue(found)
41         self.assertEquals(o["_msgname"], "show_version")
42
43     def test_json_api_trace_replay(self):
44         fname = "/tmp/create_loop.json"
45         req = """
46 [
47 {
48         "_msgname": "create_loopback",
49         "_crc": "42bb5d22",
50         "mac_address": "00:00:00:00:00:00"
51 }]
52 """
53         with open(fname, "w") as f:
54             f.write(req)
55         self.vapi.cli("api trace replay-json {}".format(fname))
56         r = self.vapi.sw_interface_dump(name_filter="loop", name_filter_valid=True)
57         self.assertEqual(len(r), 1)
58         self.assertEqual(r[0].interface_name, "loop0")
59
60
61 if __name__ == "__main__":
62     unittest.main(testRunner=VppTestRunner)