Skip to content

Commit

Permalink
Merge pull request #291 from NebraLtd/murat/feat-add-short-git-sha
Browse files Browse the repository at this point in the history
feat: Added FIRMWARE_SHORT_HASH report
  • Loading branch information
MuratUrsavas authored Jan 28, 2022
2 parents 6f323fe + 241e514 commit a467c93
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,6 @@ dmypy.json

# Cython debug symbols
cython_debug/

# VSCode editor related stuff
.vscode/
3 changes: 3 additions & 0 deletions hw_diag/diagnostics/env_var_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
}, {
'ENV_VAR': 'VARIANT',
'DIAGNOSTIC_KEY': 'VA'
}, {
'ENV_VAR': 'FIRMWARE_SHORT_HASH',
'DIAGNOSTIC_KEY': 'firmware_short_hash'
}]


Expand Down
2 changes: 1 addition & 1 deletion hw_diag/templates/diagnostics_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ <h3 class="text-center mb-4">Diagnostics Breakdown</h3>
</tr>
<tr>
<td>Firmware Version</td>
<td class="text-right">{{ diagnostics.FW }}</td>
<td class="text-right">{{ diagnostics.FW }} ({{ diagnostics.firmware_short_hash }})</td>
</tr>
<tr>
<td>Frequency</td>
Expand Down
7 changes: 6 additions & 1 deletion hw_diag/tests/diagnostics/test_env_var_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,10 @@ def test_env_vars_success(self):
'FIRMWARE_VERSION': 'foo',
'FW': 'foo',
'VARIANT': 'foo',
'VA': 'foo'
'VA': 'foo',
# We're moving towards longer lowercase key naming and will
# deprecate old ones in near future. Just keeping this entry in the
# list for the sake of style compatibility.
'FIRMWARE_SHORT_HASH': 'foo',
'firmware_short_hash': 'foo'
})
7 changes: 6 additions & 1 deletion hw_diag/tests/test_views_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ def test_initFile_output(self):

@patch.dict(
os.environ,
{'FIRMWARE_VERSION': '1337.13.37', 'DIAGNOSTICS_VERSION': 'aabbffe'}
{
'FIRMWARE_VERSION': '1337.13.37',
'DIAGNOSTICS_VERSION': 'aabbffe',
'FIRMWARE_SHORT_HASH': '0011223'
}
)
def test_version_endpoint(self):
# Check the version json output
Expand All @@ -81,3 +85,4 @@ def test_version_endpoint(self):
self.assertEqual(resp.status_code, 200)
self.assertEqual(reply['firmware_version'], '1337.13.37')
self.assertEqual(reply['diagnostics_version'], 'aabbffe')
self.assertEqual(reply['firmware_short_hash'], '0011223')
5 changes: 3 additions & 2 deletions hw_diag/utilities/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def get_environment_var(diagnostics):
'BALENA_APP_NAME',
'FREQ',
'FIRMWARE_VERSION',
'VARIANT'
'VARIANT',
'FIRMWARE_SHORT_HASH'
]
keys = ["BN", "ID", "BA", "FR", "FW", "VA"]
keys = ["BN", "ID", "BA", "FR", "FW", "VA", "firmware_short_hash"]

for (var, key) in zip(env_var, keys):
diagnostics[key] = os.getenv(var)
Expand Down
1 change: 1 addition & 0 deletions hw_diag/views/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def version_information():
response = {
'firmware_version': os.getenv('FIRMWARE_VERSION', 'unknown'),
'diagnostics_version': os.getenv('DIAGNOSTICS_VERSION', 'unknown'),
'firmware_short_hash': os.getenv('FIRMWARE_SHORT_HASH', 'unknown'),
}

return response

0 comments on commit a467c93

Please sign in to comment.