Skip to content

Conversation

@joaomariolago
Copy link
Collaborator

@joaomariolago joaomariolago commented Aug 9, 2025

Make sure that when _execute_route is called it keeps the DHCP requisition IP marker 0.0.0.0 Mode.Client alive if the link changed it's state somehow.

Related to #3466

Summary by Sourcery

Preserve the DHCP client IP marker (0.0.0.0 Mode.Client) when link state changes by propagating a new include_dhcp_markers flag through interface retrieval methods and using it in route execution.

Bug Fixes:

  • Prevent the DHCP client marker from being removed when executing route changes.

Enhancements:

  • Add include_dhcp_markers parameter to get_interfaces, get_interface_by_name, and get_ethernet_interfaces to optionally retain DHCP markers in interface listings.

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 9, 2025

Reviewer's Guide

This PR enhances the Cable Guy manager to preserve the DHCP client marker (0.0.0.0 Mode.Client) when interface state changes by introducing an include_dhcp_markers flag to interface retrieval methods, re-injecting missing DHCP markers in get_interfaces, and updating route execution to retain those markers.

Sequence diagram for preserving DHCP client marker during route execution

sequenceDiagram
    participant Manager
    participant Interface
    participant Settings
    Manager->>Manager: _execute_route(action, interface_name, route)
    Manager->>Manager: get_interface_by_name(interface_name, include_dhcp_markers=True)
    Manager->>Manager: get_ethernet_interfaces(include_dhcp_markers=True)
    Manager->>Manager: get_interfaces(filter_wifi=True, include_dhcp_markers=True)
    Manager->>Settings: get_saved_interface_by_name(interface)
    alt DHCP marker missing in valid_addresses
        Manager->>Manager: Add InterfaceAddress(ip="0.0.0.0", mode=AddressMode.Client)
    end
    Manager->>Interface: Update routes and managed state
Loading

ER diagram for DHCP marker preservation in NetworkInterface addresses

erDiagram
    NETWORKINTERFACE {
        string name
    }
    INTERFACEADDRESS {
        string ip
        string mode
    }
    NETWORKINTERFACE ||--o{ INTERFACEADDRESS: has
    INTERFACEADDRESS }|--|| ADDRESSMODE: mode
    ADDRESSMODE {
        enum Client
        enum Unmanaged
    }
Loading

Class diagram for updated Cable Guy manager interface methods

classDiagram
    class Manager {
        +get_interface_by_name(name: str, include_dhcp_markers: bool = False): NetworkInterface
        +get_interfaces(filter_wifi: bool = False, include_dhcp_markers: bool = False): List[NetworkInterface]
        +get_ethernet_interfaces(include_dhcp_markers: bool = False): List[NetworkInterface]
        +_execute_route(action: str, interface_name: str, route: Route): None
    }
    class NetworkInterface {
        +name: str
        +addresses: List[InterfaceAddress]
        +routes: List[Route]
    }
    class InterfaceAddress {
        +ip: str
        +mode: AddressMode
    }
    class AddressMode {
        <<enumeration>>
        Client
        Unmanaged
    }
    Manager --> NetworkInterface
    NetworkInterface --> InterfaceAddress
    InterfaceAddress --> AddressMode
Loading

File-Level Changes

Change Details Files
Expose include_dhcp_markers flag on interface lookup methods
  • Added include_dhcp_markers parameter to get_interface_by_name
  • Extended get_interfaces signature with include_dhcp_markers
  • Updated get_ethernet_interfaces to forward include_dhcp_markers
core/services/cable_guy/api/manager.py
Re-add saved DHCP client marker in get_interfaces
  • Check saved interface settings for 0.0.0.0 Mode.Client
  • Append DHCP marker when include_dhcp_markers is true and marker is missing
  • Use InterfaceAddress(ip="0.0.0.0", mode=AddressMode.Client) for reinsertion
core/services/cable_guy/api/manager.py
Preserve DHCP marker during route execution
  • Call get_interface_by_name with include_dhcp_markers=True in _execute_route
