Example #1
0
    def test_complex_entry_and_task_name_found_for_item_change(self, kind):
        """
        Test if we find both log entry and the belonging ansible task name, we return both.
        """
        expected_task_name = "task name"
        expected_log_entry = {
            "changed":
            False,
            "other":
            True,
            "stdout_lines": [
                "WARN -- : MONGODB | Unsupported client option 'max_retries'. It will be ignored.",
                "/edx/app/forum/.gem/ruby/2.5.0/gems/rake-12.0.0/exe/rake:27:in `<top (required)>'"
            ]
        }

        self.appserver.logger.info('Usual log message')
        self.appserver.logger.warning('A warning message')

        self.appserver.logger.info(f'TASK [{expected_task_name}]')
        self.appserver.logger.info(
            f'{kind}: [1.2.3.4]: FAILED! => (item={json.dumps(expected_log_entry)})'
        )

        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, _ = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, expected_task_name)
        self.assertDictEqual(log_entry, expected_log_entry)
Example #2
0
    def test_entry_and_task_name_found(self):
        """
        Test if we find both log entry and the belonging ansible task name, we return both.
        """
        expected_task_name = "task name"
        expected_log_entry = {
            "changed": False,
            "other": True,
            "stdout_lines": []
        }

        self.appserver.logger.info('Usual log message')
        self.appserver.logger.warning('A warning message')

        self.appserver.logger.info(f'TASK [{expected_task_name}]')
        self.appserver.logger.info(
            f'fatal: [1.2.3.4]: FAILED! => {json.dumps(expected_log_entry)}')

        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, _ = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, expected_task_name)
        self.assertDictEqual(log_entry, expected_log_entry)
Example #3
0
    def test_entry_found_without_task_name(self):
        """
        Test when entry found without task, the entry returned, but task name remains
        empty. This behaviour is expected, since the value is in the log entry not in the
        ansible task name.
        """
        expected_log_entry = {
            "changed": False,
            "other": True,
            "stdout_lines": []
        }

        self.appserver.logger.info('Usual log message')
        self.appserver.logger.warning('A warning message')

        self.appserver.logger.info('fatal: [1.2.3.4]: FAILED! => {}'.format(
            json.dumps(expected_log_entry)))

        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, _ = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, "")
        self.assertDictEqual(log_entry, expected_log_entry)
Example #4
0
    def test_no_entries_found(self):
        """
        Test when no log entries found, we return default values, so processing
        result can continue.
        """
        self.appserver.logger.info('Usual log message')
        self.appserver.logger.warning('A warning message')
        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, _ = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, "")
        self.assertDictEqual(log_entry, dict())
    def test_entry_and_task_name_not_found_within_the_log_limit(self):
        """
        Test that the log entries don't contain information past the cutoff point even if those
        entries might have matched otherwise, and it would result in the log being empty.
        """
        self.appserver.logger.info('TASK [task name]')
        self.appserver.logger.info(
            'failed: [1.2.3.4] (item={"state": "present", "password": "******", "name": "397bf39ead3d3751"}) => '
            '{"ansible_loop_var": "item", "changed": false, "item": {"name": "397bf39ead3d3751", "password": "******",'
            '"state": "present"}, "msg": "Failed to import the required Python library (passlib) on '
            'edxapp-periodic-buil-appserver-1039\'s Python /usr/bin/python3. Please read module documentation and '
            'install in the appropriate location"}', )
        self.appserver.logger.info(
            'fatal: [1.2.3.4]: FAILED! => {"changed": true, "stdout_lines": ["out"], "stderr_lines": ["err"]}'
        )

        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, other_logs = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, "")
        self.assertDictEqual(log_entry, dict())
        self.assertListEqual(other_logs, [{
            'ansible_loop_var':
            'item',
            'changed':
            False,
            'item': {
                'name': '397bf39ead3d3751',
                'password': '******',
                'state': 'present'
            },
            'msg':
            ('Failed to import the required Python library (passlib) on '
             "edxapp-periodic-buil-appserver-1039's Python /usr/bin/python3. "
             'Please read module documentation and install in the appropriate '
             'location')
        }, {
            'changed': True,
            'stderr_lines': ['err'],
            'stdout_lines': ['out']
        }])
Example #6
0
    def test_entry_and_task_name_not_found_within_the_log_limit(self):
        """
        Test that the log entries don't contain information past the cutoff point even if those
        entries might have matched otherwise, and it would result in the log being empty.
        """
        self.appserver.logger.info('TASK [task name]')
        self.appserver.logger.info(
            'fatal: [1.2.3.4]: FAILED! => {"changed": true, "stdout_lines": ["out"], "stderr_lines": ["err"]}'
        )

        self.appserver.logger.error(
            "Some error happened, but that's not Ansible related")
        self.appserver.logger.error("Other error message happened")

        task_name, log_entry, other_logs = get_ansible_failure_log_entry(
            self.appserver.log_entries_queryset)

        self.assertEqual(task_name, "")
        self.assertDictEqual(log_entry, dict())
        self.assertListEqual(other_logs, ["out", "err"])