Merge "Expanding logging facilities to rest of the framework"

This commit is contained in:
Zuul 2022-12-19 13:23:11 +00:00 committed by Gerrit Code Review
commit 430530fad5
10 changed files with 27 additions and 26 deletions

View File

@ -14,7 +14,7 @@
#
import ansible_runner
import logging
from validations_libs.logger import getLogger
import pkg_resources
import pwd
import os
@ -27,7 +27,7 @@ import configparser
from validations_libs import constants
from validations_libs import utils
LOG = logging.getLogger(__name__ + ".ansible")
LOG = getLogger(__name__ + ".ansible")
# NOTE(cloudnull): This is setting the FileExistsError for py2 environments.
# When we no longer support py2 (centos7) this should be
@ -48,7 +48,7 @@ class Ansible:
"""An Object for encapsulating an Ansible execution"""
def __init__(self, uuid=None):
self.log = logging.getLogger(__name__ + ".Ansible")
self.log = getLogger(__name__ + ".Ansible")
self.uuid = uuid
def _playbook_check(self, play, playbook_dir=None):

View File

@ -17,7 +17,7 @@
from argparse import ArgumentDefaultsHelpFormatter
from cliff import _argparse
import json
import logging
from validations_libs.logger import getLogger
from prettytable import PrettyTable
import re
import sys
@ -92,7 +92,7 @@ def write_output(output_log, results):
def write_junitxml(output_junitxml, results):
"""Write output file as JUnitXML format"""
if not JUNIT_XML_FOUND:
log = logging.getLogger(__name__ + ".write_junitxml")
log = getLogger(__name__ + ".write_junitxml")
log.warning('junitxml output disabled: the `junit_xml` python module '
'is missing.')
return

View File

@ -14,7 +14,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import logging
from validations_libs.logger import getLogger
import os
from validations_libs import constants, utils
@ -22,7 +22,7 @@ from validations_libs.cli.base import BaseCommand
from validations_libs.community.init_validation import \
CommunityValidation as com_val
LOG = logging.getLogger(__name__)
LOG = getLogger(__name__)
class CommunityValidationInit(BaseCommand):

View File

@ -15,7 +15,7 @@
# under the License.
#
import logging
from validations_libs.logger import getLogger
import re
import os
# @matbu backward compatibility for stable/train
@ -26,7 +26,7 @@ except ImportError:
from validations_libs import constants, utils
LOG = logging.getLogger(__name__)
LOG = getLogger(__name__)
class CommunityValidation:

View File

@ -13,10 +13,10 @@
# under the License.
#
import logging
from validations_libs.logger import getLogger
import yaml
LOG = logging.getLogger(__name__ + ".Group")
LOG = getLogger(__name__ + ".Group")
class Group:

View File

@ -56,7 +56,7 @@ class TestAnsible(TestCase):
self.run = Ansible()
self.run.log = mock.MagicMock()
@mock.patch('logging.getLogger')
@mock.patch('validations_libs.ansible.getLogger')
def test_ansible_init(self, mock_logger):
"""
Test of Ansible init.

View File

@ -536,7 +536,8 @@ class TestValidationActions(TestCase):
'2019-11-25T13:40:14.404623Z',
'0:00:03.753')])
@mock.patch('os.stat')
@mock.patch('validations_libs.validation_actions.getLogger')
@mock.patch('validations_libs.validation_actions.os.stat')
@mock.patch('validations_libs.validation_logs.ValidationLogs.'
'get_all_logfiles',
return_value=[
@ -546,7 +547,7 @@ class TestValidationActions(TestCase):
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
@mock.patch('builtins.open')
def test_show_history_most_recent(self, mock_open, mock_load,
mock_get_log, mock_stat):
mock_get_log, mock_stat, mock_logger):
first_validation = mock.MagicMock()
second_validation = mock.MagicMock()

View File

@ -13,12 +13,12 @@
# under the License.
#
import logging
from validations_libs.logger import getLogger
import os
import yaml
from collections import OrderedDict
LOG = logging.getLogger(__name__ + ".validation")
LOG = getLogger(__name__ + ".validation")
class Validation:

View File

@ -12,7 +12,7 @@
# License for the specific language governing permissions and limitations
# under the License.
#
import logging
from validations_libs.logger import getLogger
import os
import sys
import json
@ -26,7 +26,7 @@ from validations_libs import constants
from validations_libs import utils as v_utils
from validations_libs.exceptions import ValidationRunException, ValidationShowException
LOG = logging.getLogger(__name__ + ".validation_actions")
LOG = getLogger(__name__ + ".validation_actions")
class ValidationActions:
@ -55,7 +55,7 @@ class ValidationActions:
(Defaults to ``constants.VALIDATIONS_LOG_BASEDIR``)
:type log_path: ``string``
"""
self.log = logging.getLogger(__name__ + ".ValidationActions")
self.log = getLogger(__name__ + ".ValidationActions")
self.validation_path = validation_path
self.log_path = log_path
@ -119,7 +119,7 @@ class ValidationActions:
['category2'],
['product2'])])
"""
self.log = logging.getLogger(__name__ + ".list_validations")
self.log = getLogger(__name__ + ".list_validations")
validations = v_utils.parse_all_validations_on_disk(
path=self.validation_path,
@ -177,7 +177,7 @@ class ValidationActions:
'Parameters': {'foo1': bar1}
}
"""
self.log = logging.getLogger(__name__ + ".show_validations")
self.log = getLogger(__name__ + ".show_validations")
# Get validation data:
vlog = ValidationLogs(self.log_path)
data = v_utils.get_validations_data(
@ -415,7 +415,7 @@ class ValidationActions:
'Unreachable_Hosts': '',
'Validations': 'bar'}]
"""
self.log = logging.getLogger(__name__ + ".run_validations")
self.log = getLogger(__name__ + ".run_validations")
playbooks = []
validations_dir = (validations_dir if validations_dir
else self.validation_path)

View File

@ -14,14 +14,14 @@
#
import json
import glob
import logging
from validations_libs.logger import getLogger
import os
import time
from os.path import join
from validations_libs import constants
LOG = logging.getLogger(__name__ + ".validation_logs")
LOG = getLogger(__name__ + ".validation_logs")
class ValidationLog:
@ -78,8 +78,8 @@ class ValidationLog:
self.uuid, _name = self.name.split('_', 1)
self.validation_id, self.datetime = _name.rsplit('_', 1)
except ValueError:
logging.warning('Wrong log file format, it should be formed '
'such as {uuid}_{validation-id}_{timestamp}')
LOG.warning('Wrong log file format, it should be formed '
'such as {uuid}_{validation-id}_{timestamp}')
def _get_content(self):
try: