Skip to content

Conversation

@richm
Copy link
Contributor

@richm richm commented Feb 10, 2026

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:

  • Correct tunnel configuration lookup to use the actual host key instead of the hostname field when resolving subnets.

Tests:

  • Extend subnet-to-subnet VPN tests to cover multiple hosts and validate hostname/ID handling in tunnel definitions.

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>
@richm richm requested a review from ueno as a code owner February 10, 2026 22:52
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 10, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts 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 structure

erDiagram
  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
Loading

File-Level Changes

Change Details Files
Template now uses the correct dict key when resolving host configuration for subnets in host-to-host tunnels.
  • Replace tunnel.hosts[host] with tunnel.hosts[thishost] in the conditional check for subnets.
  • Update the for-loop to iterate over tunnel.hosts[thishost].subnets instead of tunnel.hosts[host].subnets.
templates/libreswan-host-to-host.conf.j2
Subnet-to-subnet test inventory expanded to cover two hosts plus an extra main host entry with hostnames, ids, and subnets to validate the template fix.
  • Increase __vpn_num_hosts from 1 to 2 in test vars.
  • Add mainhost.local with hostname and leftid but no subnets.
  • Add host01.local and host02.local with hostnames, rightid values, and subnets to exercise the new host lookup behavior.
tests/tests_subnet_to_subnet.yml

Possibly linked issues

  • #unknown: PR updates libreswan-host-to-host template to index tunnel.hosts by thishost, fixing the reported dict-attribute error.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@richm
Copy link
Contributor Author

richm commented Feb 10, 2026

fixes #230

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • 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.
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.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@richm
Copy link
Contributor Author

richm commented Feb 10, 2026

[citest]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant