Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug logging #77

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions hpe3parclient/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,20 @@ def getWsApiVersion(self):
self.http.set_url(self.api_url)

def debug_rest(self, flag):
"""This is useful for debugging requests to 3PAR.
"""Enable/disable log output for the client

:param flag: set to True to enable debugging
By default logs are disabled, even for error messages, enabling debug
mode will enable http and ssh logs at debug level.

This is useful for debugging all requests to 3PAR.

:param flag: set to True to enable logs, False to disable.
:type flag: bool

"""
self.http.set_debug_flag(flag)
if self.ssh:
self.ssh.set_debug_flag(flag)
# Call method using the class as self.ssh is not created with instance
ssh.HPE3PARSSHClient.set_debug_flag(flag)

def login(self, username, password, optional=None):
"""This authenticates against the 3PAR wsapi server and creates a
Expand Down
27 changes: 19 additions & 8 deletions hpe3parclient/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class HTTPJSONRESTClient(object):
SESSION_COOKIE_NAME = 'X-Hp3Par-Wsapi-Sessionkey'
http_log_debug = False
_logger = logging.getLogger(__name__)
_logger.setLevel(logging.INFO)
_log_handler = None

# Retry constants
retry_exceptions = (exceptions.HTTPServiceUnavailable,
Expand Down Expand Up @@ -86,19 +88,28 @@ def set_url(self, api_url):
# should be http://<Server:Port>/api/v1
self.api_url = api_url.rstrip('/')

def set_debug_flag(self, flag):
"""
This turns on/off http request/response debugging output to console
@classmethod
def set_debug_flag(cls, flag):
"""This turns on/off http request/response logs

By default logs are disabled, even for error messages, enabling debug
mode will enable http logs at debug level.

:param flag: Set to True to enable debugging output
:type flag: bool

"""
if not HTTPJSONRESTClient.http_log_debug and flag:
ch = logging.StreamHandler()
HTTPJSONRESTClient._logger.setLevel(logging.DEBUG)
HTTPJSONRESTClient._logger.addHandler(ch)
HTTPJSONRESTClient.http_log_debug = True
flag = bool(flag) # In case we don't receive a bool instance
if flag != cls.http_log_debug:
if flag:
if cls._log_handler is None:
cls._log_handler = logging.StreamHandler()
cls._logger.addHandler(cls._log_handler)
cls._logger.setLevel(logging.DEBUG)
else:
cls._logger.setLevel(logging.INFO)
cls._logger.removeHandler(cls._log_handler)
cls.http_log_debug = flag

def authenticate(self, user, password, optional=None):
"""
Expand Down
28 changes: 19 additions & 9 deletions hpe3parclient/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class HPE3PARSSHClient(object):
log_debug = False
_logger = logging.getLogger(__name__)
_logger.setLevel(logging.INFO)
_log_handler = None

def __init__(self, ip, login, password,
port=22, conn_timeout=None, privatekey=None,
Expand Down Expand Up @@ -151,19 +152,28 @@ def close(self):
if self.ssh:
self.ssh.close()

def set_debug_flag(self, flag):
"""
This turns on ssh debugging output to console
@classmethod
def set_debug_flag(cls, flag):
"""This turns on/off log output for ssh commands.

By default logs are disabled, even for error messages, enabling debug
mode will enable ssh logs at debug level.

:param flag: Set to True to enable debugging output
:param flag: Whether we want to have logs or not
:type flag: bool

"""
if not HPE3PARSSHClient.log_debug and flag:
ch = logging.StreamHandler()
self._logger.setLevel(logging.DEBUG)
self._logger.addHandler(ch)
HPE3PARSSHClient.log_debug = True
flag = bool(flag) # In case we don't receive a bool instance
if flag != cls.log_debug:
if flag:
if cls._log_handler is None:
cls._log_handler = logging.StreamHandler()
cls._logger.addHandler(cls._log_handler)
cls._logger.setLevel(logging.DEBUG)
else:
cls._logger.setLevel(logging.INFO)
cls._logger.removeHandler(cls._log_handler)
cls.log_debug = flag

@staticmethod
def sanitize_cert(output_list):
Expand Down