Exemple #1
0
 def test_get_log_path(self, mock_open, mock_yaml, mock_glob):
     mock_glob.return_value = \
         ['/tmp/123_foo_2020-03-30T13:17:22.447857Z.json']
     val = ValidationLog(uuid='123', validation_id='foo', log_path='/tmp')
     path = val.get_log_path()
     self.assertEquals(path,
                       '/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
Exemple #2
0
 def test_validation_wrong_log_file(self, mock_open, mock_json):
     msg = ('Wrong log file format, it should be formed '
            'such as {uuid}_{validation-id}_{timestamp}')
     with mock.patch('logging.Logger.warning') as mock_log:
         ValidationLog(
             logfile='/tmp/foo_2020-03-30T13:17:22.447857Z.json')
         mock_log.assert_called_with(msg)
Exemple #3
0
 def test_get_logfile_infos(self, mock_open, mock_json, mock_glob):
     mock_glob.return_value = \
         ['/tmp/123_foo_2020-03-30T13:17:22.447857Z.json']
     val = ValidationLog(uuid='123', validation_id='foo', log_path='/tmp')
     log_info = val.get_logfile_infos
     self.assertEquals(log_info,
                       ['123', 'foo', '2020-03-30T13:17:22.447857Z'])
Exemple #4
0
 def test_get_plays(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     plays = val.get_plays
     self.assertEquals(
         plays,
         [fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0]['plays'][0]['play']])
Exemple #5
0
 def test_get_tasks_data(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     tasks_data = val.get_tasks_data
     self.assertEquals(
         tasks_data,
         [fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0]
          ['validation_output'][0]['task']])
Exemple #6
0
 def test_get_duration_bad_data(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     duration = val.get_duration
     self.assertEquals(duration, '')
Exemple #7
0
 def test_validation_underscore_validation_id(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_bar_2020-03-30T13:17:22.447857Z.json')
     self.assertEquals(val.uuid, '123')
     self.assertEquals(val.validation_id, 'foo_bar')
     self.assertEquals(val.datetime, '2020-03-30T13:17:22.447857Z')
Exemple #8
0
 def test_validation_validation_id_wo_uuid(self, mock_open, mock_json):
     with self.assertRaises(Exception) as exc_mgr:
         ValidationLog(validation_id='foo')
     self.assertEqual('When not using logfile argument, the uuid and '
                      'validation_id have to be set',
                      str(exc_mgr.exception))
 def test_get_host_group(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     host_group = val.get_host_group
     self.assertEqual(host_group, 'undercloud')
Exemple #10
0
 def test_is_valid_format(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     self.assertTrue(val.is_valid_format())
Exemple #11
0
 def test_get_logfile_content(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     content = val.get_logfile_content
     self.assertEquals(content, fakes.VALIDATIONS_LOGS_CONTENTS_LIST)
Exemple #12
0
    def show_history(self, validation_ids=None, extension='json',
                     log_path=constants.VALIDATIONS_LOG_BASEDIR):
        """Return validation executions history

        :param validation_ids: The validation ids
        :type validation_ids: a list of strings
        :param extension: The log file extension (Defaults to ``json``)
        :type extension: ``string``
        :param log_path: The absolute path of the validations logs directory
        :type log_path: ``string``

        :return: Returns the information about the validation executions
                 history
        :rtype: ``tuple``

        :Example:

        >>> actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR)
        >>> print(actions.show_history())
        (('UUID', 'Validations', 'Status', 'Execution at', 'Duration'),
         [('5afb1597-e2a1-4635-b2df-7afe21d00de6',
         'foo',
         'PASSED',
         '2020-11-13T11:47:04.740442Z',
         '0:00:02.388'),
         ('32a5e217-d7a9-49a5-9838-19e5f9b82a77',
         'foo2',
         'PASSED',
         '2020-11-13T11:47:07.931184Z',
         '0:00:02.455'),
         ('62d4d54c-7cce-4f38-9091-292cf49268d7',
         'foo',
         'PASSED',
         '2020-11-13T11:47:47.188876Z',
         '0:00:02.285'),
         ('04e6165c-7c33-4881-bac7-73ff3f909c24',
         'foo3',
         'PASSED',
         '2020-11-13T11:47:50.279662Z',
         '0:00:02.237')])
        >>> actions = ValidationActions(constants.ANSIBLE_VALIDATION_DIR)
        >>> print(actions.show_history(validation_ids=['foo']))
        (('UUID', 'Validations', 'Status', 'Execution at', 'Duration'),
         [('5afb1597-e2a1-4635-b2df-7afe21d00de6',
         'foo',
         'PASSED',
         '2020-11-13T11:47:04.740442Z',
         '0:00:02.388'),
         ('04e6165c-7c33-4881-bac7-73ff3f909c24',
         'foo',
         'PASSED',
         '2020-11-13T11:47:50.279662Z',
         '0:00:02.237')])
        """
        vlogs = ValidationLogs(log_path)
        if validation_ids:
            if not isinstance(validation_ids, list):
                validation_ids = [validation_ids]
            logs = []
            for validation_id in validation_ids:
                logs.extend(vlogs.get_logfile_by_validation(validation_id))
        else:
            logs = vlogs.get_all_logfiles(extension)

        values = []
        column_name = ('UUID', 'Validations',
                       'Status', 'Execution at',
                       'Duration')
        for log in logs:
            vlog = ValidationLog(logfile=log)
            if vlog.is_valid_format():
                for play in vlog.get_plays:
                    values.append((play['id'], play['validation_id'],
                                   vlog.get_status,
                                   play['duration'].get('start'),
                                   play['duration'].get('time_elapsed')))
        return (column_name, values)
Exemple #13
0
 def test_get_unreachable_hosts_bad_data(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     unreachable = val.get_unreachable_hosts
     self.assertEquals(unreachable, 'undercloud')
Exemple #14
0
 def test_get_hosts_status_unreachable(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     host_group = val.get_hosts_status
     self.assertEquals(host_group, 'undercloud,UNREACHABLE')
Exemple #15
0
 def test_get_hosts_status_failed(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     host_group = val.get_hosts_status
     self.assertEquals(host_group, 'undercloud,FAILED')
Exemple #16
0
 def test_get_status_unreachable(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     status = val.get_status
     self.assertEquals(status, 'FAILED')
Exemple #17
0
 def test_get_validation_id(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     validation_id = val.get_validation_id
     self.assertEquals(validation_id, 'foo')
     self.assertEquals(val.validation_id, 'foo')
Exemple #18
0
 def test_get_start_time(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     start_time = val.get_start_time
     self.assertEquals(start_time, '2019-11-25T13:40:14.404623Z')
Exemple #19
0
 def test_get_start_time_bad_data(self, mock_open, mock_json):
     val = ValidationLog(
         logfile='/tmp/123_foo_2020-03-30T13:17:22.447857Z.json')
     start_time = val.get_start_time
     self.assertEquals(start_time, '')
Exemple #20
0
    def get_status(self, validation_id=None, uuid=None, status='FAILED',
                   log_path=constants.VALIDATIONS_LOG_BASEDIR):
        """Return validations execution details by status

        :param validation_id: The validation id
        :type validation_id: ``string``
        :param uuid: The UUID of the execution
        :type uuid: ``string``
        :param status: The status of the execution (Defaults to FAILED)
        :type status: ``string``
        :param log_path: The absolute path of the validations logs directory
        :type log_path: ``string``

        :return: A list of validations execution with details and by status
        :rtype: ``tuple``

        :Example:

        >>> actions = ValidationActions(validation_path='/foo/bar')
        >>> status = actions.get_status(validation_id='foo'))
        >>> print(status)
        (['name', 'host', 'status', 'task_data'],
         [('Check if debug mode is disabled.',
         'localhost',
         'FAILED',
         {'_ansible_no_log': False,
             'action': 'fail',
             'changed': False,
             'failed': True,
             'msg': 'Debug mode is not disabled.'}),
         ('Check if debug mode is disabled.',
         'localhost',
         'FAILED',
         {'_ansible_no_log': False,
             'action': 'fail',
             'changed': False,
             'failed': True,
             'msg': 'Debug mode is not disabled.'}),
         ('Check if debug mode is disabled.',
         'localhost',
         'FAILED',
         {'_ansible_no_log': False,
             'action': 'fail',
             'changed': False,
             'failed': True,
             'msg': 'Debug mode is not disabled.'})])
        """
        vlogs = ValidationLogs(log_path)
        if validation_id:
            logs = vlogs.get_logfile_by_validation(validation_id)
        elif uuid:
            logs = vlogs.get_logfile_by_uuid(uuid)
        else:
            raise RuntimeError("You need to provide a validation_id or a uuid")

        values = []
        column_name = ['name', 'host', 'status', 'task_data']
        for log in logs:
            vlog = ValidationLog(logfile=log)
            if vlog.is_valid_format():
                for task in vlog.get_tasks_data:
                    if task['status'] == status:
                        for host in task['hosts']:
                            values.append((task['name'], host, task['status'],
                                           task['hosts'][host]))
        return (column_name, values)
 def test_get_logfile_datetime(self, mock_open, mock_json, mock_glob):
     mock_glob.return_value = \
         ['/tmp/123_foo_2020-03-30T13:17:22.447857Z.json']
     val = ValidationLog(uuid='123', validation_id='foo', log_path='/tmp')
     datetime = val.get_logfile_datetime
     self.assertEqual(datetime, '2020-03-30T13:17:22.447857Z')