Providing logging infrastructure in proliantutils
Providing the basic logging infrastructure in proliantutils. It adds a new module log.py which encapsulates the registry of loggers(per module) of proliantutils. NullHandler is set at the top level logger. Added ddt(data driven tests) dependency to test requirements to facilitate multiplication of test cases with different data samples. Change-Id: I2d0f24ae40bd1b71b883e4e5d4dff6409939afc0 Implements: blueprint enable-logging
This commit is contained in:
parent
4b3aaf28fe
commit
57a40be4a1
@ -17,6 +17,7 @@ from proliantutils.ilo import ipmi
|
||||
from proliantutils.ilo import operations
|
||||
from proliantutils.ilo import ribcl
|
||||
from proliantutils.ilo import ris
|
||||
from proliantutils import log
|
||||
|
||||
SUPPORTED_RIS_METHODS = [
|
||||
'activate_license',
|
||||
@ -45,6 +46,8 @@ SUPPORTED_RIS_METHODS = [
|
||||
'update_persistent_boot',
|
||||
]
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
||||
|
||||
class IloClient(operations.IloOperations):
|
||||
|
||||
@ -57,13 +60,20 @@ class IloClient(operations.IloOperations):
|
||||
cacert=cacert)
|
||||
self.info = {'address': host, 'username': login, 'password': password}
|
||||
self.model = self.ribcl.get_product_name()
|
||||
LOG.debug("IloClient object created for host {} [model: {}]".format(
|
||||
host, self.model))
|
||||
|
||||
def _call_method(self, method_name, *args, **kwargs):
|
||||
"""Call the corresponding method using either RIBCL or RIS."""
|
||||
object = self.ribcl
|
||||
the_operation_object = self.ribcl
|
||||
if ('Gen9' in self.model) and (method_name in SUPPORTED_RIS_METHODS):
|
||||
object = self.ris
|
||||
method = getattr(object, method_name)
|
||||
the_operation_object = self.ris
|
||||
method = getattr(the_operation_object, method_name)
|
||||
|
||||
LOG.debug("Calling {} method of {} for host {}".format(
|
||||
method_name, type(the_operation_object).__name__,
|
||||
the_operation_object.host))
|
||||
|
||||
return method(*args, **kwargs)
|
||||
|
||||
def get_all_licenses(self):
|
||||
|
@ -29,6 +29,7 @@ import six
|
||||
from proliantutils import exception
|
||||
from proliantutils.ilo import common
|
||||
from proliantutils.ilo import operations
|
||||
from proliantutils import log
|
||||
|
||||
|
||||
POWER_STATE = {
|
||||
@ -43,6 +44,8 @@ BOOT_MODE_CMDS = [
|
||||
'SET_PENDING_BOOT_MODE'
|
||||
]
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
||||
|
||||
class RIBCLOperations(operations.IloOperations):
|
||||
"""iLO class for RIBCL interface for iLO.
|
||||
@ -66,6 +69,9 @@ class RIBCLOperations(operations.IloOperations):
|
||||
if self.cacert is None:
|
||||
urllib3.disable_warnings(urllib3_exceptions.InsecureRequestWarning)
|
||||
|
||||
LOG.debug("RIBCLOperations object created for host {}".format(
|
||||
self.host))
|
||||
|
||||
def _request_ilo(self, root):
|
||||
"""Send RIBCL XML data to iLO.
|
||||
|
||||
|
@ -28,6 +28,7 @@ from six.moves.urllib import parse as urlparse
|
||||
from proliantutils import exception
|
||||
from proliantutils.ilo import common
|
||||
from proliantutils.ilo import operations
|
||||
from proliantutils import log
|
||||
|
||||
""" Currently this class supports only secure boot and firmware settings
|
||||
related API's .
|
||||
@ -41,6 +42,8 @@ DEVICE_COMMON_TO_RIS = {'NETWORK': 'Pxe',
|
||||
DEVICE_RIS_TO_COMMON = dict(
|
||||
(v, k) for (k, v) in DEVICE_COMMON_TO_RIS.items())
|
||||
|
||||
LOG = log.get_logger(__name__)
|
||||
|
||||
|
||||
class RISOperations(operations.IloOperations):
|
||||
|
||||
@ -61,6 +64,9 @@ class RISOperations(operations.IloOperations):
|
||||
if self.cacert is None:
|
||||
urllib3.disable_warnings(urllib3_exceptions.InsecureRequestWarning)
|
||||
|
||||
LOG.debug("RISOperations object created for host {}".format(
|
||||
self.host))
|
||||
|
||||
def _rest_op(self, operation, suburi, request_headers, request_body):
|
||||
"""Generic REST Operation handler."""
|
||||
|
||||
|
36
proliantutils/log.py
Normal file
36
proliantutils/log.py
Normal file
@ -0,0 +1,36 @@
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""Logger utility for proliantutils"""
|
||||
|
||||
import logging
|
||||
|
||||
|
||||
base_logger = logging.getLogger('proliantutils')
|
||||
base_logger.addHandler(logging.NullHandler())
|
||||
|
||||
|
||||
def get_logger(name):
|
||||
"""Return a logger with the specified name
|
||||
|
||||
If no name is specified then it returns the base logger
|
||||
with the name, 'proliantutils'.
|
||||
|
||||
:param name: logger name
|
||||
"""
|
||||
if not name:
|
||||
return base_logger
|
||||
|
||||
logger = logging.getLogger(name)
|
||||
return logger
|
60
proliantutils/tests/test_log.py
Normal file
60
proliantutils/tests/test_log.py
Normal file
@ -0,0 +1,60 @@
|
||||
# Copyright 2015 Hewlett-Packard Development Company, L.P.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
"""Test Class for Log."""
|
||||
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
|
||||
from proliantutils import log
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class LogTestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(LogTestCase, self).setUp()
|
||||
|
||||
@ddt.data(('pear',),
|
||||
('apple',),
|
||||
('banana',),)
|
||||
@ddt.unpack
|
||||
def test_get_logger_returns_the_same_logger_for_a_given_name(
|
||||
self, logger_name):
|
||||
# -----------------------------------------------------------------------
|
||||
# WHEN
|
||||
# -----------------------------------------------------------------------
|
||||
logger1 = log.get_logger(logger_name)
|
||||
logger2 = log.get_logger(logger_name)
|
||||
# -----------------------------------------------------------------------
|
||||
# THEN
|
||||
# -----------------------------------------------------------------------
|
||||
self.assertIs(logger1, logger2)
|
||||
|
||||
def test_get_logger_returns_the_base_logger_for_no_name(self):
|
||||
# -----------------------------------------------------------------------
|
||||
# GIVEN
|
||||
# -----------------------------------------------------------------------
|
||||
base_logger = log.get_logger('proliantutils')
|
||||
# -----------------------------------------------------------------------
|
||||
# WHEN
|
||||
# -----------------------------------------------------------------------
|
||||
logger1 = log.get_logger(None)
|
||||
logger2 = log.get_logger('')
|
||||
# -----------------------------------------------------------------------
|
||||
# THEN
|
||||
# -----------------------------------------------------------------------
|
||||
self.assertIs(logger1, base_logger)
|
||||
self.assertIs(logger2, base_logger)
|
@ -2,3 +2,4 @@ mock
|
||||
hacking>=0.9.2,<0.10
|
||||
testrepository>=0.0.18
|
||||
testtools>=0.9.36,!=1.2.0
|
||||
ddt
|
||||
|
Loading…
Reference in New Issue
Block a user