Browse Source

Raise exception if no validation is found

In addition, I have to fix pep8 issue, due to new version

Change-Id: I04728bfdb6473c47c248a4a56bb8df647c51f5ef
changes/21/727221/3
Mathieu Bultel 2 years ago
parent
commit
ade5d57a3e
  1. 10
      validations_libs/tests/test_validation_actions.py
  2. 4
      validations_libs/validation_actions.py
  3. 12
      validations_libs/validation_logs.py

10
validations_libs/tests/test_validation_actions.py

@ -81,6 +81,16 @@ class TestValidationActions(TestCase):
validations_dir='/tmp/foo')
self.assertEqual(run_return, expected_run_return)
@mock.patch('validations_libs.utils.get_validations_playbook')
def test_validation_run_wrong_validation_name(self, mock_validation_play):
mock_validation_play.return_value = []
run = ValidationActions()
self.assertRaises(RuntimeError, run.run_validations,
validation_name='fake.yaml',
validations_dir='/tmp/foo'
)
@mock.patch('validations_libs.validation_logs.ValidationLogs.get_results')
@mock.patch('validations_libs.utils.parse_all_validations_on_disk')
@mock.patch('validations_libs.ansible.Ansible.run')

4
validations_libs/validation_actions.py

@ -88,6 +88,10 @@ class ValidationActions(object):
playbooks = v_utils.get_validations_playbook(validations_dir,
validation_name,
group)
if not playbooks:
msg = "Validation {} not found in {}.".format(validation_name,
validations_dir)
raise RuntimeError(msg)
else:
raise RuntimeError("No validations found")

12
validations_libs/validation_logs.py

@ -157,7 +157,7 @@ class ValidationLogs(object):
"""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]
return [self._get_content(log) for log in log_files]
def get_logfile_by_uuid(self, uuid):
"""Return logfiles by uuid"""
@ -166,7 +166,7 @@ class ValidationLogs(object):
def get_logfile_content_by_uuid(self, uuid):
"""Return logfiles content by uuid"""
log_files = glob.glob("{}/{}_*".format(self.logs_path, uuid))
return [self._get_content(l) for l in log_files]
return [self._get_content(log) for log in log_files]
def get_logfile_by_uuid_validation_id(self, uuid, validation_id):
"""Return logfiles by uuid"""
@ -177,7 +177,7 @@ class ValidationLogs(object):
"""Return logfiles content filter by uuid and content"""
log_files = glob.glob("{}/{}_{}_*".format(self.logs_path, uuid,
validation_id))
return [self._get_content(l) for l in log_files]
return [self._get_content(log) for log in log_files]
def get_all_logfiles(self):
"""Return logfiles from logs_path"""
@ -203,13 +203,13 @@ class ValidationLogs(object):
passed_number = 0
last_execution = None
dates = []
for l in logs:
if l.get('validation_output'):
for log in logs:
if log.get('validation_output'):
failed_number += 1
else:
passed_number += 1
date_time = \
l['plays'][0]['play']['duration'].get('start').split('T')
log['plays'][0]['play']['duration'].get('start').split('T')
date_start = date_time[0]
time_start = date_time[1].split('Z')[0]
newdate = \

Loading…
Cancel
Save