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