Skip to content

Conversation

joaoantoniocardoso
Copy link
Member

@joaoantoniocardoso joaoantoniocardoso commented Aug 22, 2025

This is a backport of #3479 into 1.4

Summary by Sourcery

Backport fix for DHCP marker removal: introduce include_dhcp_markers parameter in interface getters to preserve 0.0.0.0 AddressMode.Client entries and apply it during route updates

Bug Fixes:

  • Preserve DHCP marker entries by re-adding stored 0.0.0.0 AddressMode.Client when requested

Enhancements:

  • Add include_dhcp_markers parameter to get_interface_by_name, get_interfaces, and get_ethernet_interfaces to control DHCP marker inclusion

Copy link

sourcery-ai bot commented Aug 22, 2025

Reviewer's Guide

Backport of DHCP marker preservation: adds an include_dhcp_markers flag to interface retrieval methods and adjusts get_interfaces to restore 0.0.0.0 AddressMode.Client entries when requested.

Sequence diagram for get_interface_by_name with DHCP marker preservation

sequenceDiagram
    participant Caller
    participant Manager
    participant EthernetInterfaces
    participant NetworkInterface
    Caller->>Manager: get_interface_by_name(name, include_dhcp_markers=True)
    Manager->>EthernetInterfaces: get_ethernet_interfaces(include_dhcp_markers=True)
    EthernetInterfaces->>Manager: get_interfaces(filter_wifi=True, include_dhcp_markers=True)
    Manager->>NetworkInterface: Iterate interfaces
    NetworkInterface-->>Manager: Return matching interface
    Manager-->>Caller: Return NetworkInterface
Loading

Sequence diagram for get_interfaces restoring DHCP marker

sequenceDiagram
    participant Manager
    participant SavedInterface
    participant ValidAddresses
    Manager->>SavedInterface: get_saved_interface_by_name(interface)
    alt include_dhcp_markers is True and marker missing
        SavedInterface-->>Manager: Has 0.0.0.0 AddressMode.Client
        Manager->>ValidAddresses: Add 0.0.0.0 AddressMode.Client
    end
    Manager-->>ValidAddresses: Return addresses
Loading

Class diagram for updated interface retrieval methods in manager.py

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]
    }
    class NetworkInterface {
        +name: str
        +addresses: List[InterfaceAddress]
        +routes: List[Route]
    }
    class InterfaceAddress {
        +ip: str
        +mode: AddressMode
    }
    class AddressMode {
        <<enum>>
        Client
        Unmanaged
    }
    Manager --> NetworkInterface
    NetworkInterface --> InterfaceAddress
    InterfaceAddress --> AddressMode
Loading

File-Level Changes

Change Details Files
Add include_dhcp_markers parameter to interface retrieval methods and propagate it
  • Extend get_interface_by_name signature with include_dhcp_markers and update docstring
  • Extend get_interfaces signature with include_dhcp_markers and update docstring
  • Extend get_ethernet_interfaces signature to accept include_dhcp_markers and pass it through
  • Update _execute_route to call get_interface_by_name with include_dhcp_markers=True
core/services/cable_guy/api/manager.py
Preserve DHCP marker entries in get_interfaces
  • Check saved settings for 0.0.0.0 AddressMode.Client entries
  • Append missing DHCP marker to valid_addresses when include_dhcp_markers is true
core/services/cable_guy/api/manager.py

