-
Notifications
You must be signed in to change notification settings - Fork 229
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
Sonic: Deserialize and convert resolve.conf #8208
Conversation
Codecov Report
@@ Coverage Diff @@
## master #8208 +/- ##
============================================
- Coverage 74.50% 74.49% -0.01%
- Complexity 43519 43532 +13
============================================
Files 3388 3391 +3
Lines 168716 168781 +65
Branches 20176 20186 +10
============================================
+ Hits 125698 125736 +38
- Misses 33479 33496 +17
- Partials 9539 9549 +10
|
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.
Reviewed 7 of 17 files at r1, 10 of 10 files at r2, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @dhalperi and @ratulm)
projects/batfish/src/main/java/org/batfish/vendor/sonic/grammar/SonicControlPlaneExtractor.java, line 77 at r2 (raw file):
ResolveConf.deserialize( _fileTexts.get(resolveConfFilename), _fileResults.get(configDbFilename).getWarnings());
Should this be resolveConfFilename
?
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 21 at r2 (raw file):
private @Nonnull final List<Ip6> _nameservers6; public ResolveConf(List<Ip> nameservers, List<Ip6> nameservers6) {
Perhaps make this private and make the immutable copies in deserialize
?
I don't see any other usages in this PR.
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 26 at r2 (raw file):
} public static ResolveConf deserialize(String resolveConfText, Warnings warnings) {
nit: @Nonnull
return type
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 32 at r2 (raw file):
String[] lines = resolveConfText.split("\n"); for (String line : lines) { String[] parts = line.split("\\s");
From my read of split
javadoc, this won't work with leading whitespace.
Rather than splitting by lines and then by whitespace, why not just iterate over the file with a line regex until no more matches are found?
Something like "(?m)^\\s*nameserver\\s+(^[#\\s]+).*$"
, then grab group 1.
Note this also handles trailing comments.
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.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @dhalperi and @ratulm)
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 32 at r2 (raw file):
Previously, arifogel (Ari Fogel) wrote…
From my read of
split
javadoc, this won't work with leading whitespace.
Rather than splitting by lines and then by whitespace, why not just iterate over the file with a line regex until no more matches are found?
Something like"(?m)^\\s*nameserver\\s+(^[#\\s]+).*$"
, then grab group 1.
Note this also handles trailing comments.
stricter: "(?m)^\\s*nameserver\\s+(^[#\\s]+)\\s*(#.*)?$"
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @arifogel and @dhalperi)
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 32 at r2 (raw file):
Previously, arifogel (Ari Fogel) wrote…
stricter:
"(?m)^\\s*nameserver\\s+(^[#\\s]+)\\s*(#.*)?$"
made it robust to extra whitespace while keeping the line-by-line splitting approach.
are those trailing comments legal? i couldn't find a pointer.
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.
Reviewed 3 of 3 files at r3, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dhalperi and @ratulm)
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 32 at r2 (raw file):
Previously, ratulm wrote…
made it robust to extra whitespace while keeping the line-by-line splitting approach.
are those trailing comments legal? i couldn't find a pointer.
Yes they are valid, just tested. They are generally valid in all linux .conf
files
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.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @dhalperi and @ratulm)
projects/batfish/src/main/java/org/batfish/vendor/sonic/representation/ResolveConf.java, line 32 at r2 (raw file):
Also, on linux (Ubuntu 18.04 at least), only up to 3 nameservers may be used:
Up to MAXNS (currently 3, see <resolv.h>) name servers may be listed, one per keyword.
It's not clear if that's 3 ipv4 and 3 ipv6, or 3 total. My guess is total.
We can probably defer limiting for now.
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.
Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: complete! all files reviewed, all discussions resolved (waiting on @dhalperi)
After #8204 and #8207