Skip to content

Commit

Permalink
fix: missing ecc_location causes unbound error (#237)
Browse files Browse the repository at this point in the history
* fix: missing ecc_location causes unbound error

missing ecc_location causes unbound error

Closes: #236

* Update miner_param.py

* Update setup.py

* Update test_miner_param.py

* Update test_miner_param.py

* Update miner_param.py
  • Loading branch information
shawaj authored Apr 7, 2023
1 parent eac698c commit 8d93145
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 3 additions & 3 deletions hm_pyhelper/miner_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ def get_gateway_mfr_version() -> Version:

def get_ecc_location() -> str:
ecc_list = get_variant_attribute(os.getenv('VARIANT'), 'SWARM_KEY_URI')
ecc_location = None

try:
with open("/var/nebra/ecc_file", 'r') as data:
Expand All @@ -120,7 +121,7 @@ def get_ecc_location() -> str:
else:
LOGGER.info("Generated ECC location file found: " + generated_ecc_location)
except FileNotFoundError:
# No ECC location file found, create one with value None
# No ECC location file found, create variable with value None
generated_ecc_location = None

if os.getenv('SWARM_KEY_URI_OVERRIDE'):
Expand All @@ -144,8 +145,7 @@ def get_ecc_location() -> str:
return ecc_location

if not ecc_location:
ecc_location = None
LOGGER.info("Can't find ECC. Ensure SWARM_KEY_URI is correct in hardware definitions.")
LOGGER.error("Can't find ECC. Ensure SWARM_KEY_URI is correct in hardware definitions.")

return ecc_location

Expand Down
16 changes: 16 additions & 0 deletions hm_pyhelper/tests/test_miner_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ def test_get_gateway_mfr_command_v021_multi_SWARM_KEY_58(self, mocked_get_gatewa
expected_result = [ANY, '--device', 'ecc://i2c-4:88?slot=10', 'test']
self.assertListEqual(actual_result, expected_result)

@patch("builtins.open", mock_open(read_data=ECC_FILE_DATA_BLANK))
@patch.dict('os.environ', {"VARIANT": "NEBHNT-MULTIPLE-ECC-ADDRESS"})
@patch('subprocess.Popen')
@patch('hm_pyhelper.miner_param.get_gateway_mfr_version',
return_value=Version('0.2.1'))
def test_get_gateway_mfr_command_v021_multi_SWARM_KEY_42(self, mocked_get_gateway_mfr_version,
mock_subproc_popen):
process_mock = Mock()
attrs = {'communicate.return_value': (str.encode("42 --"), 'error')}
process_mock.configure_mock(**attrs)
mock_subproc_popen.return_value = process_mock

actual_result = get_gateway_mfr_command('test')
expected_result = [ANY, '--device', None, 'test']
self.assertListEqual(actual_result, expected_result)

@patch('hm_pyhelper.miner_param.get_gateway_mfr_version',
return_value=Version('0.2.0'))
def test_get_gateway_mfr_command_v020(self, mocked_get_gateway_mfr_version):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

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

0 comments on commit 8d93145

Please sign in to comment.