Possibly linked issues

  • #0: The PR fixes how DHCP markers are managed, which is crucial for the DHCP Server's enabled status and prevents the console loop described in the issue.
  • Core: Services: Cable Guy: Fix DHCP Client marker being removed #3479: PR modifies DHCP marker handling, resolving network configuration issues caused by backward incompatible DHCP server settings.

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

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 and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `core/services/cable_guy/api/manager.py:491` </location>
<code_context>
             List of NetworkInterface instances available
         """
-        return self.get_interfaces(filter_wifi=True)
+        return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)

     def get_interface_ndb(self, interface_name: str) -> Any:
</code_context>

<issue_to_address>
Consider documenting the interaction between filter_wifi and include_dhcp_markers.

Please update the docstring to clarify how filter_wifi and include_dhcp_markers interact, particularly if their combination introduces edge cases.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
        """Get ethernet interfaces information

        Args:
            include_dhcp_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
            inform cable guy that a dynamic IP should be acquired if available.

        Returns:
            List of NetworkInterface instances available
        """
        return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)
=======
        """Get ethernet interfaces information

        Args:
            include_dhcp_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
                inform cable guy that a dynamic IP should be acquired if available.

        Returns:
            List of NetworkInterface instances available

        Note:
            This method always sets filter_wifi=True to exclude WiFi interfaces.
            If include_dhcp_markers is True, DHCP marker interfaces (with IP 0.0.0.0 and AddressMode.Client)
            will be included in the returned list, even if they are not fully configured.
            The combination of filter_wifi=True and include_dhcp_markers=True means only non-WiFi interfaces
            are returned, but DHCP marker entries for those interfaces will be present if available.
        """
        return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)
>>>>>>> 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.

Comment on lines 482 to +491
"""Get ethernet interfaces information
Args:
include_dhcp_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
inform cable guy that a dynamic IP should be acquired if available.
Returns:
List of NetworkInterface instances available
"""
return self.get_interfaces(filter_wifi=True)
return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)
Copy link

Choose a reason for hiding this comment

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

suggestion: Consider documenting the interaction between filter_wifi and include_dhcp_markers.

Please update the docstring to clarify how filter_wifi and include_dhcp_markers interact, particularly if their combination introduces edge cases.

Suggested change
"""Get ethernet interfaces information
Args:
include_dhcp_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
inform cable guy that a dynamic IP should be acquired if available.
Returns:
List of NetworkInterface instances available
"""
return self.get_interfaces(filter_wifi=True)
return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)
"""Get ethernet interfaces information
Args:
include_dhcp_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
inform cable guy that a dynamic IP should be acquired if available.
Returns:
List of NetworkInterface instances available
Note:
This method always sets filter_wifi=True to exclude WiFi interfaces.
If include_dhcp_markers is True, DHCP marker interfaces (with IP 0.0.0.0 and AddressMode.Client)
will be included in the returned list, even if they are not fully configured.
The combination of filter_wifi=True and include_dhcp_markers=True means only non-WiFi interfaces
are returned, but DHCP marker entries for those interfaces will be present if available.
"""
return self.get_interfaces(filter_wifi=True, include_dhcp_markers=include_dhcp_markers)


# pylint: disable=too-many-locals
def get_interfaces(self, filter_wifi: bool = False) -> List[NetworkInterface]:
def get_interfaces(self, filter_wifi: bool = False, include_dhcp_markers: bool = False) -> List[NetworkInterface]:
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:


Explanation

The quality score for this function is below the quality threshold of 25%.
This score is a combination of the method length, cognitive complexity and working memory.

How can you solve this?

It might be worth refactoring this function to make it shorter and more readable.

  • Reduce the function length by extracting pieces of functionality out into
    their own functions. This is the most important thing you can do - ideally a
    function should be less than 10 lines.
  • Reduce nesting, perhaps by introducing guard clauses to return early.
  • Ensure that variables are tightly scoped, so that code using related concepts
    sits together within the function rather than being scattered.

@patrickelectric
Copy link
Member

Let's wait for the original PR to be merged

* Make sure that when `_execute_route` is called it keeps the DHCP
  requisition IP marker `0.0.0.0` `Mode.Client` alive
@joaoantoniocardoso joaoantoniocardoso force-pushed the backports/1.4/fix-removed-dhcp-marker branch from 8fce0de to 0fd549e Compare August 27, 2025 17:37
@joaoantoniocardoso joaoantoniocardoso changed the title core:services:cabel_guy: Fix DHCP marker removing core:services:cable_guy: Fix DHCP marker removing Aug 27, 2025
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.

seemed to work as expected here, nice =]

@joaoantoniocardoso
Copy link
Member Author

seemed to work as expected here, nice =]

Did you test the original PR as well (#3479)?

@Williangalvani
Copy link
Member

seemed to work as expected here, nice =]

Did you test the original PR as well (#3479)?

not really, will do tomorrow

@Williangalvani Williangalvani changed the title core:services:cable_guy: Fix DHCP marker removing [backport] core:services:cable_guy: Fix DHCP marker removing Aug 29, 2025
Copy link
Member

@patrickelectric patrickelectric left a comment

Choose a reason for hiding this comment

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

parent PR was merged

@patrickelectric patrickelectric merged commit 9686ac9 into bluerobotics:1.4 Aug 29, 2025
6 checks passed
@Williangalvani
Copy link
Member

re-tested this anyway. all good.

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