Skip to content

Commit

Permalink
Fix: Exceptions cleanup for hm-diag (#63)
Browse files Browse the repository at this point in the history
* feat: added diagnostics structures
* Diagnostic and DiagnosticsReport are used to construct
and communicate information about diagnostics state.
* Updated with new changes in hm-diag
* Fix unit test
* Added Gateway_MFR File not found exception (Encountered when does not exist)
* Added Miner Failed To Fetch Mac Address exception
* Added Unit Test for Miner Failed To Fetch Mac Address exception
* PR comment fixes
* Fix exception logging for hw-diag
* Raise ECCMalfunction instead of swallowing exception
* Version bump 0.11.6 -> 0.11.7

Co-authored-by: Marvin Arnold <[email protected]>
Co-authored-by: Sebastian <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2021
1 parent a98ff5e commit 95676fa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.11.5
current_version = 0.11.7
commit = True
tag = True

Expand Down
45 changes: 29 additions & 16 deletions hm_pyhelper/miner_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def run_gateway_mfr(args):
LOGGER.exception(err_str)
raise GatewayMFRFileNotFoundException(err_str) \
.with_traceback(e.__traceback__)
except Exception as e:
err_str = "Exception occured on running gateway_mfr %s" \
% str(e)
LOGGER.exception(e)
raise ECCMalfunctionException(err_str).with_traceback(e.__traceback__)

try:
return json.loads(run_gateway_mfr_result.stdout)
Expand Down Expand Up @@ -176,12 +181,13 @@ def get_ethernet_addresses(diagnostics):
for (path, key) in zip(path_to_files, keys):
try:
diagnostics[key] = get_mac_address(path)
except MinerFailedToFetchMacAddress as e:
diagnostics[key] = False
LOGGER.error(e)
except Exception as e:
diagnostics[key] = False
LOGGER.error(e)
raise(MinerFailedToFetchEthernetAddress(
"Unable to fetch miner ethernet address.\
Exception: %s" % str(e))).with_traceback(e.__traceback__)
raise MinerFailedToFetchEthernetAddress(str(e))


def get_mac_address(path):
Expand All @@ -199,23 +205,30 @@ def get_mac_address(path):
The path must be a string value")
try:
file = open(path)
except MinerFailedToFetchMacAddress as e:
LOGGER.exception(str(e))
except FileNotFoundError as e:
LOGGER.exception("Failed to find Miner \
Mac Address file at path %s" % path)
raise MinerFailedToFetchMacAddress(
"Failed to find file containing miner mac address. \
Exception: %s" % str(e)).with_traceback(e.__traceback__)
LOGGER.exception("Failed to find Miner"
"Mac Address file at path %s" % path)
raise MinerFailedToFetchMacAddress("Failed to find file"
"containing miner mac address."
"Exception: %s" % str(e))\
.with_traceback(e.__traceback__)
except PermissionError as e:
LOGGER.exception("Permissions invalid for Miner \
Mac Address file at path %s" % path)
raise MinerFailedToFetchMacAddress(
"Failed to fetch miner mac address. Invalid permissions to access file. \
Exception: %s" % str(e)).with_traceback(e.__traceback__)
LOGGER.exception("Permissions invalid for Miner"
"Mac Address file at path %s" % path)
raise MinerFailedToFetchMacAddress("Failed to fetch"
"miner mac address. "
"Invalid permissions to access "
"file. Exception: %s" % str(e))\
.with_traceback(e.__traceback__)
except Exception as e:
LOGGER.exception(e)
raise MinerFailedToFetchMacAddress(
"Failed to fetch miner mac address. \
Exception: %s" % str(e)).with_traceback(e.__traceback__)
raise MinerFailedToFetchMacAddress("Failed to fetch miner"
"mac address. "
"Exception: %s" % str(e))\
.with_traceback(e.__traceback__)

return file.readline().strip().upper()


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='hm_pyhelper',
version='0.11.5',
version='0.11.7',
author="Nebra Ltd",
author_email="[email protected]",
description="Helium Python Helper",
Expand Down

0 comments on commit 95676fa

Please sign in to comment.