Add primitive Redfish task monitor

This commit adds simple Redfish task monitor. We could eventually
migrate to sushy's built-in task monitor once it becomes available.
This commit is contained in:
Ilya Etingof 2019-08-26 19:37:17 +02:00
parent 49abbf630e
commit fb66161214
3 changed files with 61 additions and 10 deletions

View File

@ -3,5 +3,6 @@
# process, which may cause wedges in the gate later.
pbr!=2.1.0,>=2.0.0 # Apache-2.0
python-dateutil>=2.7.0 # BSD
six>=1.10.0 # MIT
sushy # Apache-2.0

View File

@ -0,0 +1,53 @@
# 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.
from datetime import datetime
from datetime import timedelta
import logging
import time
from dateutil import parser
import sushy
LOG = logging.getLogger(__name__)
def _to_datetime(retry_after_str):
if retry_after_str.isdigit():
# Retry-After: 120
return datetime.now() + timedelta(seconds=int(retry_after_str))
else:
# Retry-After: Fri, 31 Dec 1999 23:59:59 GMT
return parser.parse(retry_after_str)
def http_call(conn, method, *args, **kwargs):
handle = getattr(conn, method.lower())
response = handle(*args, **kwargs)
while response.status_code == 202:
location = response.headers.get('location')
retry_after = response.headers.get('retry-after')
retry_after = _to_datetime(retry_after)
time.sleep(max(0, retry_after - datetime.now()))
response = conn.get(location)
if response.status_code >= 400:
raise sushy.exceptions.ExtensionError(
error='HTTP %s with args %s, kwargs %s failed '
'with code %s' % (method.upper(), args, kwargs,
response.status_code))
return response

View File

@ -17,6 +17,8 @@ from sushy.resources import base
from sushy.resources import common
from sushy.resources.oem import base as oem_base
from sushy_oem_dellemc import asynchronous
LOG = logging.getLogger(__name__)
@ -90,20 +92,15 @@ class DellManagerExtension(oem_base.OEMResourceBase):
# TODO (etingof): figure out if on-time or persistent boot can at
# all be implemented via this OEM call
response = self._conn.post(
self.import_system_configuration_uri, data=magic_saucer)
if response.status_code != 202:
raise sushy.exceptions.ExtensionError(
error='Dell OEM action ImportSystemConfiguration fails '
'with code %s' % response.status_code)
response = asynchronous.http_call(
self._conn, 'post',
self.import_system_configuration_uri,
data=magic_saucer)
LOG.info("Set boot device to %(device)s via "
"Dell OEM magic spell", {'device': device})
# TODO(etingof): extract iDRAC task ID which looks like r"JID_.+?,"
# TODO(etingof): poll Redfish TaskService to see when task is completed
return response
def get_extension(*args, **kwargs):