Commit c98f7f87 authored by Mikołaj Nowicki's avatar Mikołaj Nowicki Committed by Mikołaj Nowicki

Add --hostalias-file flag that combines hostnames

New '--combine' approach, flag takes file as an argument and basing on
regex's from it matches similiar hostnames.
Signed-off-by: Mikołaj Nowicki's avatarMikolaj Nowicki <mikolaj.nowicki@intel.com>
parent 842c3b24
......@@ -2,4 +2,5 @@ __pycache__/
*.pyc
*.pyo
*~
hostaliases.rx
^shard-(.*?)-?\d+$ shard-\1
^test1$ test2
......@@ -18,7 +18,7 @@ if __name__ == "__main__":
ap.add_argument('-o','--output', help="Output html prefix", type=str, default='')
ap.add_argument('--heatmap', help="Create heatmap", default=False, action='store_true')
ap.add_argument('--combine', type=str, default=None,
help="Combine results for similar hosts")
help="Deprecated| Combine results for similar hosts")
ap.add_argument('--testsort', default=False, action='store_true',
help="Sort tests in alphabetical order")
ap.add_argument('-d', '--depth', type=int, default=0,
......@@ -26,6 +26,8 @@ if __name__ == "__main__":
ap.add_argument('--buildorder', type=str, default=None,
help="Filename for build order information")
ap.add_argument('files', help="Files to be visualized", metavar='files', nargs='+', type=str)
ap.add_argument('-a','--hostalias-file', type=str, default=None,
help="Combine results for similiar hosts based on RegEx file")
args = ap.parse_args()
......@@ -33,6 +35,17 @@ if __name__ == "__main__":
if args.buildorder: readbuildorder(args.buildorder)
if args.hostalias_file:
try:
read_hostalias_file(args.hostalias_file)
except Exception as e:
print("Err:",e)
exit(1)
else:
try:
read_hostalias_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hostaliases.rx"))
except: pass
try: jsons = readfiles(args.files, combine=args.combine) # arranged by [(build,host)]
except (KeyboardInterrupt) as e:
print("ERROR: Keyboard interrupt while reading files")
......
......@@ -30,7 +30,7 @@ def parse_args():
ap.add_argument('-c','--collate', type=str, default=None,
help="Collate these results, example: -c notrun,pass")
ap.add_argument('--combine', type=str, default=None,
help="Combine results for similar hosts")
help="Deprecated| Combine results for similar hosts")
ap.add_argument('--buildorder', type=str, default=None,
help="Filename for build order information")
ap.add_argument('--builddesc', type=str, default=None,
......@@ -39,7 +39,8 @@ def parse_args():
help="Create html page with only changed results within test/host")
ap.add_argument('files', metavar='files', nargs='+', type=str,
help="Piglit json files to be visualized")
ap.add_argument('-a','--hostalias-file', type=str, default=None,
help="Combine results for similiar hosts based on RegEx file")
return ap.parse_args()
# Truncate and remove single test result as much as we can for size
......@@ -70,6 +71,17 @@ def main():
if args.buildorder:
readbuildorder(args.buildorder)
if args.hostalias_file:
try:
read_hostalias_file(args.hostalias_file)
except Exception as e:
print("Err:",e)
exit(1)
else:
try:
read_hostalias_file(os.path.join(os.path.dirname(os.path.realpath(__file__)), "hostaliases.rx"))
except: pass
# Build a dict for extra information in html
# builddesc file format:
# build<space>description
......
......@@ -53,7 +53,34 @@ intel_gpu_gens = [
( "cl-", 4.2 ) # Crestline Gen4 GMAX3100
]
def readfiles_parallel(q, files=[], combine='shard'):
hostaliases = {}
def read_hostalias_file(filename):
'''Read in regex-replace pairs for hostname aliasing'''
global hostaliases
try:
with open(filename, 'r') as fp:
for line in fp.readlines():
r,s = line.strip().split(' ', 1)
hostaliases[re.compile(r)]=s
print(f'Host alias file loaded from: {filename}')
except (OSError, IOError, UnicodeDecodeError, EOFError) as e:
raise e
return hostaliases
def hostalias(hostname):
'''Go through ordered dict of regex matches.
Use first matching or return None (no matches)'''
global hostaliases
for r in hostaliases.keys():
if r.match(hostname):
return re.sub(r, hostaliases[r],hostname,count=1)
return None
def readfiles_parallel(q,files=[], combine='shard'):
for filename in files:
j = None
try:
......@@ -122,14 +149,15 @@ def readfiles_parallel(q, files=[], combine='shard'):
if j['tests'][test]['result'] == 'incomplete':
incompleted = True
# Workaround: combine shards
# This is needed for sensible comparison and more concise html
if combine and combine in host:
alias = hostalias(host)
# combine will be deprecated
if not alias and combine and combine in host:
alias=re.match("(.*?)-?[0-9]{1,3}$", host).group(1)
if alias:
for test in j['tests']:
j['tests'][test]['hostname']=host
# need number in the end of hostname
host=re.match("(.*?)-?[0-9]{1,3}$", host).group(1)
host=alias
q.put((build, host, j))
......
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