9 Generic hooks before/after API/CLI calls
12 def before_api(self, api_name, api_args):
14 Function called before API call
15 Emit a debug message describing the API name and arguments
17 @param api_name: name of the API
18 @param api_args: tuple containing the API arguments
20 debug("API: %s (%s)" % (api_name, api_args))
22 def after_api(self, api_name, api_args):
24 Function called after API call
26 @param api_name: name of the API
27 @param api_args: tuple containing the API arguments
31 def before_cli(self, cli):
33 Function called before CLI call
34 Emit a debug message describing the CLI
36 @param cli: CLI string
38 debug("CLI: %s" % (cli))
40 def after_cli(self, cli):
42 Function called after CLI call
47 class VppDiedError(Exception):
52 """ Hook which checks if the vpp subprocess is alive """
54 def __init__(self, testcase):
56 self.testcase = testcase
58 def spawn_gdb(self, gdb_path, core_path):
59 gdb_cmdline = gdb_path + ' ' + self.testcase.vpp_bin + ' ' + core_path
60 gdb = pexpect.spawn(gdb_cmdline)
67 raise Exception("GDB refused to die...")
69 def on_crash(self, core_path):
70 if self.testcase.interactive:
71 gdb_path = '/usr/bin/gdb'
72 if os.path.isfile(gdb_path) and os.access(gdb_path, os.X_OK):
73 # automatically attach gdb
74 self.spawn_gdb(gdb_path, core_path)
77 error("Debugger '%s' does not exist or is not an executable.." %
80 critical('core file present, debug with: gdb ' +
81 self.testcase.vpp_bin + ' ' + core_path)
85 Poll the vpp status and throw an exception if it's not running
86 :raises VppDiedError: exception if VPP is not running anymore
89 # already dead, nothing to do
92 self.testcase.vpp.poll()
93 if self.testcase.vpp.returncode is not None:
95 (k, v) for v, k in reversed(sorted(signal.__dict__.items()))
96 if v.startswith('SIG') and not v.startswith('SIG_'))
97 msg = "VPP subprocess died unexpectedly with returncode %d [%s]" % (
98 self.testcase.vpp.returncode,
99 signaldict[abs(self.testcase.vpp.returncode)])
101 core_path = self.testcase.tempdir + '/core'
102 if os.path.isfile(core_path):
103 self.on_crash(core_path)
104 self.testcase.vpp_dead = True
105 raise VppDiedError(msg)
107 def after_api(self, api_name, api_args):
109 Check if VPP died after executing an API
111 :param api_name: name of the API
112 :param api_args: tuple containing the API arguments
113 :raises VppDiedError: exception if VPP is not running anymore
116 super(PollHook, self).after_api(api_name, api_args)
119 def after_cli(self, cli):
121 Check if VPP died after executing a CLI
123 :param cli: CLI string
124 :raises Exception: exception if VPP is not running anymore
127 super(PollHook, self).after_cli(cli)