-
Notifications
You must be signed in to change notification settings - Fork 57
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(subnet.jinja): multiple ranges allowed in pool as per docs #59
base: master
Are you sure you want to change the base?
Conversation
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.
@waynegemmell Thanks for the PR. Still some work needed here.
salt-lint
violation needs to be resolved.
[201] Trailing whitespace
dhcpd/files/subnet.jinja:82
{%- for range_def in pool.range %}
-
Test(s) will need to be updated, since all the instances are failing.
-
It would be helpful if you could link to the upstream docs, showing how this is supposed to be defined.
Pools should allow multiple ranges. It's in the docs but doesn't work in practice.
|
@waynegemmell Might not be necessary, see below.
I meant the upstream documentation. I've searched for it myself: https://kb.isc.org/v1/docs/isc-dhcp-44-manual-pages-dhcpdconf#examples ...
subnet 204.254.239.0 netmask 255.255.255.224 {
subnet-specific parameters...
range 204.254.239.10 204.254.239.30;
}
subnet 204.254.239.32 netmask 255.255.255.224 {
subnet-specific parameters...
range 204.254.239.42 204.254.239.62;
}
subnet 204.254.239.64 netmask 255.255.255.224 {
subnet-specific parameters...
range 204.254.239.74 204.254.239.94;
}
... So it looks like the formula is already working as expected: dhcpd-formula/test/integration/default/controls/config_spec.rb Lines 187 to 194 in 7ba856e
Unless you see something I've missed. Other references: |
For one thing, I have that in production.
So at least one, which to me implies more than one . I do this in practice and it works fine. |
@waynegemmell Perhaps this is easier to understand with a comparison. Taking the block from Lines 44 to 54 in 7ba856e
Before this PR, this results in: subnet 10.152.187.0 netmask 255.255.255.0 {
pool {
failover peer "dhcp-failover";
range 10.152.187.1 10.152.187.254;
}
} After this PR, we get: subnet 10.152.187.0 netmask 255.255.255.0 {
pool {
failover peer "dhcp-failover";
range 10.152.187.1;
range 10.152.187.254;
}
} Taking what you've quoted above: range [ dynamic-bootp ] low-address [ high-address]; Then we can see that the range isn't being set correctly, if this PR was merged. However, there is something that still needs to be fixed. The current implementation does not allow for a range to be set using only a subnet 10.152.187.0 netmask 255.255.255.0 {
pool {
failover peer "dhcp-failover";
range 10.152.187.1;
}
} So we could adjust this PR in order to provide that functionality, depending on how the data is provided in the pillar/config. There are two obvious ways to deal with this. Allow a single entry ( pools:
- failover_peer: dhcp-failover
range:
- 10.152.187.1 Or avoid using a list when there's only a pools:
- failover_peer: dhcp-failover
range: 10.152.187.1 I've seen the second method used in other formulas and it seems more explicit (string vs. list). |
I definitely think the string is the way to go with this, mostly to cater for all the possible variation that you mentioned. TBH I implemented it as a string on my side and that's why I was quite certain that it worked fine. My only worry with changing this to a string is that it's a breaking change. |
Having it in a list really seems like the hard way to do it. |
@waynegemmell This method was introduced ~8 years ago in #4. In fact, looking at 9115b05, you can see that the intent was to replace the string-based method with the list-based method.
As I mentioned above, there's another way that's used in other formulas. Allow the end user to supply the data as a string or a list; process it accordingly using an Try out this block: {%- if 'range' in pool %}
{%- if pool.range | is_list %}
range {{ pool.range[0] }} {{ pool.range[1] }};
{%- else %}
range {{ pool.range }};
{%- endif %}
{%- endif %} Then you can supply the data in any of the following forms. Existing method using a list: pools:
- failover_peer: dhcp-failover
range:
- 10.152.187.1
- 10.152.187.254 The same result by using a string: pools:
- failover_peer: dhcp-failover
range: 10.152.187.1 10.152.187.254 Using a string to provide only a pools:
- failover_peer: dhcp-failover
range: 10.152.187.1 If this works out for you, we can finalise all the updates required to |
@waynegemmell If the method above works, for consistency, we should allow list/string configuration for all the places that the Lines 52 to 54 in 7ba856e
Lines 59 to 61 in 7ba856e
Lines 72 to 74 in 7ba856e
Lines 81 to 83 in 7ba856e
Lines 152 to 161 in 7ba856e
|
Sounds good. Can we add a ranges variable as well? It would have a list of string ranges so I can still achieve what I set out to achieve. |
@waynegemmell Would you mind providing an example of what you would like as the end (rendered) result? Based on the following snippet: subnet 10.152.187.0 netmask 255.255.255.0 {
pool {
failover peer "dhcp-failover";
range 10.152.187.1 10.152.187.254;
}
} Then we can figure out how the data should be provided and processed. |
It goes something like this subnet 10.152.0.0 netmask 255.255.0.0 { |
@waynegemmell Thanks for that example. I've also found this in the docs:
Reverse compatibility and multiple address ranges is now a step too far for any simple solution. Other than introducing TOFS, I reckon the cleanest solution is something like this:
I've got more to share but I'm short on time right now. Feel free to share any feedback that you have. |
@waynegemmell I've put something together using macros for |
Maybe just make a branch your side? I'll have a look asap. Slammed today. Hopefully tomorrow I can get back onto this. |
@waynegemmell This is the branch (just one commit added): This covers all the possible I haven't updated the Firstly, the configuration examples from the comment above are all possible:
The interesting addition is the All the examples below are based on this block: Lines 59 to 61 in 7ba856e
Examples using listsWhere the basic range:
- 10.254.239.10
- 10.254.239.20 This is identical using ranges:
-
- 10.254.239.10
- 10.254.239.20 And for multiple ranges:
-
- 10.254.239.10
- 10.254.239.14
-
- 10.254.239.15
- 10.254.239.20 Examples using stringsWhere the basic range: 10.254.239.10 10.254.239.20 This is identical using ranges:
- 10.254.239.10 10.254.239.20 And for multiple ranges:
- 10.254.239.10 10.254.239.14
- 10.254.239.15 10.254.239.20 |
Hi, it looks good. For some reason the config check is breaking. If I run the check manually it's fine and if I remove the check everything is fine. I'll have another look Monday. Thanks for the effort. |
@waynegemmell Did you manage to have another look? The only config check failures I faced were when I mistakenly tested ranges that were outside the relevant |
It works well. Thanks. My issue was a slight config issue which I have corrected. Apologies. |
PR progress checklist (to be filled in by reviewers)
What type of PR is this?
Primary type
[build]
Changes related to the build system[chore]
Changes to the build process or auxiliary tools and libraries such as documentation generation[ci]
Changes to the continuous integration configuration[feat]
A new feature[fix]
A bug fix[perf]
A code change that improves performance[refactor]
A code change that neither fixes a bug nor adds a feature[revert]
A change used to revert a previous commit[style]
Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)Secondary type
[docs]
Documentation changes[test]
Adding missing or correcting existing testsDoes this PR introduce a
BREAKING CHANGE
?No.
Related issues and/or pull requests
None
Describe the changes you're proposing
Pools should allow multiple ranges. It's in the docs but doesn't work in practice. I've just added a for loop to fix that.
Pillar / config required to test the proposed changes
From pillar.example
Debug log showing how the proposed changes work
Documentation checklist
README
(e.g.Available states
).pillar.example
.Testing checklist
state_top
).Additional context