Add some logs and fix the get_allowed_*() methods
This patch is adding logs to some parts of the library to help with troubleshooting it. The patch also fixes a problem with the get_alllowed_*() methods from System. When the allowed values are not found in the resource JSON we should return all values known to Sushy instead of an empty list. Change-Id: Ifb29c85eaef47f7e112621d1c6cad4315f4c4578
This commit is contained in:
parent
f760529c03
commit
efe4410eef
@ -8,8 +8,15 @@ To use sushy in a project:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import logging
|
||||
|
||||
import sushy
|
||||
|
||||
# Enable logging at DEBUG level
|
||||
LOG = logging.getLogger('sushy')
|
||||
LOG.setLevel(logging.DEBUG)
|
||||
LOG.addHandler(logging.StreamHandler())
|
||||
|
||||
s = sushy.Sushy('http://127.0.0.1:8000/redfish/v1',
|
||||
username='foo', password='bar')
|
||||
|
||||
|
@ -12,6 +12,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
|
||||
import pbr.version
|
||||
|
||||
from sushy.main import Sushy
|
||||
@ -20,3 +22,6 @@ from sushy.resources.system.constants import * # noqa
|
||||
__all__ = ('Sushy',)
|
||||
__version__ = pbr.version.VersionInfo(
|
||||
'sushy').version_string()
|
||||
|
||||
# Set the default handler to avoid "No handler found" warnings
|
||||
logging.getLogger(__name__).addHandler(logging.NullHandler())
|
||||
|
@ -14,10 +14,13 @@
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
|
||||
import requests
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Connector(object):
|
||||
|
||||
@ -43,6 +46,12 @@ class Connector(object):
|
||||
data = json.dumps(data)
|
||||
|
||||
url = os.path.join(self._url, path)
|
||||
# TODO(lucasagomes): We should mask the data to remove sensitive
|
||||
# information
|
||||
LOG.debug('Issuing a HTTP %(method)s request at %(url)s with '
|
||||
'the headers "%(headers)s" and data "%(data)s"',
|
||||
{'method': method, 'url': url, 'headers': headers,
|
||||
'data': data or ''})
|
||||
return session.request(method, url, data=data)
|
||||
|
||||
def get(self, path='', data=None, headers=None):
|
||||
|
@ -13,6 +13,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import os
|
||||
|
||||
from sushy import exceptions
|
||||
@ -21,6 +22,8 @@ from sushy.resources.system import constants as sys_cons
|
||||
from sushy.resources.system import mappings as sys_maps
|
||||
from sushy import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class System(base.ResourceBase):
|
||||
|
||||
@ -126,7 +129,9 @@ class System(base.ResourceBase):
|
||||
|
||||
allowed_values = reset_action.get('ResetType@Redfish.AllowableValues')
|
||||
if not allowed_values:
|
||||
return []
|
||||
LOG.warning('Could not figure out the allowed values for the '
|
||||
'reset system action for System %s', self.identity)
|
||||
return sys_maps.RESET_SYSTEM_VALUE_MAP.keys()
|
||||
|
||||
return [sys_maps.RESET_SYSTEM_VALUE_MAP[v] for v in
|
||||
set(sys_maps.RESET_SYSTEM_VALUE_MAP.keys()).
|
||||
@ -154,7 +159,10 @@ class System(base.ResourceBase):
|
||||
'BootSourceOverrideTarget@Redfish.AllowableValues')
|
||||
|
||||
if not allowed_values:
|
||||
return []
|
||||
LOG.warning('Could not figure out the allowed values for '
|
||||
'configuring the boot source for System %s',
|
||||
self.identity)
|
||||
return sys_maps.BOOT_SOURCE_TARGET_MAP.keys()
|
||||
|
||||
return [sys_maps.BOOT_SOURCE_TARGET_MAP[v] for v in
|
||||
set(sys_maps.BOOT_SOURCE_TARGET_MAP.keys()).
|
||||
@ -243,8 +251,11 @@ class SystemCollection(base.ResourceBase):
|
||||
members = []
|
||||
for member in self.json.get('Members', []):
|
||||
ident = member.get('@odata.id')
|
||||
if ident is not None:
|
||||
ident = os.path.basename(ident)
|
||||
members.append(self.get_member(ident))
|
||||
if ident is None:
|
||||
LOG.warning('Could not find the identity attribute for '
|
||||
'member %s', member)
|
||||
continue
|
||||
ident = os.path.basename(ident)
|
||||
members.append(self.get_member(ident))
|
||||
|
||||
return members
|
||||
|
Loading…
Reference in New Issue
Block a user