Commit 3bc71ce3 authored by Grigorii Demidov's avatar Grigorii Demidov

basic error recovery capabilities for STEP CHECK ANSWER were implemented

parent 2b6a1249
......@@ -91,7 +91,7 @@ def parse_entry(op, args, file_in):
def parse_step(op, args, file_in):
""" Parse range definition. """
if len(args) < 2:
raise Exception('expected STEP <id> <type>')
raise Exception('expected at least STEP <id> <type>')
extra_args = []
if len(args) > 2:
extra_args = args[2:]
......
......@@ -272,6 +272,23 @@ class Step:
self.has_data = self.type not in Step.require_data
self.answer = None
self.raw_answer = None
self.repeat_if_fail = 0
self.pause_if_fail = 0
self.next_if_fail = -1
if type == 'CHECK_ANSWER':
for arg in extra_args:
param = arg.split('=')
try:
if param[0] == 'REPEAT':
self.repeat_if_fail = int(param[1])
elif param[0] == 'PAUSE':
self.pause_if_fail = float(param[1])
elif param[0] == 'NEXT':
self.next_if_fail = int(param[1])
except Exception as e:
raise Exception('step #%d - wrong %s arg: %s' % (self.id, param[0], str(e)))
def add(self, entry):
""" Append a data entry to this step. """
......@@ -402,15 +419,31 @@ class Scenario:
self.child_sock.settimeout(2)
self.child_sock.connect((paddr, 53))
step = None
if len(self.steps) == 0:
raise ('no steps in this scenario')
try:
for step in self.steps:
step = None
i = 0
while i < len(self.steps):
step = self.steps[i]
self.current_step = step
step.play(self, paddr)
except Exception as e:
raise Exception('step #%d %s' % (step.id, str(e)))
try:
step.play(self, paddr)
except Exception as e:
if (step.repeat_if_fail > 0):
dprint ('[play]',"step %d: exception catched - '%s', retrying step %d (%d left)" % (step.id, e, step.next_if_fail, step.repeat_if_fail))
step.repeat_if_fail -= 1
if (step.pause_if_fail > 0):
time.sleep(step.pause_if_fail)
if (step.next_if_fail != -1):
next_step = [j for j in range(len(self.steps)) if self.steps[j].id == step.next_if_fail][0]
if (next_step < len(self.steps)):
i = next_step
continue
else:
raise Exception('step #%d %s' % (step.id, str(e)))
i = i + 1
finally:
self.child_sock.close()
self.child_sock = None
......@@ -34,18 +34,33 @@ example.com. IN SOA
SECTION ANSWER
example.com. 3600 IN SOA dns1.example.com. hostmaster.example.com. 2010111213 21600 3600 604800 86400
ENTRY_END
RANGE_END
STEP 10 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
example.com IN SOA
ENTRY_END
STEP 20 CHECK_ANSWER REPEAT=3 PAUSE=1 NEXT=10
ENTRY_BEGIN
MATCH all
REPLY QR AA RD NOERROR
SECTION QUESTION
example.com IN SOA
SECTION ANSWER
example.com. 3600 IN SOA dns1.example.com. hostmaster.example.com. 2010111213 21600 3600 604800 86400
ENTRY_END
STEP 1 QUERY
STEP 30 QUERY
ENTRY_BEGIN
REPLY RD
SECTION QUESTION
example.com IN NS
ENTRY_END
STEP 2 CHECK_ANSWER
STEP 40 CHECK_ANSWER
ENTRY_BEGIN
MATCH all
REPLY QR AA RD NOERROR
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment