-
Notifications
You must be signed in to change notification settings - Fork 220
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
Fixes #12211 - Improve DHCP subnets parsing to get more informations … #330
Conversation
5a59cdb
to
5839bd7
Compare
case option | ||
when /option\s+routers\s+[\d\.]+/ | ||
# get the first router match and use it for gateway | ||
options[:gateway] = option.scan(/option\s+routers\s+([\d\.]+)/).first.first |
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.
why not keep the whole list?
@bagasse: cheers for the PR! I feel that in the data we return we should keep option names and format of their values close to the original ones (if not the same): Another issue that I see is that dhcp config file may contain global options applicable to all subnets (and potentially overridden in individual subnet configs). I we should support this if we are going to return these additional options. |
@witlessbird I changed the options names to map names used on the foreman side. I will update the PR to keep names like in the dhcp server config, and keep all values too. |
@bagasse: let's wait with the renaming until we hear something from the foreman side (although I think it makes sense to rename attribute names there and keep them close to original here). Yeah, I agree that parsing global options makes things more complicated (and possibly warrants a real parser, not regexes). I'm ok with postponing this bit, as long as we can get the functionality in not too distant future. |
5839bd7
to
e19101a
Compare
[test] |
e19101a
to
0977f1c
Compare
@dLobatog: I've fixed rubocop warnings, sorry i forgot to run rubocop before on this PR. For the get_root of dhcp_api_test, all test are green in my dev env (CentOS 7, ruby 1.9.3). I seen in jenkins that this test only fail with ruby 1.8.7. I don't know why, with this ruby version, networks presents in the list are not in the same order than in others ruby versions. I will take a look at this more deeply tomorrow. |
[test] |
@@ -288,8 +298,7 @@ def read_config file, ignore_includes=false | |||
logger.debug "Reading config file #{file}" | |||
config = [] | |||
File.readlines(file).each do |line| | |||
|
|||
line.strip! # remove left and right whitespace | |||
line = line.split('#').first.strip # remove comments, left and right whitespace |
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.
Why this change? The next line used to skip over comments (and isn't needed with this change).
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 my understanding, the next line remove lines that starts with comment, this remove comments at the end of lines. But if you want i can remove 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.
once you call String#split
all instances of the symbol you used to split the string will be removed, which makes https://github.com/bagasse/smart-proxy/blob/Fixes_12211_-_Improve_DHCP_subnets_parsing_to_get_more_informations_from_DHCP_server/modules/dhcp/providers/server/isc.rb#L302 redundant.
I'm ok with this change if you remove code on line 302.
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.
line 302 removed.
0977f1c
to
c28d12b
Compare
@witlessbird: changed, arrays to sets, thanks for pointing this out to me. |
[test] |
@@ -82,8 +82,24 @@ def test_poap_quirks | |||
def test_loadSubnets_loads_managed_subnets | |||
subnets = @dhcp.loadSubnets |
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 know that this was here before, but it wasn't a very good test: loadSubnets
returns subnets that were processed, not the data that was stored.
Another issue is that this tests too many things; which will make it harder to pinpoint an issue should code change. Could you break this up to test specific cases, for example handling of domain_name_server
option when it's not present, when only one server is present, when both are present, etc.
It is probably easier to work directly with subnet_service (see @subnet_service
in setup -- you can query it for relevant subnets, as opposed to parsing the hash returned by @dhcp.subnets
.
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 my understanding, loadSubnets
implementation of Proxy::DHCP::Server::ISC
load subnets only from config files and Proxy::DHCP::SubnetService
is only here to store loaded data, so i don't see the problem to use loadSubnets
here. For the other point, i've separated tests in several methods.
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.
Nods,that's correct. However, currently these tests verify the behaviour of parse_config_for_subnets
method: so either calls to loadSubnets
should be replaced with calls to parse_config_for_subnets
, or the assertions should be made against Proxy::DHCP::SubnetService
(the main side-effect of loadSubnets
is initialization of SubnetService
).
@bagasse: Looks pretty good, only needs some changes in tests around added functionality. |
c28d12b
to
ec1d84d
Compare
[test] one last time :) |
@domcleal Glad to join and thank you for the invitation :) |
ec1d84d
to
d2938d9
Compare
ret_val << Proxy::DHCP::Subnet.new(match[0], match[1]) | ||
@config.scan(/subnet\s+([\d\.]+)\s+netmask\s+([\d\.]+)\s*{([\w|;|\.|,|\-|\s]*)}/) do |match| | ||
options = {} | ||
if match[2] |
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.
Mind to extract this logic to a method or something similar? Maybe write a comment / save match[0] match[1] match[2]
to named variables? It's a bit difficult to understand without being well acquainted with the format of the conf file.
d2938d9
to
424b1b6
Compare
@dLobatog you are right, it's not really readable, i've extracted range regexp too and used named vars. |
@@ -409,4 +421,14 @@ def poap_options_statements(options) | |||
statements | |||
end | |||
end | |||
|
|||
# Get all IPv4 addresses provided by the ISC DHCP config line following the pattern "my-config-option-or-directive IPv4_ADDR[, IPv4_ADDR] [...];" and return an array. | |||
def get_ip_list_from_config_line(option_line) |
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 test for this method?
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.
It was already there, but i've added a test for get_range_from_config_line
that i've extracted too. I changed loadSubnets
calls to parse_config_for_subnets
as suggested.
424b1b6
to
3761282
Compare
[test] |
Waiting for tests to pass before merging. |
@witlessbird @dLobatog, thank you for pointers and re (re re re)-reviews :) |
…from DHCP server
Add ability to parse some subnet options and provides them to the foreman to enhance subnet imports.
This modify the dhcp smart-proxy API (adding options hash).