Include summary information in action output

When a tempest run is triggered by running the run-tempest action
parse the logfile and include the results eg

> juju action fetch c0a57e2f-62a3-4328-8171-ce23cc8b49a3
results:
  expected-fail: "0"
  failed: "0"
  passed: "21"
  skipped: "49"
  tempest-logfile: /var/lib/tempest/logs/run_20160928123429.log
  unexpected-success: "0"
status: completed
timing:
  completed: 2016-09-28 12:36:33 +0000 UTC
  enqueued: 2016-09-28 10:41:36 +0000 UTC
  started: 2016-09-28 10:41:36 +0000 UTC

Closes-Bug: 1628492
Change-Id: If051e925cc09daaa389cfb89a54c0fc82e672ff1
This commit is contained in:
Liam Young 2016-09-28 12:41:39 +00:00
parent 26b4fb2374
commit 0b835ba2ba
1 changed files with 27 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import re
import os
import subprocess
import time
@ -257,7 +258,7 @@ class TempestCharm(charm.OpenStackCharm):
required_relations = ['identity-admin']
"""Directories and files used for running tempest"""
TEMPEST_ROOT = '/var/lib/tempest/'
TEMPEST_ROOT = '/var/lib/tempest'
TEMPEST_LOGDIR = TEMPEST_ROOT + '/logs'
TEMPEST_CONF = TEMPEST_ROOT + '/tempest.conf'
"""pip.conf for proxy settings etc"""
@ -330,15 +331,37 @@ class TempestCharm(charm.OpenStackCharm):
run_dir = '{}/tempest'.format(git_dir)
return git_dir, logfile, run_dir
def parse_tempest_log(self, logfile):
"""Read tempest logfile and return summary as dict
@return dict: Dictonary of summary data
"""
summary = {}
with open(logfile) as tempest_log:
summary_line = False
for line in tempest_log:
if line.strip() == "Totals":
summary_line = True
if line.strip() == "Worker Balance":
summary_line = False
if summary_line:
# Match lines like: ' - Unexpected Success: 0'
matchObj = re.match(
r'(.*)- (.*?):\s+(.*)', line, re.M | re.I)
if matchObj:
key = matchObj.group(2)
key = key.replace(' ', '-').replace(':', '').lower()
summary[key] = matchObj.group(3)
return summary
def run_test(self, tox_target):
"""Run smoke tests"""
action_args = hookenv.action_get()
branch_name = action_args['branch']
git_dir, logfile, run_dir = self.get_tempest_files(branch_name)
action_info = {
'tempest-logfile': logfile,
}
self.setup_directories()
self.setup_git(branch_name, git_dir)
self.execute_tox(run_dir, logfile, tox_target)
action_info = self.parse_tempest_log(logfile)
action_info['tempest-logfile'] = logfile
hookenv.action_set(action_info)