Commit a950904f authored by Daniel Salzman's avatar Daniel Salzman

tests-extra: print error after exception if any

parent 4f32b2f3
......@@ -165,6 +165,20 @@ def main(args):
except dnstest.utils.Skip as exc:
log.error(case_str_err + "SKIPPED (%s)" % format(exc))
skip_cnt += 1
except dnstest.utils.Failed as exc:
save_traceback(params.out_dir)
desc = format(exc)
msg = "FAILED (%s)" % (desc if desc else exc.__class__.__name__)
if params.err and params.err_msg:
msg += " AND (" + params.err_msg + ")"
log.error(case_str_err + msg)
log_failed(outs_dir, case_str_fail + msg)
if params.debug:
traceback.print_exc()
fail_cnt += 1
except Exception as exc:
save_traceback(params.out_dir)
......@@ -190,7 +204,7 @@ def main(args):
else:
if params.err:
msg = "FAILED" + \
(("(" + params.err_msg + ")") if params.err_msg else "")
((" (" + params.err_msg + ")") if params.err_msg else "")
log.info(case_str_err + msg)
log_failed(outs_dir, case_str_fail + msg)
fail_cnt += 1
......
......@@ -50,7 +50,7 @@ class Tsig(object):
self.alg = random.choice(list(Tsig.algs.keys()))
else:
if alg not in Tsig.algs:
raise Exception("Unsupported TSIG algorithm %s" % alg)
raise Failed("Unsupported TSIG algorithm %s" % alg)
self.alg = alg
if not key:
......@@ -104,5 +104,5 @@ class Key(object):
self.name = out.strip()
if cmd.returncode != 0 or self.name[0] != "K":
raise Exception("Can't generate key for %s zone" % self.zone_name)
raise Failed("Can't generate key for %s zone" % self.zone_name)
......@@ -23,7 +23,7 @@ def zone_arg_check(zone):
# Convert one item list to single object.
if isinstance(zone, list):
if len(zone) != 1:
raise Exception("One zone required")
raise Failed("One zone required")
return zone[0]
return zone
......@@ -205,7 +205,7 @@ class Server(object):
'''Set the server as a slave for the zone'''
if zone.name in self.zones:
raise Exception("Can't set zone='%s' as a slave" % zone.name)
raise Failed("Can't set zone='%s' as a slave" % zone.name)
slave_file = zone.clone(self.dir + "/slave", exists=False)
z = Zone(slave_file, ddns, ixfr)
......@@ -218,7 +218,7 @@ class Server(object):
stdout=self.fout, stderr=self.ferr)
p.communicate(timeout=Server.COMPILE_TIMEOUT)
except:
raise Exception("Can't compile server='%s'" %self.name)
raise Failed("Can't compile server='%s'" %self.name)
def start(self, clean=False):
mode = "w" if clean else "a"
......@@ -238,7 +238,7 @@ class Server(object):
else:
time.sleep(Server.START_WAIT)
except OSError:
raise Exception("Can't start server='%s'" % self.name)
raise Failed("Can't start server='%s'" % self.name)
# Start inquirer if enabled.
if params.test.stress and self.inquirer:
......@@ -252,8 +252,8 @@ class Server(object):
time.sleep(Server.START_WAIT)
except CalledProcessError as e:
self.backtrace()
raise Exception("Can't reload server='%s', ret='%i'" %
(self.name, e.returncode))
raise Failed("Can't reload server='%s', ret='%i'" %
(self.name, e.returncode))
def flush(self):
try:
......@@ -263,8 +263,8 @@ class Server(object):
time.sleep(Server.START_WAIT)
except CalledProcessError as e:
self.backtrace()
raise Exception("Can't flush server='%s', ret='%i'" %
(self.name, e.returncode))
raise Failed("Can't flush server='%s', ret='%i'" %
(self.name, e.returncode))
def running(self):
proc = psutil.Process(self.proc.pid)
......@@ -400,7 +400,7 @@ class Server(object):
# Convert one item zone list to zone name.
if isinstance(rname, list):
if len(rname) != 1:
raise Exception("One zone required")
raise Failed("One zone required")
rname = rname[0].name
rtype_str = rtype.upper()
......@@ -531,8 +531,8 @@ class Server(object):
except:
time.sleep(timeout)
raise Exception("Can't query server='%s' for '%s %s %s'" % \
(self.name, rname, rclass, rtype))
raise Failed("Can't query server='%s' for '%s %s %s'" % \
(self.name, rname, rclass, rtype))
def create_sock(self, socket_type):
family = socket.AF_INET
......@@ -545,8 +545,8 @@ class Server(object):
sock = self.create_sock(socket.SOCK_DGRAM)
sent = sock.sendto(bytes(data, 'utf-8'), (self.addr, self.port))
if sent != len(data):
raise Exception("Can't send RAW data (%d bytes) to server='%s'" %
(len(data), self.name))
raise Failed("Can't send RAW data (%d bytes) to server='%s'" %
(len(data), self.name))
def zone_wait(self, zone, serial=None):
'''Try to get SOA record with serial higher then specified'''
......@@ -566,8 +566,8 @@ class Server(object):
else:
if resp.resp.rcode() == 0:
if not resp.resp.answer:
raise Exception("No SOA in ANSWER, zone='%s', server='%s'" %
(zone.name, self.name))
raise Failed("No SOA in ANSWER, zone='%s', server='%s'" %
(zone.name, self.name))
soa = str((resp.resp.answer[0]).to_rdataset())
_serial = int(soa.split()[5])
......@@ -580,9 +580,9 @@ class Server(object):
time.sleep(2)
else:
self.backtrace()
raise Exception("Can't get SOA%s, zone='%s', server='%s'" %
(" serial > %i" % serial if serial else "",
zone.name, self.name))
raise Failed("Can't get SOA%s, zone='%s', server='%s'" %
(" serial > %i" % serial if serial else "",
zone.name, self.name))
detail_log(SEP)
......@@ -666,7 +666,7 @@ class Server(object):
# Convert one item list to single object.
if isinstance(zone, list):
if len(zone) != 1:
raise Exception("One zone required")
raise Failed("One zone required")
zone = zone[0]
self.zones[zone.name].add_query_module(module, param)
......
......@@ -36,7 +36,7 @@ class Test(object):
self.ip = ip if ip else random.choice([4, 6])
if self.ip not in [4, 6]:
raise Exception("Invalid IP version")
raise Failed("Invalid IP version")
self.tsig = None
if tsig != None:
......@@ -108,7 +108,7 @@ class Test(object):
elif server == "dummy":
srv = dnstest.server.Dummy()
else:
raise Exception("Unsupported server '%s'" % server)
raise Failed("Unsupported server '%s'" % server)
type(srv).count += 1
......@@ -168,7 +168,7 @@ class Test(object):
'''Start all test servers'''
if self.start_tries > Test.MAX_START_TRIES:
raise Exception("Can't start all servers")
raise Failed("Can't start all servers")
self.start_tries += 1
......@@ -185,7 +185,7 @@ class Test(object):
server.start(clean=True)
if not server.running():
raise Exception("Server '%s' not running" % server.name)
raise Failed("Server '%s' not running" % server.name)
if not server.listening():
self.stop(kill=True)
......@@ -245,12 +245,12 @@ class Test(object):
def link(self, zones, master, slave=None, ddns=False, ixfr=False):
for zone in zones:
if master not in self.servers:
raise Exception("Server is out of testing scope")
raise Failed("Server is out of testing scope")
master.set_master(zone, slave, ddns, ixfr)
if slave:
if slave not in self.servers:
raise Exception("Server is out of testing scope")
raise Failed("Server is out of testing scope")
slave.set_slave(zone, master, ddns, ixfr)
def _canonize_record(self, rtype, record):
......
......@@ -12,6 +12,10 @@ class Skip(Exception):
"""Exception for skipping current case."""
pass
class Failed(Exception):
"""Exception for serious error."""
pass
def prepare_dir(path):
try:
os.makedirs(path)
......
......@@ -96,7 +96,7 @@ class ZoneFile(object):
+ params
if zone_generate.main(params) != 0:
raise OSError
except OSError:
raise Exception("Can't create zone file '%s'" % self.path)
......
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