-
Notifications
You must be signed in to change notification settings - Fork 111
[backport] core:services:cable_guy: Fix DHCP marker removing #3505
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
[backport] core:services:cable_guy: Fix DHCP marker removing #3505
Conversation
Reviewer's GuideBackport 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 preservationsequenceDiagram
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
Sequence diagram for get_interfaces restoring DHCP markersequenceDiagram
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
Class diagram for updated interface retrieval methods in manager.pyclassDiagram
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
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
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>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
"""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) |
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.
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.
"""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]: |
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.
issue (code-quality): We've found these issues:
- Simplify logical expression using De Morgan identities (
de-morgan
) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Use named expression to simplify assignment and conditional (
use-named-expression
) - Low code quality found in EthernetManager.get_interfaces - 16% (
low-code-quality
)
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.
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
8fce0de
to
0fd549e
Compare
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.
seemed to work as expected here, nice =]
Did you test the original PR as well (#3479)? |
not really, will do tomorrow |
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.
parent PR was merged
re-tested this anyway. all good. |
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:
Enhancements: