-
-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better detect BT devices and LTE devices #242
Conversation
ef3f6bc
to
3178de9
Compare
Dockerfile
Outdated
pkg-config=0.29-6 \ | ||
libdbus-1-3 && \ | ||
# Because the PATH is already updated above, this command creates a new venv AND activates it | ||
python3 -m venv /opt/venv && \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC @marvinmarnold and @vpetersson mentioned previously that there was little point in using venv in containerised setup.
Think was in relation to hm-config but guess it applies here too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still have a soft spot for venv since it makes python portable. But yea, we did agree to stop using it.
@posterzh hm-pktfwd is an example of the new pattern: https://github.com/NebraLtd/hm-pktfwd/blob/e067bef1be17f9d3c1036cbe1100b317d5cc5f57/Dockerfile#L65
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marvinmarnold I am not fussed either way! Whichever you think is best TBH
Dockerfile
Outdated
RUN \ | ||
install_packages \ | ||
i2c-tools \ | ||
bluez \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need bluez and network manager in the container if we are communicating with them over dbus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shawaj Without the dependencies of bluez
, network-manager
, modem-manager
, detecting BT, WIFI, LTE devices works well with only dbus
dependency. I removed unnecessary dependencies in the Dockerfile.
Dockerfile
Outdated
# Finally, use pip to install dependencies. | ||
RUN \ | ||
install_packages \ | ||
python3-dev=3.7.3-1 \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC @vpetersson thought it best to unpin packages previously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sense
aa12bc8
to
23de222
Compare
Nice improvement, @posterzh! |
23de222
to
0da1c07
Compare
0da1c07
to
7907641
Compare
7907641
to
03b9a44
Compare
03b9a44
to
7fe3df3
Compare
Looks good to me, but probably worth @vpetersson or @marvinmarnold or someone else from @NebraLtd/developers taking a deeper look. |
Good job @posterzh. This is a big improvement. I wonder however if we should move the detection logic to hm-pyhelper` instead as we should probably re-use this code in hm-diag too. Wdyt @marvinmarnold? |
FYI, in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This work looks really good. The code is very readable and clear.
This logic also needs to be added to https://github.com/NebraLtd/hm-diag/blob/00c716dd4980e35ac7436d9f59aebb17bec07535/hw_diag/diagnostics/bt_lte_diagnostic.py Until we have completed https://github.com/NebraLtd/Hotspot-Production-Tool/issues/28 we will continue to have parallel logic for /json and /initFile.txt.
Lastly, my typical comment. Could you please add some basic unit tests?
hw_diag/utilities/hardware.py
Outdated
from hm_pyhelper.miner_param import get_public_keys_rust | ||
from hm_pyhelper.hardware_definitions import variant_definitions, is_rockpi | ||
from hw_diag.utilities.shell import config_search_param | ||
|
||
log = logging.getLogger() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use get_logger from hm_pyhelper?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, make sense.
hw_diag/utilities/hardware.py
Outdated
|
||
|
||
if __name__ == '__main__': | ||
print('set_diagnostics_bt_lte: %s' % set_diagnostics_bt_lte({})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be log instead of print.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
Dockerfile
Outdated
pip3 install --no-cache-dir -r /tmp/build/requirements.txt && \ | ||
python3 setup.py install && \ | ||
rm -rf /tmp/build | ||
# Cleanup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this entirely. That's the whole purpose of using install_packages
from Balena as it takes care of the cleanup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the size of the docker image is same after removing the clean up.
hw_diag/utilities/hardware.py
Outdated
from hm_pyhelper.miner_param import get_public_keys_rust | ||
from hm_pyhelper.hardware_definitions import variant_definitions, is_rockpi | ||
from hw_diag.utilities.shell import config_search_param | ||
|
||
log = logging.getLogger() | ||
log.setLevel(logging.DEBUG) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log level needs to be controlled centrally. IIRC we already have a framework for this. We don't want debug logging in production unless we're troubleshooting something.
hw_diag/utilities/hardware.py
Outdated
@@ -15,25 +74,112 @@ def should_display_lte(diagnostics): | |||
return variant_data.get('CELLULAR') | |||
|
|||
|
|||
def get_ble_devices(): | |||
log.info("Get BLE devices.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'Retrieving list of BLE device(s)"
hw_diag/utilities/hardware.py
Outdated
"Discovering": str(adapter.get("Discovering")), | ||
}) | ||
|
||
log.info('BLE Devices: %s' % ble_devices) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Found the following BLE devices:"
hw_diag/utilities/hardware.py
Outdated
log.info('BLE Devices: %s' % ble_devices) | ||
except dbus.exceptions.DBusException as ex: | ||
log.error(ex.get_dbus_message()) | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the standardized way is to do Exception as e
. Not a big deal, just to keep things consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I will keep in mind it.
hw_diag/utilities/hardware.py
Outdated
log.info('WiFi Devices: %s' % wifi_devices) | ||
except dbus.exceptions.DBusException as ex: | ||
log.error(ex.get_dbus_message()) | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as e
(same as above).
hw_diag/utilities/hardware.py
Outdated
|
||
|
||
def get_lte_devices(): | ||
log.info("Get LTE devices.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Retrieving list of LTE device(s)."
hw_diag/utilities/hardware.py
Outdated
}) | ||
|
||
log.info('LTE Devices: %s' % lte_devices) | ||
except dbus.exceptions.DBusException as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as e
(same as above).
hw_diag/utilities/hardware.py
Outdated
log.info('LTE Devices: %s' % lte_devices) | ||
except dbus.exceptions.DBusException as ex: | ||
log.error(ex.get_dbus_message()) | ||
except Exception as ex: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as e
(same as above).
hw_diag/utilities/hardware.py
Outdated
|
||
|
||
if __name__ == '__main__': | ||
print('set_diagnostics_bt_lte: %s' % set_diagnostics_bt_lte({})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid using print()
in favor of logging
.
@posterzh Please fix the linting errors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved by me, but I would ideally like to see some unit tests here. Don't merge this before @marvinmarnold approves it.
Dockerfile
Outdated
install_packages \ | ||
build-essential \ | ||
libdbus-glib-1-dev && \ | ||
pip3 install --no-cache-dir --target="$PYTHON_DEPENDENCIES_DIR" . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking here, but I'd probably run this on a separate RUN
line just to help with debugging if for whatever reason it would fail building.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would help debugging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved by me, but I would ideally like to see some unit tests here. Don't merge this before @marvinmarnold approves it.
Yeah, I am writing the unit test and a parallel logic in DiagnosticsReport
. These pushes are just for In-progress
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Please update the PR to 'Draft' mode if that is the case.
@vpetersson do you think we would need this in hm-config? We seem to be using some custom nmcli in there so not sure it'll be compatible https://github.com/NebraLtd/hm-config/blob/3b2e0fe138ab04533ffa44afa3d0a60d7972430e/gatewayconfig/processors/wifi_processor.py#L20 |
@marvinmarnold
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about using a separate BtDiagnostics and LteDiagnostics rather than BtLteDiagnostics?
Good idea but lets not let that hold things up. Merge this and create a follow up ticket to do in a future sprint.
@marvinmarnold I created a follow up ticket as above. |
Why
Detect the BLE and LET devices in better way.
How
Get the BLE devices and LTE devices programatically using dbus.
References
#96
#88