Merge "Expanding logging facilities to rest of the framework"
This commit is contained in:
commit
430530fad5
@ -14,7 +14,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
import ansible_runner
|
import ansible_runner
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import pkg_resources
|
import pkg_resources
|
||||||
import pwd
|
import pwd
|
||||||
import os
|
import os
|
||||||
@ -27,7 +27,7 @@ import configparser
|
|||||||
from validations_libs import constants
|
from validations_libs import constants
|
||||||
from validations_libs import utils
|
from validations_libs import utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__ + ".ansible")
|
LOG = getLogger(__name__ + ".ansible")
|
||||||
|
|
||||||
# NOTE(cloudnull): This is setting the FileExistsError for py2 environments.
|
# NOTE(cloudnull): This is setting the FileExistsError for py2 environments.
|
||||||
# When we no longer support py2 (centos7) this should be
|
# When we no longer support py2 (centos7) this should be
|
||||||
@ -48,7 +48,7 @@ class Ansible:
|
|||||||
"""An Object for encapsulating an Ansible execution"""
|
"""An Object for encapsulating an Ansible execution"""
|
||||||
|
|
||||||
def __init__(self, uuid=None):
|
def __init__(self, uuid=None):
|
||||||
self.log = logging.getLogger(__name__ + ".Ansible")
|
self.log = getLogger(__name__ + ".Ansible")
|
||||||
self.uuid = uuid
|
self.uuid = uuid
|
||||||
|
|
||||||
def _playbook_check(self, play, playbook_dir=None):
|
def _playbook_check(self, play, playbook_dir=None):
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
from argparse import ArgumentDefaultsHelpFormatter
|
from argparse import ArgumentDefaultsHelpFormatter
|
||||||
from cliff import _argparse
|
from cliff import _argparse
|
||||||
import json
|
import json
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
from prettytable import PrettyTable
|
from prettytable import PrettyTable
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
@ -92,7 +92,7 @@ def write_output(output_log, results):
|
|||||||
def write_junitxml(output_junitxml, results):
|
def write_junitxml(output_junitxml, results):
|
||||||
"""Write output file as JUnitXML format"""
|
"""Write output file as JUnitXML format"""
|
||||||
if not JUNIT_XML_FOUND:
|
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 '
|
log.warning('junitxml output disabled: the `junit_xml` python module '
|
||||||
'is missing.')
|
'is missing.')
|
||||||
return
|
return
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from validations_libs import constants, utils
|
from validations_libs import constants, utils
|
||||||
@ -22,7 +22,7 @@ from validations_libs.cli.base import BaseCommand
|
|||||||
from validations_libs.community.init_validation import \
|
from validations_libs.community.init_validation import \
|
||||||
CommunityValidation as com_val
|
CommunityValidation as com_val
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CommunityValidationInit(BaseCommand):
|
class CommunityValidationInit(BaseCommand):
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
# @matbu backward compatibility for stable/train
|
# @matbu backward compatibility for stable/train
|
||||||
@ -26,7 +26,7 @@ except ImportError:
|
|||||||
|
|
||||||
from validations_libs import constants, utils
|
from validations_libs import constants, utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CommunityValidation:
|
class CommunityValidation:
|
||||||
|
@ -13,10 +13,10 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__ + ".Group")
|
LOG = getLogger(__name__ + ".Group")
|
||||||
|
|
||||||
|
|
||||||
class Group:
|
class Group:
|
||||||
|
@ -56,7 +56,7 @@ class TestAnsible(TestCase):
|
|||||||
self.run = Ansible()
|
self.run = Ansible()
|
||||||
self.run.log = mock.MagicMock()
|
self.run.log = mock.MagicMock()
|
||||||
|
|
||||||
@mock.patch('logging.getLogger')
|
@mock.patch('validations_libs.ansible.getLogger')
|
||||||
def test_ansible_init(self, mock_logger):
|
def test_ansible_init(self, mock_logger):
|
||||||
"""
|
"""
|
||||||
Test of Ansible init.
|
Test of Ansible init.
|
||||||
|
@ -536,7 +536,8 @@ class TestValidationActions(TestCase):
|
|||||||
'2019-11-25T13:40:14.404623Z',
|
'2019-11-25T13:40:14.404623Z',
|
||||||
'0:00:03.753')])
|
'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.'
|
@mock.patch('validations_libs.validation_logs.ValidationLogs.'
|
||||||
'get_all_logfiles',
|
'get_all_logfiles',
|
||||||
return_value=[
|
return_value=[
|
||||||
@ -546,7 +547,7 @@ class TestValidationActions(TestCase):
|
|||||||
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
return_value=fakes.VALIDATIONS_LOGS_CONTENTS_LIST[0])
|
||||||
@mock.patch('builtins.open')
|
@mock.patch('builtins.open')
|
||||||
def test_show_history_most_recent(self, mock_open, mock_load,
|
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()
|
first_validation = mock.MagicMock()
|
||||||
second_validation = mock.MagicMock()
|
second_validation = mock.MagicMock()
|
||||||
|
@ -13,12 +13,12 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
|
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import os
|
import os
|
||||||
import yaml
|
import yaml
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__ + ".validation")
|
LOG = getLogger(__name__ + ".validation")
|
||||||
|
|
||||||
|
|
||||||
class Validation:
|
class Validation:
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
#
|
#
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
@ -26,7 +26,7 @@ from validations_libs import constants
|
|||||||
from validations_libs import utils as v_utils
|
from validations_libs import utils as v_utils
|
||||||
from validations_libs.exceptions import ValidationRunException, ValidationShowException
|
from validations_libs.exceptions import ValidationRunException, ValidationShowException
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__ + ".validation_actions")
|
LOG = getLogger(__name__ + ".validation_actions")
|
||||||
|
|
||||||
|
|
||||||
class ValidationActions:
|
class ValidationActions:
|
||||||
@ -55,7 +55,7 @@ class ValidationActions:
|
|||||||
(Defaults to ``constants.VALIDATIONS_LOG_BASEDIR``)
|
(Defaults to ``constants.VALIDATIONS_LOG_BASEDIR``)
|
||||||
:type log_path: ``string``
|
:type log_path: ``string``
|
||||||
"""
|
"""
|
||||||
self.log = logging.getLogger(__name__ + ".ValidationActions")
|
self.log = getLogger(__name__ + ".ValidationActions")
|
||||||
self.validation_path = validation_path
|
self.validation_path = validation_path
|
||||||
self.log_path = log_path
|
self.log_path = log_path
|
||||||
|
|
||||||
@ -119,7 +119,7 @@ class ValidationActions:
|
|||||||
['category2'],
|
['category2'],
|
||||||
['product2'])])
|
['product2'])])
|
||||||
"""
|
"""
|
||||||
self.log = logging.getLogger(__name__ + ".list_validations")
|
self.log = getLogger(__name__ + ".list_validations")
|
||||||
|
|
||||||
validations = v_utils.parse_all_validations_on_disk(
|
validations = v_utils.parse_all_validations_on_disk(
|
||||||
path=self.validation_path,
|
path=self.validation_path,
|
||||||
@ -177,7 +177,7 @@ class ValidationActions:
|
|||||||
'Parameters': {'foo1': bar1}
|
'Parameters': {'foo1': bar1}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
self.log = logging.getLogger(__name__ + ".show_validations")
|
self.log = getLogger(__name__ + ".show_validations")
|
||||||
# Get validation data:
|
# Get validation data:
|
||||||
vlog = ValidationLogs(self.log_path)
|
vlog = ValidationLogs(self.log_path)
|
||||||
data = v_utils.get_validations_data(
|
data = v_utils.get_validations_data(
|
||||||
@ -415,7 +415,7 @@ class ValidationActions:
|
|||||||
'Unreachable_Hosts': '',
|
'Unreachable_Hosts': '',
|
||||||
'Validations': 'bar'}]
|
'Validations': 'bar'}]
|
||||||
"""
|
"""
|
||||||
self.log = logging.getLogger(__name__ + ".run_validations")
|
self.log = getLogger(__name__ + ".run_validations")
|
||||||
playbooks = []
|
playbooks = []
|
||||||
validations_dir = (validations_dir if validations_dir
|
validations_dir = (validations_dir if validations_dir
|
||||||
else self.validation_path)
|
else self.validation_path)
|
||||||
|
@ -14,14 +14,14 @@
|
|||||||
#
|
#
|
||||||
import json
|
import json
|
||||||
import glob
|
import glob
|
||||||
import logging
|
from validations_libs.logger import getLogger
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
from validations_libs import constants
|
from validations_libs import constants
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__ + ".validation_logs")
|
LOG = getLogger(__name__ + ".validation_logs")
|
||||||
|
|
||||||
|
|
||||||
class ValidationLog:
|
class ValidationLog:
|
||||||
@ -78,8 +78,8 @@ class ValidationLog:
|
|||||||
self.uuid, _name = self.name.split('_', 1)
|
self.uuid, _name = self.name.split('_', 1)
|
||||||
self.validation_id, self.datetime = _name.rsplit('_', 1)
|
self.validation_id, self.datetime = _name.rsplit('_', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logging.warning('Wrong log file format, it should be formed '
|
LOG.warning('Wrong log file format, it should be formed '
|
||||||
'such as {uuid}_{validation-id}_{timestamp}')
|
'such as {uuid}_{validation-id}_{timestamp}')
|
||||||
|
|
||||||
def _get_content(self):
|
def _get_content(self):
|
||||||
try:
|
try:
|
||||||
|
Loading…
Reference in New Issue
Block a user