Skip to content

[fix] Use context variables in Vpn.auto_client for OpenVPN backend#1227

Merged
nemesifier merged 1 commit intomasterfrom
fix-vpn-auto-client
Feb 24, 2026
Merged

[fix] Use context variables in Vpn.auto_client for OpenVPN backend#1227
nemesifier merged 1 commit intomasterfrom
fix-vpn-auto-client

Conversation

@pandafy
Copy link
Copy Markdown
Member

@pandafy pandafy commented Feb 17, 2026

Checklist

  • I have read the OpenWISP Contributing Guidelines.
  • I have manually tested the changes proposed in this pull request.
  • N/A I have written new test cases for new code and/or updated existing tests for changes to existing code.
  • N/A I have updated the documentation.

Description of Changes

Bug:

The Vpn.auto_client method was incorrectly using the Vpn.host field when generating the client configuration for the OpenVPN backend.

This resulted in the remote directive being hardcoded in the Template.config, instead of being rendered from the provided context variables.

Fix:

The Vpn.auto_client method has been updated to use the correct context-based values.

Bug:

The `Vpn.auto_client` method was incorrectly using the Vpn.host field
when generating the client configuration for the OpenVPN backend.

This resulted in the `remote` directive being hardcoded in the
`Template.config`, instead of being rendered from the provided
context variables.

Fix:

The `Vpn.auto_client` method has been updated to use the correct
context-based values.
@pandafy pandafy self-assigned this Feb 17, 2026
@pandafy pandafy moved this from To do (general) to Needs review in OpenWISP Contributor's Board Feb 17, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 17, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 012a094 and 8ee0c8e.

📒 Files selected for processing (2)
  • openwisp_controller/config/base/vpn.py
  • openwisp_controller/config/tests/test_vpn.py
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-01-15T15:05:49.557Z
Learnt from: DragnEmperor
Repo: openwisp/openwisp-controller PR: 1175
File: openwisp_controller/config/management/commands/clear_last_ip.py:38-42
Timestamp: 2026-01-15T15:05:49.557Z
Learning: In Django projects, when using select_related() to traverse relations (for example, select_related("organization__config_settings")), the traversed relation must not be deferred. If you also use .only() in the same query, include the relation name or FK field (e.g., "organization" or "organization_id") in the .only() list to avoid the error "Field X cannot be both deferred and traversed using select_related at the same time." Apply this guideline to Django code in openwisp_controller/config/management/commands/clear_last_ip.py and similar modules by ensuring any select_related with an accompanying only() includes the related field names to prevent deferred/traversed conflicts.

Applied to files:

  • openwisp_controller/config/tests/test_vpn.py
  • openwisp_controller/config/base/vpn.py
📚 Learning: 2026-01-15T15:07:17.354Z
Learnt from: DragnEmperor
Repo: openwisp/openwisp-controller PR: 1175
File: openwisp_controller/geo/estimated_location/tests/tests.py:172-175
Timestamp: 2026-01-15T15:07:17.354Z
Learning: In this repository, flake8 enforces E501 (line too long) via setup.cfg (max-line-length = 88) while ruff ignores E501 via ruff.toml. Therefore, use '# noqa: E501' on lines that intentionally exceed 88 characters to satisfy flake8 without affecting ruff checks. This applies to Python files across the project (any .py) and is relevant for tests as well. Use sparingly and only where breaking lines is not feasible without hurting readability or functionality.

Applied to files:

  • openwisp_controller/config/tests/test_vpn.py
  • openwisp_controller/config/base/vpn.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Python==3.11 | django~=4.2.0
  • GitHub Check: Python==3.12 | django~=5.2.0
  • GitHub Check: Python==3.11 | django~=5.1.0
  • GitHub Check: Python==3.13 | django~=5.2.0
  • GitHub Check: Python==3.13 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=5.1.0
  • GitHub Check: Python==3.10 | django~=4.2.0
  • GitHub Check: Python==3.12 | django~=5.1.0
  • GitHub Check: Python==3.11 | django~=5.2.0
  • GitHub Check: Python==3.12 | django~=4.2.0
🔇 Additional comments (3)
openwisp_controller/config/base/vpn.py (1)

621-654: LGTM! Correct fix for using context variables in OpenVPN auto_client.

The pop("vpn_host", self.host) correctly extracts the wrapped context variable (e.g., {{vpn_host_<hex>}}) and passes it as host to backend.auto_client, ensuring the remote directive is rendered from context rather than hardcoded. The pop also properly removes vpn_host from context_keys to avoid passing an unsupported kwarg.

openwisp_controller/config/tests/test_vpn.py (2)

193-222: LGTM! Tests correctly updated to mirror the production code change.

The test now constructs the control value using context_keys.pop("vpn_host") as the host argument, matching the new behavior in auto_client where host is derived from context variables rather than vpn.host directly.


224-245: LGTM!

Consistent with the test_auto_client update above.


Walkthrough

The change modifies the AbstractVpn.auto_client method to derive the host argument from context_keys (specifically the vpn_host key, defaulting to self.host) instead of directly using self.host when invoking the backend's auto_client. The corresponding tests are updated to reflect this new host extraction pattern.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: using context variables in Vpn.auto_client method for OpenVPN backend, which aligns with the changeset.
Description check ✅ Passed The description includes key sections (checklist completion, description of bug and fix) but lacks reference to an existing issue and test case details.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-vpn-auto-client

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pandafy
Copy link
Copy Markdown
Member Author

pandafy commented Feb 17, 2026

@nemesifier IMO, this needs to be backported as well.

@github-project-automation github-project-automation Bot moved this from Needs review to In progress in OpenWISP Contributor's Board Feb 17, 2026
@coveralls
Copy link
Copy Markdown

Coverage Status

coverage: 98.636% (+0.03%) from 98.607%
when pulling 8ee0c8e on fix-vpn-auto-client
into 012a094 on master.

@nemesifier nemesifier merged commit dbf1a05 into master Feb 24, 2026
21 checks passed
@nemesifier nemesifier deleted the fix-vpn-auto-client branch February 24, 2026 16:34
@github-project-automation github-project-automation Bot moved this from In progress to Done in OpenWISP Contributor's Board Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants