|
25 | 25 | import string |
26 | 26 | import struct |
27 | 27 | import sys |
| 28 | +import time |
| 29 | +import os |
28 | 30 | from ctypes import ( |
29 | 31 | POINTER, |
30 | 32 | c_char_p, |
@@ -176,7 +178,9 @@ def __init__(self, log_dir=None): |
176 | 178 | lib = self.gethprestchifhandle() |
177 | 179 | self.log_dir = log_dir |
178 | 180 | self.channel = HpIlo(dll=lib, log_dir=log_dir) |
179 | | - self.max_retries = 3 |
| 181 | + self.max_retries = 40 |
| 182 | + self.max_read_retries = 3 |
| 183 | + self.delay = 0.25 |
180 | 184 |
|
181 | 185 | def __del__(self): |
182 | 186 | """Blob store 2 close channel function""" |
@@ -233,19 +237,31 @@ def get_info(self, key, namespace, retries=0): |
233 | 237 | data = ptr[: lib.size_of_infoRequest()] |
234 | 238 | data = bytearray(data) |
235 | 239 |
|
236 | | - resp = self._send_receive_raw(data) |
| 240 | + while(retries <= self.max_retries): |
| 241 | + """The Redfish request is submitted to iLO successfully in rest_immediate() function. |
| 242 | + Here we are checking if iLO has processed the Redfish request and the response is |
| 243 | + written in the key in the volatile namespace in blob. |
| 244 | + If iLO has not processed the request and response is not written, we get BADPARAMETER error. |
| 245 | + Hence retry after 0.25 seconds.""" |
| 246 | + resp = self._send_receive_raw(data) |
237 | 247 |
|
238 | | - errorcode = struct.unpack("<I", bytes(resp[8:12]))[0] |
239 | | - if errorcode == BlobReturnCodes.BADPARAMETER: |
240 | | - if retries < self.max_retries: |
241 | | - self.get_info(key=key, namespace=namespace, retries=retries + 1) |
242 | | - else: |
243 | | - raise Blob2OverrideError(errorcode) |
244 | | - elif errorcode == BlobReturnCodes.NOTFOUND: |
245 | | - raise BlobNotFoundError(key, namespace) |
| 248 | + #checking for errors in the received response |
| 249 | + errorcode = struct.unpack("<I", bytes(resp[8:12]))[0] |
246 | 250 |
|
247 | | - if not (errorcode == BlobReturnCodes.SUCCESS or errorcode == BlobReturnCodes.NOTMODIFIED): |
248 | | - raise HpIloError(errorcode) |
| 251 | + if errorcode == BlobReturnCodes.BADPARAMETER: |
| 252 | + #if BADPARAMETER, delaying the execution by 0.25 seconds and retrying "send_receive_raw" |
| 253 | + if retries < self.max_retries: |
| 254 | + time.sleep(self.delay) |
| 255 | + retries += 1 |
| 256 | + else: |
| 257 | + #if all retries are exhausted and an error is still received, raise Blob2override error. |
| 258 | + raise Blob2OverrideError(errorcode) |
| 259 | + elif errorcode == BlobReturnCodes.NOTFOUND: |
| 260 | + raise BlobNotFoundError(key, namespace) |
| 261 | + elif not (errorcode == BlobReturnCodes.SUCCESS or errorcode == BlobReturnCodes.NOTMODIFIED): |
| 262 | + raise HpIloError(errorcode) |
| 263 | + else: |
| 264 | + break |
249 | 265 |
|
250 | 266 | response = resp[lib.size_of_responseHeaderBlob() :] |
251 | 267 |
|
@@ -288,7 +304,7 @@ def read(self, key, namespace, retries=0): |
288 | 304 | bytesread = struct.unpack("<I", bytes(recvpkt[readhead:(newreadsize)]))[0] |
289 | 305 |
|
290 | 306 | if bytesread == 0: |
291 | | - if retries < self.max_retries: |
| 307 | + if retries < self.max_read_retries: |
292 | 308 | data = self.read(key=key, namespace=namespace, retries=retries + 1) |
293 | 309 | return data |
294 | 310 | else: |
@@ -431,16 +447,29 @@ def delete(self, key, namespace, retries=0): |
431 | 447 | data = ptr[: lib.size_of_deleteRequest()] |
432 | 448 | data = bytearray(data) |
433 | 449 |
|
434 | | - resp = self._send_receive_raw(data) |
| 450 | + while(retries <= self.max_retries): |
| 451 | + """The Redfish request is submitted to iLO successfully in rest_immediate() function. |
| 452 | + Here we are checking if iLO has processed the Redfish request and the response is |
| 453 | + written in the key in the volatile namespace in blob. |
| 454 | + If iLO has not processed the request and response is not written, we get BADPARAMETER error. |
| 455 | + Hence retry after 0.25 seconds.""" |
| 456 | + resp = self._send_receive_raw(data) |
435 | 457 |
|
436 | | - errorcode = struct.unpack("<I", bytes(resp[8:12]))[0] |
437 | | - if errorcode == BlobReturnCodes.BADPARAMETER: |
438 | | - if retries < self.max_retries: |
439 | | - self.delete(key=key, namespace=namespace, retries=retries + 1) |
| 458 | + #checking for errors in the received response |
| 459 | + errorcode = struct.unpack("<I", bytes(resp[8:12]))[0] |
| 460 | + |
| 461 | + if errorcode == BlobReturnCodes.BADPARAMETER: |
| 462 | + #if error is BADPARAMETER, delaying the execution by 0.25 seconds and retrying "send_receive_raw" |
| 463 | + if retries < self.max_retries: |
| 464 | + time.sleep(self.delay) |
| 465 | + retries += 1 |
| 466 | + else: |
| 467 | + #if all retries are exhausted and an error is still received, raise Blob2override error. |
| 468 | + raise Blob2OverrideError(errorcode) |
| 469 | + elif not (errorcode == BlobReturnCodes.SUCCESS or errorcode == BlobReturnCodes.NOTMODIFIED): |
| 470 | + raise HpIloError(errorcode) |
440 | 471 | else: |
441 | | - raise Blob2OverrideError(errorcode) |
442 | | - elif not (errorcode == BlobReturnCodes.SUCCESS or errorcode == BlobReturnCodes.NOTMODIFIED): |
443 | | - raise HpIloError(errorcode) |
| 472 | + break |
444 | 473 |
|
445 | 474 | self.unloadchifhandle(lib) |
446 | 475 |
|
@@ -889,6 +918,21 @@ def gethprestchifhandle(): |
889 | 918 | if libhandle: |
890 | 919 | BlobStore2.setglobalhprestchifrandnumber(libhandle) |
891 | 920 | return libhandle |
| 921 | + else: |
| 922 | + import site |
| 923 | + site_packages = site.getsitepackages() |
| 924 | + for package in site_packages: |
| 925 | + try: |
| 926 | + if os.name != "nt": |
| 927 | + libpath = os.path.join(package, "ilorest", "chiflibrary", "ilorest_chif.so") |
| 928 | + else: |
| 929 | + libpath = os.path.join(package, "ilorest", "chiflibrary", "ilorest_chif.dll") |
| 930 | + libhandle = cdll.LoadLibrary(libpath) |
| 931 | + except Exception as exp: |
| 932 | + excp = exp |
| 933 | + if libhandle: |
| 934 | + BlobStore2.setglobalhprestchifrandnumber(libhandle) |
| 935 | + return libhandle |
892 | 936 | raise ChifDllMissingError(excp) |
893 | 937 |
|
894 | 938 | @staticmethod |
|
0 commit comments