core/services/cable_guy/api/manager.py

Possibly linked issues

  • Backports/1.4/routes api #3466: The PR ensures the DHCP client marker (0.0.0.0 Mode.Client) is preserved, directly fixing the issue's described problem of the marker being removed.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@joaomariolago joaomariolago force-pushed the fix-removed-dhcp-marker branch from 9e389bc to 9e5ec67 Compare August 9, 2025 16:38
@Williangalvani
Copy link
Member

we might need to backport this to 1.4

@joaomariolago joaomariolago force-pushed the fix-removed-dhcp-marker branch 2 times, most recently from cfe7b07 to 5e58370 Compare August 19, 2025 17:50
@joaomariolago joaomariolago marked this pull request as ready for review August 19, 2025 17:51
Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • Docstring for get_interfaces references include_dynamic_markers but the parameter is named include_dhcp_markers – please align names and descriptions.
  • The new include_dhcp_markers flag in get_ethernet_interfaces is missing from its docstring parameters – please add it for clarity.
  • Consider extracting the DHCP marker re-add logic from get_interfaces into a dedicated helper to reduce method complexity and improve readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Docstring for get_interfaces references include_dynamic_markers but the parameter is named include_dhcp_markers – please align names and descriptions.
- The new include_dhcp_markers flag in get_ethernet_interfaces is missing from its docstring parameters – please add it for clarity.
- Consider extracting the DHCP marker re-add logic from get_interfaces into a dedicated helper to reduce method complexity and improve readability.

## Individual Comments

### Comment 1
<location> `core/services/cable_guy/api/manager.py:472` </location>
<code_context>
         return result

-    def get_ethernet_interfaces(self) -> List[NetworkInterface]:
+    def get_ethernet_interfaces(self, include_dhcp_markers: bool = False) -> List[NetworkInterface]:
         """Get ethernet interfaces information

</code_context>

<issue_to_address>
Consider updating the docstring to mention the new include_dhcp_markers parameter.

The docstring should document the include_dhcp_markers parameter for clarity.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    def get_ethernet_interfaces(self, include_dhcp_markers: bool = False) -> List[NetworkInterface]:
        """Get ethernet interfaces information

=======
    def get_ethernet_interfaces(self, include_dhcp_markers: bool = False) -> List[NetworkInterface]:
        """
        Get ethernet interfaces information.

        Args:
            include_dhcp_markers (bool): If True, include DHCP marker interfaces in the returned list.
        Returns:
            List[NetworkInterface]: List of ethernet network interfaces.
        """
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@joaoantoniocardoso
Copy link
Member

The code looks sane, but only @Williangalvani actually has the setup to reproduce the problem

@joaoantoniocardoso
Copy link
Member

btw, there's a typo in the commit title: "cabel" -> "cable"

* Make sure that when `_execute_route` is called it keeps the DHCP
  requisition IP marker `0.0.0.0` `Mode.Client` alive
@joaomariolago joaomariolago force-pushed the fix-removed-dhcp-marker branch from 74ed9a0 to cd1ea97 Compare August 28, 2025 13:30
@joaomariolago
Copy link
Collaborator Author

btw, there's a typo in the commit title: "cabel" -> "cable"

Fixed the typo thanks.

@patrickelectric
Copy link
Member

waiting for @Williangalvani test to merge

Copy link
Member

@Williangalvani Williangalvani left a comment

Choose a reason for hiding this comment

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

so this "joaomariolago/blueos-core:fix-removed-dhcp-marker" is actually the one I tested.
I'll test the backport now.

@Williangalvani Williangalvani merged commit 6d4acc2 into bluerobotics:master Aug 29, 2025
6 checks passed
@patrickelectric
Copy link
Member

Should be move this to 1.4 ?

@joaoantoniocardoso
Copy link
Member

joaoantoniocardoso commented Oct 23, 2025

Should be move this to 1.4 ?

It's already there: #3505

@patrickelectric patrickelectric removed the move-to-stable Needs to be cherry-picked and move to stable label Oct 23, 2025
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.

4 participants