-
Notifications
You must be signed in to change notification settings - Fork 3
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
[neutron-dhcp-agent] creating resolv.conf in namespaces #68
Conversation
f7ee498
to
b3a8c78
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.
Have you thought about a test for when we set up a DHCP agent on the netns and make sure the file is written?
that is indeed the next item on the agenda :) update: tests are there now |
1c87735
to
d06770c
Compare
d06770c
to
70fbc5f
Compare
6c0954f
to
09ca166
Compare
148a699
to
9d08630
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.
Code looks good, added a couple of comments. When the PR is out of WIP I'll review the tests as well.
9d08630
to
8754d7e
Compare
93542ab
to
47bf728
Compare
47bf728
to
a74153b
Compare
a74153b
to
d6ed0c9
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.
Like the tests
d6ed0c9
to
4df8ec3
Compare
for line in f.readlines(): | ||
if ' ' in line: | ||
keyword, value = line.strip().split(' ', 1) | ||
if keyword in ('search', 'options', | ||
'nameserver'): | ||
found_settings.add((keyword, value)) |
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.
[optional] If this were a resolv.conf parsing function like described above you could also just return the options as a set and do something like assertEqual(set(), settings - set(self._parse_resolv_conf(resolvconf)))
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.
this would not catch the case where the resulting resolv.conf has more settings than intended:
In [1]: set([1,2,3]) - set([1,2,3,4])
Out[1]: set()
what is the advantage for that approach? Given that the assertion will give a verbose error message, e.g.:
AssertionError: Items in the first set but not the second:
('nameserver', '::1')
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 advantage would be that you could write one "resolv.conf parsing function" and use it everywhere and that I like set operations. We can keep it as is though :) For the case you're mentioning you can just compare the sets if they're equal or if you want the extra elements, do an xor:
In [2]: set([1,2,3]) ^ set([1,2,3,4])
Out[2]: {4}
Anyway, as marked as optional you can also keep it as is.
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 implemented the resolv.conf parsing function, that totally makes sense, even to me ;)
I just don't get why I should do the set operation myself when the unittest framework is giving me nice output already when comparing the sets
4df8ec3
to
d694b74
Compare
for line in f.readlines(): | ||
if ' ' in line: | ||
keyword, value = line.strip().split(' ', 1) | ||
if keyword in ('search', 'options', | ||
'nameserver'): | ||
found_settings.add((keyword, value)) |
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 advantage would be that you could write one "resolv.conf parsing function" and use it everywhere and that I like set operations. We can keep it as is though :) For the case you're mentioning you can just compare the sets if they're equal or if you want the extra elements, do an xor:
In [2]: set([1,2,3]) ^ set([1,2,3,4])
Out[2]: {4}
Anyway, as marked as optional you can also keep it as is.
with open(resolvconf, 'rt') as f: | ||
for line in f.readlines(): | ||
if ' ' in line: | ||
keyword, value = line.strip().split(' ', 1) | ||
if keyword in ('search', 'options', 'nameserver'): | ||
found_settings.add((keyword, value)) |
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 this also be covered by _read_resolvconf()
?
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.
hmm. need to adapt _read_resolvconf for that, but is doable,
The test is only looking for the given three keywords and ignoring everything else in the file, so it would only fail if the setting for one of these keywords is not correct, making the test specific to that corner case.
If for example the code adds an additional keyword (because an additional linebreak is added by accident in a comment when the code is modified), now all tests that check the resolv.conf will fail, because a new keyword-value pair is found by the helper function that parses the file. This could make it unneccessarily hard for the developer to verify the root cause with 4 tests failing.
The parser has been updated and got its own test, so that should work in the same way as before, with a parameter to the parser function.
9d386f0
to
6170f65
Compare
Using the 'regular' /etc/resolv.conf inside the network namespaces prevents proper DNS resolution, as these nameservers usually are unreachable from within the namespaces. This change enables creation of a resolv.conf in each namespace. The new setting netns_resolvconf enables this feature, by default it is disabled. Default nameservers are 127.0.0.1 and ::1 if IPv6 is enabled, for search domains the networks dns_domain is used if set. These defaults can be overwritten via settings file. To skip setting nameservers, search domains or options in the generated file and not use the dynamic defaults, one can add the settings key in the configuration file but leave out any value, e.g.: netns_resolvconf = yes netns_resolvconf_search = netns_resolvconf_options = netns_resolvconf_nameservers = This would create an empty resolv.conf.
6170f65
to
ad82d7b
Compare
Using the 'regular' /etc/resolv.conf inside the network namespaces prevents proper DNS resolution, as these nameservers usually are unreachable from within the namespaces.
This change enables creation of a resolv.conf in each namespace.
The new setting netns_resolvconf enables this feature, by default its disabled.
Default nameservers are 127.0.0.1 and ::1 if IPv6 is enabled, for search domains the dns_domain is used if set.
These internal defaults can be overwritten via settings file.
To skip setting nameservers, search domains or options in the generated file and not use the dynamic defaults, one can add the settings key in the configuration file but leave out any value, e.g.:
netns_resolvconf = yes
netns_resolvconf_search =
netns_resolvconf_options =
netns_resolvconf_nameservers =
This would create an empty resolv.conf.