Skip to content

Commit

Permalink
minor patches
Browse files Browse the repository at this point in the history
  • Loading branch information
rajeevkallur committed Jan 18, 2023
1 parent ab39f1f commit fd20533
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/redfish/rest/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,19 @@ def _init_connection(self):
self._connection_properties.pop("ca_cert_data")
except KeyError:
pass
timeout = urllib3.Timeout(connect=60.0, read=60.0)
timeout = urllib3.Timeout(connect=40.0, read=40.0)
if "timeout" not in self._connection_properties:
http = PoolManager(
cert_reqs=cert_reqs,
maxsize=6,
timeout=timeout,
retries=urllib3.Retry(connect=50, read=50, redirect=2),
retries=urllib3.Retry(connect=10, read=10, redirect=2),
**self._connection_properties
)
else:
http = PoolManager(
cert_reqs=cert_reqs, maxsize=6, **self._connection_properties,
retries=urllib3.Retry(connect=50, read=50, redirect=2)
retries=urllib3.Retry(connect=10, read=10, redirect=2)
)

self._conn = http.request
Expand Down
6 changes: 5 additions & 1 deletion src/redfish/rest/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
"""Containers used for REST requests and responses."""
import sys
import json
import six

from collections import OrderedDict
try:
from collections import OrderedDict
except ImportError:
from collections.abc import OrderedDict

from six import text_type, string_types, StringIO, BytesIO
from six.moves import http_client
Expand Down
2 changes: 2 additions & 0 deletions src/redfish/ris/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
ValidationError,
ValueChangedError,
RmcCacheManager,
ScepenabledError,
IloLicenseError,
RmcFileCacheManager,
)

