Skip to content

Commit

Permalink
Fix flake8 B904 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mschnepf committed Sep 17, 2021
1 parent ba32d74 commit 9728248
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
6 changes: 3 additions & 3 deletions tardis/adapters/sites/cloudstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ def handle_exceptions(self):
yield
except asyncio.TimeoutError as te:
raise TardisTimeout from te
except ClientConnectionError:
except ClientConnectionError as err:
logger.warning("Connection reset error")
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from err
except CloudStackClientException as ce:
log_msg = (
f"Error code: {ce.error_code}, error text: {ce.error_text}, "
f"response: {ce.response}"
)
if ce.error_code == 535:
logger.warning(f"Quota exceeded: {log_msg}")
raise TardisQuotaExceeded
raise TardisQuotaExceeded from ce
elif ce.error_code == 500:
if "timed out" in ce.response["message"]:
logger.warning(f"Timed out: {log_msg}")
Expand Down
2 changes: 1 addition & 1 deletion tardis/adapters/sites/htcondor.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ async def resource_status(
if (
self._htcondor_queue.last_update - resource_attributes.created
).total_seconds() < 0:
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from None
else:
return AttributeDict(resource_status=ResourceStatus.Deleted)
else:
Expand Down
6 changes: 3 additions & 3 deletions tardis/adapters/sites/moab.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ async def resource_status(
try:
resource_uuid = resource_attributes.remote_resource_uuid
resource_status = self._moab_status[str(resource_uuid)]
except KeyError:
except KeyError as err:
if (
self._moab_status._last_update - resource_attributes.created
).total_seconds() < 0:
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from err
else:
resource_status = {
"JobID": resource_attributes.remote_resource_uuid,
Expand Down Expand Up @@ -234,7 +234,7 @@ def handle_exceptions(self):
raise TardisTimeout from te
except asyncssh.Error as exc:
logger.warning("SSH connection failed: " + str(exc))
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from exc
except IndexError as ide:
raise TardisResourceStatusUpdateFailed from ide
except TardisResourceStatusUpdateFailed:
Expand Down
12 changes: 6 additions & 6 deletions tardis/adapters/sites/openstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ def handle_exceptions(self):
raise TardisTimeout from te
except AuthError as ae:
raise TardisAuthError from ae
except ContentTypeError:
except ContentTypeError as cte:
logger.warning("OpenStack: content Type Error")
raise TardisResourceStatusUpdateFailed
except ClientError:
raise TardisResourceStatusUpdateFailed from cte
except ClientError as ce:
logger.warning("REST client error")
raise TardisDroneCrashed
except ClientConnectionError:
raise TardisDroneCrashed from ce
except ClientConnectionError as cde:
logger.warning("Connection reset error")
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from cde
except Exception as ex:
raise TardisError from ex
4 changes: 2 additions & 2 deletions tardis/adapters/sites/slurm.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def resource_status(
# In case the created timestamp is after last update timestamp of the
# asynccachemap, no decision about the current state can be given,
# since map is updated asynchronously. Just retry later on.
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from None
else:
resource_status = {
"JobID": resource_attributes.remote_resource_uuid,
Expand Down Expand Up @@ -209,7 +209,7 @@ def handle_exceptions(self):
yield
except CommandExecutionFailure as ex:
logger.warning("Execute command failed: %s" % str(ex))
raise TardisResourceStatusUpdateFailed
raise TardisResourceStatusUpdateFailed from ex
except TardisResourceStatusUpdateFailed:
raise
except TimeoutError as te:
Expand Down
8 changes: 4 additions & 4 deletions tardis/resources/dronestates.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ async def resource_status(state_transition, drone: "Drone", current_state: Type[
await drone.site_agent.resource_status(drone.resource_attributes)
)
logger.debug(f"Resource attributes: {drone.resource_attributes}")
except (TardisAuthError, TardisTimeout, TardisResourceStatusUpdateFailed):
except (TardisAuthError, TardisTimeout, TardisResourceStatusUpdateFailed) as err:
# Retry to get current state of the resource
raise StopProcessing(last_result=current_state())
except TardisDroneCrashed:
raise StopProcessing(last_result=current_state()) from err
except TardisDroneCrashed as tdc:
# Try to cleanup crashed resources
raise StopProcessing(last_result=CleanupState())
raise StopProcessing(last_result=CleanupState()) from tdc
else:
return state_transition[drone.resource_attributes.resource_status]()

Expand Down
4 changes: 2 additions & 2 deletions tardis/utilities/attributedict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __getattr__(self, item):
except KeyError:
raise AttributeError(
f"{item} is not a valid attribute. Dict contains {str(self)}."
)
) from None

def __setattr__(self, key, value):
self[key] = value
Expand All @@ -27,4 +27,4 @@ def __delattr__(self, item):
except KeyError:
raise AttributeError(
f"{item} is not a valid attribute. Dict contains {str(self)}."
)
) from None

0 comments on commit 9728248

Please sign in to comment.