Skip to content
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

Add option for detached HUP on start_os_update #378

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jaomaloy
Copy link

This will call the v2 actions endpoint for resinhup which runs a detached version of HUP that increases HUP reliability on slow networks but will offer
no status updates such as in_progress.

Change-type: minor

@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@jaomaloy jaomaloy force-pushed the jaomaloy/detached-hup branch 2 times, most recently from 0b1c6ee to 30af156 Compare January 30, 2025 12:09
Copy link
Contributor

@kb2ma kb2ma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First pass review. Have not tested operation yet.

DOCUMENTATION.md Outdated Show resolved Hide resolved
balena/models/device.py Outdated Show resolved Hide resolved
balena/models/device.py Outdated Show resolved Hide resolved
balena/models/device.py Outdated Show resolved Hide resolved
@jaomaloy jaomaloy force-pushed the jaomaloy/detached-hup branch 2 times, most recently from 00f8a99 to 0d3c654 Compare February 6, 2025 16:07
@@ -1766,7 +1776,7 @@ def start_os_update(self, uuid_or_id: Union[str, int], target_os_version: str) -
data = {"parameters": {"target_version": target_os_version}}

url_base = self.__config.get_all()["deviceUrlsBase"]
action_api_version = self.__settings.get("device_actions_endpoint_version")
action_api_version = "v2" if run_detached is True else self.__settings.get("device_actions_endpoint_version")
Copy link
Contributor

@otaviojacobi otaviojacobi Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
action_api_version = "v2" if run_detached is True else self.__settings.get("device_actions_endpoint_version")
action_api_version = "v2" if run_detached else self.__settings.get("device_actions_endpoint_version")

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kb2ma @jaomaloy Are we using v2 actions endpoint only on for HuP or should the entire SDK move to the new actions endpoint?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v2 is only for detached HUP at this point @otaviojacobi

Copy link
Contributor

@kb2ma kb2ma Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch on the "is True", @otaviojacobi . If the user happens to use runDetached="True", that still works with your change since the test now is for Truthiness. I'm a little surprised use of a string isn't type checked though since it's typed as Optional[bool] .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the key thing here is to (similar to typescript) always think of the type system as best effort. There is only so much you can do on a dynamically typed languages (js/python) to avoid these mistakes. There is the argument of if someone does run_detatched="False" it will still be truthy, however considering it defaults to False I think someone messing with this parameter probably wants to run detatched

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also always validate that it is either True False or None and throw it otherwise so that we avoid all these sort of issues. I would defer if you want to go this route to you

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually like the strict checking best to remove the ambiguity.

Copy link
Author

@jaomaloy jaomaloy Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Added below.

if not isinstance(run_detached, bool) and run_detached is not None:
            raise ValueError(f"run_detached must be True, False, or None, got {type(run_detached)}: {run_detached}")
action_api_version = "v2" if run_detached is True else self.__settings.get("device_actions_endpoint_version")

Copy link
Contributor

@kb2ma kb2ma Feb 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why we need to allow the value to be None. We have a default value of False. How about:

if not isinstance(run_detached, bool):
    raise ValueError(f"run_detached must be True or False, got {type(run_detached)}: {run_detached}")
action_api_version = "v2" if run_detached else self.__settings.get("device_actions_endpoint_version")

@jaomaloy jaomaloy marked this pull request as ready for review February 6, 2025 16:29
@jaomaloy jaomaloy force-pushed the jaomaloy/detached-hup branch 2 times, most recently from 48c22db to c9e3d7d Compare February 6, 2025 16:35
@flowzone-app flowzone-app bot enabled auto-merge February 6, 2025 16:50
@jaomaloy jaomaloy requested a review from kb2ma February 7, 2025 04:17
@kb2ma
Copy link
Contributor

kb2ma commented Feb 7, 2025

Tested HUP against live device with and without runDetached=True, and it worked as expected.

Added a commit with some simple input tests on start_os_update().

@jaomaloy if you can squash in my commit and fix the issue flagged by otaviojacoby, I'm happy to approve. Of course let me know if you have any concerns about the test I added.

@jaomaloy jaomaloy force-pushed the jaomaloy/detached-hup branch 5 times, most recently from 7db7935 to b7df93c Compare February 11, 2025 03:42
This will call the v2 actions endpoint for resinhup
which runs a detached version of HUP that increases
HUP reliability on slow networks but will offer
no status updates such as in_progress.

Add tests for start_os_update as well.

Change-type: minor
@jaomaloy jaomaloy force-pushed the jaomaloy/detached-hup branch from b7df93c to 7ab93c0 Compare February 11, 2025 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants