@@ -295,40 +295,45 @@ def __init__(self, clusters: 'ClusterManager'):
295295 self .task = None
296296
297297 async def _get_filelist (self , cluster : 'Cluster' ):
298- async with aiohttp .ClientSession (
299- config .const .base_url ,
300- headers = {
301- "User-Agent" : USER_AGENT ,
302- "Authorization" : f"Bearer { await cluster .get_token ()} "
303- }
304- ) as session :
305- async with session .get (
306- f"/openbmclapi/files" ,
307- params = {
308- "lastModified" : str (int (self .cluster_last_modified [cluster ]))
298+ try :
299+ async with aiohttp .ClientSession (
300+ config .const .base_url ,
301+ headers = {
302+ "User-Agent" : USER_AGENT ,
303+ "Authorization" : f"Bearer { await cluster .get_token ()} "
309304 }
310- ) as resp :
311- body = await resp .read ()
312- if utils .is_service_error (body ):
313- utils .raise_service_error (body )
314- return []
315- resp .raise_for_status ()
316- if resp .status == 204 :
317- return []
318- stream = utils .FileStream (zstd .decompress (body ))
319- filelist = [
320- File (
321- path = stream .read_string (),
322- hash = stream .read_string (),
323- size = stream .read_long (),
324- mtime = stream .read_long ()
325- )
326- for _ in range (stream .read_long ())
327- ]
328- if filelist :
329- mtime = max (filelist , key = lambda f : f .mtime ).mtime
330- self .cluster_last_modified [cluster ] = max (mtime , self .cluster_last_modified [cluster ])
331- return filelist
305+ ) as session :
306+ async with session .get (
307+ f"/openbmclapi/files" ,
308+ params = {
309+ "lastModified" : str (int (self .cluster_last_modified [cluster ]))
310+ }
311+ ) as resp :
312+ body = await resp .read ()
313+ if utils .is_service_error (body ):
314+ utils .raise_service_error (body )
315+ return []
316+ resp .raise_for_status ()
317+ if resp .status == 204 :
318+ return []
319+ stream = utils .FileStream (zstd .decompress (body ))
320+ filelist = [
321+ File (
322+ path = stream .read_string (),
323+ hash = stream .read_string (),
324+ size = stream .read_long (),
325+ mtime = stream .read_long ()
326+ )
327+ for _ in range (stream .read_long ())
328+ ]
329+ if filelist :
330+ mtime = max (filelist , key = lambda f : f .mtime ).mtime
331+ self .cluster_last_modified [cluster ] = max (mtime , self .cluster_last_modified [cluster ])
332+ return filelist
333+ except :
334+ logger .ttraceback ("cluster.error.fetch_filelist" , cluster = cluster .id )
335+ return []
336+
332337
333338 async def fetch_filelist (self ) -> set [File ]:
334339 result_filelist = set ().union (* await asyncio .gather (* (asyncio .create_task (self ._get_filelist (cluster )) for cluster in self .clusters .clusters )))
@@ -503,23 +508,27 @@ async def _r(urls: tuple[URLResponse, ...]):
503508
504509
505510 async def _get_configuration (self , cluster : 'Cluster' ):
506- async with aiohttp .ClientSession (
507- config .const .base_url ,
508- headers = {
509- "User-Agent" : USER_AGENT ,
510- "Authorization" : f"Bearer { await cluster .get_token ()} "
511- }
512- ) as session :
513- async with session .get (
514- f"/openbmclapi/configuration"
515- ) as resp :
516- body = await resp .json ()
517- if utils .raise_service_error (body ):
518- return {}
519- resp .raise_for_status ()
520- return {
521- k : OpenBMCLAPIConfiguration (** v ) for k , v in (body ).items ()
511+ try :
512+ async with aiohttp .ClientSession (
513+ config .const .base_url ,
514+ headers = {
515+ "User-Agent" : USER_AGENT ,
516+ "Authorization" : f"Bearer { await cluster .get_token ()} "
522517 }
518+ ) as session :
519+ async with session .get (
520+ f"/openbmclapi/configuration"
521+ ) as resp :
522+ body = await resp .json ()
523+ if utils .raise_service_error (body ):
524+ return {}
525+ resp .raise_for_status ()
526+ return {
527+ k : OpenBMCLAPIConfiguration (** v ) for k , v in (body ).items ()
528+ }
529+ except :
530+ logger .ttraceback ("cluster.error.configuration" , cluster = cluster .id )
531+ return {}
523532
524533class ClusterManager :
525534 def __init__ (self ):
@@ -961,7 +970,7 @@ def __init__(self, hash: str, size: int, mtime: float, data: bytes) -> None:
961970
962971ROOT = Path (__file__ ).parent .parent
963972
964- API_VERSION = "1.13.0 "
973+ API_VERSION = "1.13.1 "
965974USER_AGENT = f"openbmclapi/{ API_VERSION } python-openbmclapi/{ config .VERSION } "
966975CHECK_FILE_CONTENT = "Python OpenBMCLAPI"
967976CHECK_FILE_MD5 = hashlib .md5 (CHECK_FILE_CONTENT .encode ("utf-8" )).hexdigest ()
0 commit comments