diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 4f0d5ee..78bc3d3 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 0.11.4 +current_version = 0.11.5 commit = True tag = True diff --git a/hm_pyhelper/diagnostics/__init__.py b/hm_pyhelper/diagnostics/__init__.py index ee6028b..cffdc5b 100644 --- a/hm_pyhelper/diagnostics/__init__.py +++ b/hm_pyhelper/diagnostics/__init__.py @@ -1,2 +1,2 @@ from hm_pyhelper.diagnostics.diagnostics_report import DiagnosticsReport # noqa F401 -from hm_pyhelper.diagnostics.diagnostic import Diagnostic # noqa F401 +from hm_pyhelper.diagnostics.diagnostic import Diagnostic # noqa F401 \ No newline at end of file diff --git a/hm_pyhelper/exceptions.py b/hm_pyhelper/exceptions.py index eed11e1..618a606 100644 --- a/hm_pyhelper/exceptions.py +++ b/hm_pyhelper/exceptions.py @@ -8,3 +8,11 @@ class SPIUnavailableException(Exception): class ECCMalfunctionException(Exception): pass + + +class GatewayMFRFileNotFoundException(Exception): + pass + + +class MinerFailedToFetchMacAddress(Exception): + pass diff --git a/hm_pyhelper/miner_json_rpc/exceptions.py b/hm_pyhelper/miner_json_rpc/exceptions.py index 2dbd78e..ab787ad 100644 --- a/hm_pyhelper/miner_json_rpc/exceptions.py +++ b/hm_pyhelper/miner_json_rpc/exceptions.py @@ -1,4 +1,3 @@ - class MinerJSONRPCException(Exception): pass @@ -13,3 +12,11 @@ class MinerMalformedURL(MinerJSONRPCException): class MinerRegionUnset(MinerJSONRPCException): pass + + +class MinerFailedFetchData(MinerJSONRPCException): + pass + + +class MinerFailedToFetchEthernetAddress(MinerJSONRPCException): + pass diff --git a/hm_pyhelper/miner_param.py b/hm_pyhelper/miner_param.py index 48deaad..e6da27f 100644 --- a/hm_pyhelper/miner_param.py +++ b/hm_pyhelper/miner_param.py @@ -5,7 +5,11 @@ from hm_pyhelper.lock_singleton import lock_ecc from hm_pyhelper.logger import get_logger from hm_pyhelper.exceptions import MalformedRegionException, \ - SPIUnavailableException, ECCMalfunctionException + SPIUnavailableException, ECCMalfunctionException, \ + GatewayMFRFileNotFoundException, \ + MinerFailedToFetchMacAddress +from hm_pyhelper.miner_json_rpc.exceptions import \ + MinerFailedToFetchEthernetAddress from hm_pyhelper.hardware_definitions import is_rockpi @@ -41,6 +45,11 @@ def run_gateway_mfr(args): err_str = "gateway_mfr exited with a non-zero status" LOGGER.exception(err_str) raise ECCMalfunctionException(err_str).with_traceback(e.__traceback__) + except (FileNotFoundError, NotADirectoryError) as e: + err_str = "file/directory for gateway_mfr was not found" + LOGGER.exception(err_str) + raise GatewayMFRFileNotFoundException(err_str) \ + .with_traceback(e.__traceback__) try: return json.loads(run_gateway_mfr_result.stdout) @@ -170,6 +179,9 @@ def get_ethernet_addresses(diagnostics): 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__) def get_mac_address(path): @@ -182,13 +194,28 @@ def get_mac_address(path): TypeError - If the function argument is not a string. """ if type(path) is not str: - raise TypeError("The path must be a string value") + raise TypeError( + "Constructing miner mac address failed.\ + The path must be a string value") try: file = open(path) except FileNotFoundError as e: - raise 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__) except PermissionError as e: - raise 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__) + except Exception as e: + LOGGER.exception(e) + raise MinerFailedToFetchMacAddress( + "Failed to fetch miner mac address. \ + Exception: %s" % str(e)).with_traceback(e.__traceback__) return file.readline().strip().upper() diff --git a/hm_pyhelper/tests/test_diagnostic_report.py b/hm_pyhelper/tests/test_diagnostic_report.py index c3d57b4..4b99a87 100644 --- a/hm_pyhelper/tests/test_diagnostic_report.py +++ b/hm_pyhelper/tests/test_diagnostic_report.py @@ -1,8 +1,7 @@ import unittest import json -from hm_pyhelper.diagnostics import Diagnostic -from hm_pyhelper.diagnostics import DiagnosticsReport +from hm_pyhelper.diagnostics import Diagnostic, DiagnosticsReport from hm_pyhelper.diagnostics.diagnostics_report import \ DIAGNOSTICS_PASSED_KEY, \ DIAGNOSTICS_ERRORS_KEY diff --git a/hm_pyhelper/tests/test_miner_param.py b/hm_pyhelper/tests/test_miner_param.py index 0cfe9ff..5847786 100644 --- a/hm_pyhelper/tests/test_miner_param.py +++ b/hm_pyhelper/tests/test_miner_param.py @@ -1,7 +1,10 @@ +from hm_pyhelper.exceptions import MinerFailedToFetchMacAddress from hm_pyhelper.miner_param import retry_get_region, await_spi_available, \ - provision_key, did_gateway_mfr_test_result_include_miner_key_pass + provision_key, did_gateway_mfr_test_result_include_miner_key_pass, \ + get_mac_address import unittest from unittest.mock import mock_open, patch +import pytest ALL_PASS_GATEWAY_MFR_TESTS = [ { @@ -170,3 +173,7 @@ def test_get_region_from_miner(self, _): @patch("os.path.exists", return_value=True) def test_is_spi_available(self, _): self.assertTrue(await_spi_available("spiXY.Z")) + + def test_error_mac_address(self): + with pytest.raises(MinerFailedToFetchMacAddress): + get_mac_address("test/path") diff --git a/setup.py b/setup.py index 443cc8d..b5a22d0 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='hm_pyhelper', - version='0.11.4', + version='0.11.5', author="Nebra Ltd", author_email="support@nebra.com", description="Helium Python Helper",