Implement validation show history command

Implement validation show history command in validation_actions

Change-Id: I97c9df5e08c2358612704fcdb78cf24cd6f8e421
This commit is contained in:
Mathieu Bultel 2020-03-22 22:29:21 +01:00 committed by mathieu bultel
parent 2028851815
commit e367d62445
2 changed files with 37 additions and 3 deletions

View File

@ -12,13 +12,12 @@
# License for the specific language governing permissions and limitations
# under the License.
#
import logging
import os
from validations_libs.ansible import Ansible as v_ansible
from validations_libs.group import Group
from validations_libs.validation_logs import ValidationLogs
from validations_libs.validation_logs import ValidationLogs, ValidationLog
from validations_libs import constants
from validations_libs import utils as v_utils
@ -150,3 +149,22 @@ class ValidationActions(object):
return v_utils.get_validations_parameters({'validations': validations},
validation,
group)
def show_history(self, validation_id):
"""Return validations history"""
vlogs = ValidationLogs()
logs = (vlogs.get_logfile_by_validation(validation_id)
if validation_id else vlogs.get_all_logfiles())
values = []
column_name = ('UUID', 'Validations',
'Status', 'Execution at',
'Duration')
for log in logs:
vlog = ValidationLog(logfile=log)
values.append((vlog.get_uuid, vlog.validation_id,
vlog.get_status, vlog.get_start_time,
vlog.get_duration))
return (column_name, values)

View File

@ -126,6 +126,12 @@ class ValidationLog(object):
return ', '.join([play['play']['duration'].get('time_elapsed') for
play in self.content['plays']])
@property
def get_start_time(self):
"""Return Ansible start time"""
return ', '.join([play['play']['duration'].get('start') for
play in self.content['plays']])
class ValidationLogs(object):
@ -136,6 +142,16 @@ class ValidationLogs(object):
with open(file, 'r') as log_file:
return yaml.safe_load(log_file)[0]
def get_logfile_by_validation(self, validation_id):
"""Return logfiles by validation_id"""
return glob.glob("{}/*_{}_*".format(self.logs_path, validation_id))
def get_logfile_content_by_validation(self, validation_id):
"""Return logfiles content by validation_id"""
log_files = glob.glob("{}/*_{}_*".format(self.logs_path,
validation_id))
return [self._get_content(l) for l in log_files]
def get_logfile_by_uuid(self, uuid):
"""Return logfiles by uuid"""
return glob.glob("{}/{}_*".format(self.logs_path, uuid))
@ -158,7 +174,7 @@ class ValidationLogs(object):
def get_all_logfiles(self):
"""Return logfiles from logs_path"""
return [f for f in listdir(self.logs_path) if
return [join(self.logs_path, f) for f in listdir(self.logs_path) if
isfile(join(self.logs_path, f))]
def get_all_logfiles_content(self):