Lines Matching +full:event +full:- +full:name

2 # NBD server - fault injection utility
5 # [inject-error "disconnect-neg1"]
6 # event=neg1
11 # name, so give each [inject-error] a unique name.
13 # inject-error options:
14 # event - name of the trigger event
15 # "neg1" - first part of negotiation struct
16 # "export" - export struct
17 # "neg2" - second part of negotiation struct
18 # "request" - NBD request struct
19 # "reply" - NBD reply struct
20 # "data" - request/reply data
21 # io - I/O direction that triggers this rule:
24 # when - after how many bytes to inject the fault
25 # -1 - inject error after I/O
26 # 0 - inject error before I/O
27 # integer - inject error after integer bytes
28 # "before" - alias for 0
29 # "after" - alias for -1
44 # See the COPYING file in the top-level directory.
83 chunk = sock.recv(bufsize - received)
91 def __init__(self, name, event, io, when): argument
92 self.name = name
93 self.event = event
97 def match(self, event, io): argument
98 if event != self.event:
109 def check(self, event, io, bufsize=None): argument
111 if rule.match(event, io):
113 print('Closing connection on rule match %s' % rule.name)
117 if rule.when != -1:
121 def send(self, buf, event): argument
122 bufsize = self.check(event, 'write', bufsize=len(buf))
124 self.check(event, 'write')
126 def recv(self, bufsize, event): argument
127 bufsize = self.check(event, 'read', bufsize=bufsize)
129 self.check(event, 'read')
138 conn.send(buf, event='neg-classic')
143 conn.send(buf, event='neg1')
146 buf = conn.recv(export_struct.size, event='export')
150 name = conn.recv(export.len, event='export-name')
154 conn.send(buf, event='neg2')
165 buf = conn.recv(request_struct.size, event='request')
172 conn.send(buf, event='reply')
180 conn.send(b'\0' * req.len, event='data')
182 _ = conn.recv(req.len, event='data')
196 def parse_inject_error(name, options): argument
197 if 'event' not in options:
198 err('missing \"event\" option in %s' % name)
199 event = options['event']
200 if event not in ('neg-classic', 'neg1', 'export', 'neg2', 'request', 'reply', 'data'):
201 err('invalid \"event\" option value \"%s\" in %s' % (event, name))
204 err('invalid \"io\" option value \"%s\" in %s' % (io, name))
212 when = -1
214 err('invalid \"when\" option value \"%s\" in %s' % (when, name))
215 return Rule(name, event, io, when)
219 for name in config.sections():
220 if name.startswith('inject-error'):
221 options = dict(config.items(name))
222 rules.append(parse_inject_error(name, options))
224 err('invalid config section name: %s' % name)
252 …sys.stderr.write('usage: %s [--classic-negotiation] <tcp-port>|<unix-path> <config-file>\n' % args…
260 if args[1] == '--classic-negotiation':