Expand Down
3 changes: 3 additions & 0 deletions src/redfish/ris/gen_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def getgen(
url=None,
username=None,
password=None,
sessionid=None,
logger=None,
proxy=None,
ca_cert_data={},
Expand Down Expand Up @@ -111,6 +112,7 @@ def getgen(
base_url=self.url,
username=username,
password=password,
sessionid=sessionid,
proxy=proxy,
ca_cert_data=ca_cert_data,
)
Expand All @@ -125,6 +127,7 @@ def getgen(
base_url=self.url,
username=username,
password=password,
sessionid=sessionid,
proxy=proxy,
ca_cert_data=ca_cert_data,
)
Expand Down
23 changes: 9 additions & 14 deletions src/redfish/ris/resp_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
with registries available on system, otherwise will return generic error responses."""
import logging

from rdmc_helper import IloLicenseError, ScepenabledError
from redfish.ris.rmc_helper import IloLicenseError, ScepenabledError
from redfish.ris.ris import SessionExpired
from redfish.ris.utils import warning_handler, get_errmsg_type, json_traversal
from redfish.ris.utils import warning_handler, print_handler, get_errmsg_type, json_traversal
from redfish.ris.rmc_helper import (
IloResponseError,
IdTokenError,
Expand Down Expand Up @@ -76,15 +76,12 @@ def output_resp(self, response, dl_reg=False, verbosity=1):
if response.status < 300 and (
response._rest_request.method == "GET" or not response.read
):
warning_handler(
print_handler(
self.verbosity_levels(
message=message_text,
response_status=response.status,
verbosity=verbosity,
dl_reg=dl_reg,
),
override=True,
)
dl_reg=dl_reg))
elif response.status == 401:
raise SessionExpired()
elif response.status == 403:
Expand Down Expand Up @@ -183,7 +180,7 @@ def message_handler(
pass
finally:
response_error_str += "[%s] %s\n" % (response_status, message_text)
warning_handler(
print_handler(
self.verbosity_levels(
message_text,
_tmp_message_id,
Expand All @@ -192,15 +189,14 @@ def message_handler(
response_status,
verbosity,
dl_reg,
),
override=True,
)
)
retlist.append(inst)
except Exception:
if not message_text:
message_text = _tmp_message_id
response_error_str += "[%s] %s\n" % (response_status, message_text)
warning_handler(
print_handler(
self.verbosity_levels(
message_text,
_tmp_message_id,
Expand All @@ -209,8 +205,7 @@ def message_handler(
response_status,
verbosity,
dl_reg,
),
override=True,
)
)
retlist.append(inst)
finally:
Expand Down Expand Up @@ -265,7 +260,7 @@ def verbosity_levels(
:param resolution: Message from BMC registry model/schema with the suggested
resolution for the given error.
:type resolution: str
:param resposne_status: HTTP response status code.
:param response_status: HTTP response status code.
:type response_status: int
:param verbosity: Option to set/control output message (stderr) verbosity.
:type verbosity: int
Expand Down
8 changes: 5 additions & 3 deletions src/redfish/ris/ris.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
import weakref
import logging
import threading

from collections import OrderedDict, defaultdict

# Added for py3 compatibility
import six

try:
from collections import OrderedDict, defaultdict
except ImportError:
from collections.abc import OrderedDict, defaultdict

from queue import Queue
from six.moves.urllib.parse import urlparse, urlunparse

Expand Down
12 changes: 10 additions & 2 deletions src/redfish/ris/rmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
import shutil
import logging
import hashlib
import six

from collections import OrderedDict
try:
from collections import OrderedDict
except ImportError:
from collections.abc import OrderedDict

import six
import jsonpatch
import jsonpointer
import redfish.ris.gen_compat
Expand Down Expand Up @@ -86,13 +89,15 @@ class RmcApp(object):
def __init__(self, showwarnings=False, cache_dir=None):
self.logger = LOGGER
self.redfishinst = None
self.sessioninst = None
self._cm = RmcFileCacheManager(self)
self.monolith = None
self._iloversion = None
self._validationmanager = None
self._selector = None
self._cachedir = cache_dir
self.verbose = 1
self._sessionid = None
self.typepath = redfish.ris.gen_compat.Typesandpathdefines()
Typepathforval(typepathobj=self.typepath)

Expand Down Expand Up @@ -199,6 +204,7 @@ def login(
self,
username=None,
password=None,
sessionid=None,
base_url="blobstore://.",
path=None,
skipbuild=False,
Expand Down Expand Up @@ -248,6 +254,7 @@ def login(
url=base_url,
username=username,
password=password,
sessionid=sessionid,
ca_cert_data=user_ca_cert_data,
proxy=proxy,
isredfish=is_redfish,
Expand All @@ -266,6 +273,7 @@ def login(
base_url=base_url,
username=username,
password=password,
session_key=sessionid,
default_prefix=self.typepath.defs.startpath,
biospassword=biospassword,
is_redfish=is_redfish,
Expand Down
10 changes: 10 additions & 0 deletions src/redfish/ris/rmc_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ class CurrentlyLoggedInError(Exception):

pass

class IloLicenseError(Exception):
"""Raised when the proper iLO license is not available for a command"""

pass


class ScepenabledError(Exception):
"""Raised when the generation csr or deletion of https cert is issues when scep is enabled"""

pass

class NothingSelectedError(Exception):
"""Raised when attempting to access an object without first selecting it."""
Expand Down
29 changes: 21 additions & 8 deletions src/redfish/ris/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@
if six.PY3:
from functools import reduce

if six.PY2:
try:
from collections import Mapping
from collections.abc import Mapping
except ImportError:
from collections.abc import Mapping

import jsonpath_rw

Expand All @@ -50,19 +51,31 @@
# ---------End of debug logger---------


def print_handler(msg):
"""Helper function for handling warning messages appropriately. If LOGGER level is set to 40
print out the warnings, else log them as a warning.
:param msg: The warning message.
:type msg: str
"""
#if override:
sys.stdout.write(msg)
#else:
#if LOGGER.getEffectiveLevel() == 40:
#LOGGER.warning(msg)

def warning_handler(msg, override=False):
"""Helper function for handling warning messages appropriately. If LOGGER level is set to 40
print out the warnings, else log them as a warning.
:param msg: The warning message.
:type msg: str
"""
if override:
sys.stderr.write(msg)
if LOGGER.getEffectiveLevel() > 40:
sys.stderr.write(msg)
else:
LOGGER.warning(msg)
#if override:
#sys.stdout.write(msg)
#else:
#if LOGGER.getEffectiveLevel() == 40:
LOGGER.warning(msg)


def validate_headers(instance, verbose=False):
Expand Down
5 changes: 4 additions & 1 deletion src/redfish/ris/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
import textwrap
import jsonpath_rw

from collections import OrderedDict
try:
from collections import OrderedDict
except ImportError:
from collections.abc import OrderedDict
from redfish.rest.containers import RisObject
from redfish.ris.utils import json_traversal
from .sharedtypes import JSONEncoder
Expand Down

0 comments on commit fd20533

Please sign in to comment.