fix: use host for dict key in tunnel - hostname is not a dict key - #236
Merged
richm merged 1 commit intoFeb 11, 2026
Merged
Conversation
Cause: The template code was using the hostname field as a dict key into the tunnel configuration when a hostname was given in the configuration. By default, the host field is used which works correctly. Consequence: The host field is the key, not the hostname field. This caused an error to be reported that the hostname value is not a attribute of the tunnel dict. Fix: Use the correct host field value as the tunnel dict key even if the hostname field is given. Result: The tunnel is configured correctly with no errors. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's guide (collapsed on small PRs)Reviewer's GuideAdjusts the libreswan host-to-host tunnel Jinja2 template to consistently use the dictionary key (host) for lookups instead of the hostname value, and extends the subnet-to-subnet test to cover multiple hosts with hostnames and subnets. ER diagram for tunnel and hosts configuration structureerDiagram
TUNNEL {
string name
string host
string hostname
}
HOST_ENTRY {
string host_key
string hostname
string subnets_list
}
SUBNET {
string cidr
}
TUNNEL ||--o{ HOST_ENTRY : has_hosts
HOST_ENTRY ||--o{ SUBNET : has_subnets
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
Author
|
fixes #230 |
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- In
libreswan-host-to-host.conf.j2,tunnel.hosts[thishost]is now used only forsubnetswhile other lookups still usehost; consider standardizing on a single key variable to avoid inconsistent behavior whenhostandhostnamediffer. - The change of
__vpn_num_hostsfrom 1 to 2 intests_subnet_to_subnet.ymlhappens alongside adding three hosts (mainhost.local,host01.local,host02.local); double-check that this count still reflects the intended semantics of the variable to avoid future confusion.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `libreswan-host-to-host.conf.j2`, `tunnel.hosts[thishost]` is now used only for `subnets` while other lookups still use `host`; consider standardizing on a single key variable to avoid inconsistent behavior when `host` and `hostname` differ.
- The change of `__vpn_num_hosts` from 1 to 2 in `tests_subnet_to_subnet.yml` happens alongside adding three hosts (`mainhost.local`, `host01.local`, `host02.local`); double-check that this count still reflects the intended semantics of the variable to avoid future confusion.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Contributor
Author
|
[citest] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause: The template code was using the hostname field as a dict key into the tunnel configuration
when a hostname was given in the configuration. By default, the host field is used which works
correctly.
Consequence: The host field is the key, not the hostname field. This caused an error to be reported
that the hostname value is not a attribute of the tunnel dict.
Fix: Use the correct host field value as the tunnel dict key even if the hostname field is given.
Result: The tunnel is configured correctly with no errors.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Fix tunnel template to use the correct host key when looking up host configuration and expand subnet-to-subnet test coverage to multiple hosts.
Bug Fixes:
Tests: