Skip to content
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 route changed-state if hyphen in gateway-name (fix #99) #115

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions plugins/module_utils/main/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def check(self) -> None:
self._base_check()

def _simplify_existing(self, route: dict) -> dict:
# makes processing easier
simple = simplify_translate(
existing=route,
typing=self.FIELDS_TYPING,
translate=self.FIELDS_TRANSLATE,
bool_invert=self.FIELDS_BOOL_INVERT,
)
simple['gateway'] = simple['gateway'].rsplit('-', 1)[0].strip()
if simple['gateway'].find(' - ') != -1:
simple['gateway'] = simple['gateway'].rsplit('-', 1)[0].strip()

return simple
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ The gateway tests will not work correctly if the LAN network mismatches.

You can provide your GW IPs via env-vars: `TEST_FIREWALL_GW1` and `TEST_FIREWALL_GW2`

The `route` module will expect the gateways `LAN_GW` and `TEST-GW` to exist.

### Rule interface groups

The gateway tests will not work correctly if the LAN interface mismatches.
Expand Down
4 changes: 2 additions & 2 deletions tests/gateway.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
register: opn1
failed_when: >
'data' not in opn1 or
opn1.data | length != 3
opn1.data | length != 4
when: not ansible_check_mode

- name: Cleanup
Expand All @@ -105,4 +105,4 @@
register: opn2
failed_when: >
'data' not in opn2 or
opn2.data | length != 1
opn2.data | length != 2
19 changes: 15 additions & 4 deletions tests/route.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,35 @@
ansibleguy.opnsense.route:
description: 'ANSIBLE_TEST_2'
network: '4.4.4.2/32'
gateway: 'LAN_GW'
gateway: 'TEST-GW'
register: opn5
failed_when: >
opn5.failed or
not opn5.changed

- name: Adding 2 - nothing changed with match-fields network & gateway
- name: Adding 2 - nothing changed
ansibleguy.opnsense.route:
description: 'ANSIBLE_TEST_2'
network: '4.4.4.2/32'
gateway: 'LAN_GW'
match_fields: ['network', 'gateway']
gateway: 'TEST-GW'
register: opn9
failed_when: >
opn9.failed or
opn9.changed
when: not ansible_check_mode

- name: Adding 2 - nothing changed with match-fields network & gateway
ansibleguy.opnsense.route:
description: 'ANSIBLE_TEST_2'
network: '4.4.4.2/32'
gateway: 'TEST-GW'
match_fields: ['network', 'gateway']
register: opn10
failed_when: >
opn10.failed or
opn10.changed
when: not ansible_check_mode

- name: Disabling 1
ansibleguy.opnsense.route:
description: 'ANSIBLE_TEST_1'
Expand Down
Loading