-
Notifications
You must be signed in to change notification settings - Fork 372
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
Fix /proc/net/route requirement that causes errors on FreeBSD #1638
Conversation
to build_route_list
Codecov Report
@@ Coverage Diff @@
## develop #1638 +/- ##
==========================================
Coverage ? 67.19%
==========================================
Files ? 80
Lines ? 11440
Branches ? 1608
==========================================
Hits ? 7687
Misses ? 3420
Partials ? 333
Continue to review full report at Codecov.
|
- Moved route conversion code from read_route_table to build_route_list - Fixed some typos - Fixed some routes being ignored
1ee6e01 is just a squish of all the other commits. It has all the changes. |
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.
Thank you for your contribution @onenachi. Could you please add some test cases for the changes in freebsd.py file? We have a test file \tests\common\osutil\test_freebsd.py where you can add the specific tests for your changes to improve the code coverage.
I've also initiated a run from our automated end-to-end testing just to ensure the changes are not breaking anything.
Apart from that the changes look good to me.
# Add the route | ||
linux_style_route_file.append("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}".format( | ||
netif, dest, gw, flags, refcount, use, metric, mask, mtu, window, irtt)) | ||
return linux_style_route_file |
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.
The original implementation of this function handles all errors in function and doesn't propagate any exception further.
try:
with open('/proc/net/route') as routing_table:
return list(map(str.strip, routing_table.readlines()))
except Exception as e:
logger.error("Cannot read route table [{0}]", ustr(e))
return []
After you refactor this function, could you please ensure that the read_route_table
function doesn't raise any exception so as to not break the agent
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.
done with 515b672
@@ -29,6 +31,103 @@ def tearDown(self): | |||
def test_get_dhcp_pid_should_return_a_list_of_pids(self): | |||
osutil_get_dhcp_pid_should_return_a_list_of_pids(self, FreeBSDOSUtil()) | |||
|
|||
def test_empty_proc_net_route(self): |
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.
Thank you for adding the tests 👍
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.
Left some comments around refactoring and exception handling.
return linux_style_route_file | ||
netstat_output = netstat_output[3:] | ||
# Parse the Netstat -RN header line | ||
n_columns = 0 |
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.
Could you add a comment with a sample output of netstat -rn
is to make it easier for the reader to understand the parsing logic
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.
Exmples added as requested in 10819af
|
||
:return: Entries in the route priority table from `netstat -rn` | ||
:rtype: list(str) | ||
""" |
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.
Could you please add an example of how the netstat -rn
output differs with the linux based proc/net/route
header just to make sure what this function is parsing
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.
Exmples added as requested in 10819af
- refactored it into meaningful subfunctions - modified the function documentation to make it more understandable - added examples to the function documentation
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.
@narrieta this LGTM, can you please take a look
if os.path.exists(route_file) and \ | ||
KNOWN_WIRESERVER_IP_ENTRY in open(route_file).read(): | ||
route_table = self.osutil.read_route_table() | ||
if any([(KNOWN_WIRESERVER_IP_ENTRY in route) for route in route_table]): |
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.
In the original code there was a check for exists(route_file); if it was false, we would output a warning.
In the new code this would be reported as an error.
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'm not sure how to work around this. read_route_table will log an error by default and then return an empty list if /proc/net/route doesn't exist.
The only thing it guarantees is not to raise an exception.
Im not sure changing that function would be appropriate. I do think using that function would be appropriate since checking route is clearly a platform specific task.
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 also do think that this is an edge case and not really an issue as it will only log an error on systems without /proc/net/route (non Linux systems) which have not overridden that function with their own osutil (so now, neither Linux nor FreeBSD).
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
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.
requestion 1 small change, otherwise looks good
:rtype: list(dict) | ||
""" | ||
cmd = "netstat -rn -f inet" | ||
ret, output = shellutil.run_get_output(cmd) |
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.
we are deprecating shellutil.run_get_output in favor of shellutil.run_command, could you change this?
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.
:rtype: list(dict) | ||
""" | ||
cmd = "netstat -rn -f inet" | ||
output = shellutil.run_command(cmd, log_error=True) |
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.
thank you for the update.
run_command sets shell=False when invoking subprocess.Popen, so the command needs to be passed as an array of strings; see, for example https://github.com/Azure/WALinuxAgent/blob/develop/azurelinuxagent/common/utils/cryptutil.py#L55
Also, please be sure to tests this end-to-end on your side. Our test infrastructure does not validate FreeBSD.
Thanks
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.
Fixed in 08ba686
Tested in FreeBSD 11.2 on Azure:
Route table is read successfully.
Sorry about that.
LGTM; running automation - will approve and merge after that |
Automation OK |
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.
Thank you!
Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation git-svn-id: svn+ssh://svn.freebsd.org/ports/head@517374 35697150-7ecd-e111-bb59-0022644237b5
Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation
Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation git-svn-id: svn+ssh://svn.freebsd.org/ports/head@517374 35697150-7ecd-e111-bb59-0022644237b5
Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation
- Update to 2.2.45 (pre-release) to pull in the requried fix Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation Approved by: ports-secteam (blanket(s): bugfix release)
- Update to 2.2.45 (pre-release) to pull in the requried fix Azure/WALinuxAgent#1638 - Update WWW to where the code exists - Switch to use Python 3 to match the ports' default to avoid some subprocess invoking issues Approved by: Wei Hu <weh@microsoft.com> (maintainer, implicitly) Sponsored by: The FreeBSD Foundation Approved by: ports-secteam (blanket(s): bugfix release)
Description
This is a fix for Issue #1479).
What it does is:
/proc/net/route
in wireserver_route_exists in dhcp.py, it calls the osutil.get_list_of_routes API and checks if the route destination matches the KNOWN_WIRESERVER_IPnetstat -rn
and creates RouteEntry objects that look similar enough to the Linux ones for the rest of the code to workIssue #1479
PR information
Quality of Code and Contribution Guidelines
This change is