Skip to content

Commit

Permalink
issue #70 - improved legacy gateway xml cleanup (do not delet groups …
Browse files Browse the repository at this point in the history
…defined in xml but not in yaml)
  • Loading branch information
zerwes committed Jul 26, 2024
1 parent d9d8748 commit a2e194f
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 5 deletions.
5 changes: 2 additions & 3 deletions tasks/gateways.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,13 @@
delegate_to: localhost
community.general.xml:
path: "{{ local_config_path }}"
xpath: "/opnsense/gateways"
xpath: "/opnsense/gateways[not(node())]"
state: absent
pretty_print: true
when:
- opn_gateways is defined
- opn_gateways | length > 0
- opn_gateway_groups is defined
- opn_gateway_groups | length > 0
- opn_gateway_groups | default([]) | length == 0
- opn_gateways_remove_legacy_entry | default(true) | bool

# finisage
Expand Down
1 change: 0 additions & 1 deletion test/gateways-test1-expect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@
</gateway_item>
</Gateways>
</OPNsense>
<gateways/>
</opnsense>
1 change: 0 additions & 1 deletion test/gateways-test2-expect.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@
</gateway_item>
</Gateways>
</OPNsense>
<gateways/>
</opnsense>
28 changes: 28 additions & 0 deletions test/gateways-test3-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<OPNsense>
<Gateways version="1.0.0">
<gateway_item uuid="eb9d8a75-7d26-562d-8c0b-cde467eed23f">
<interface>opt6</interface>
<gateway>192.168.0.123</gateway>
<name>SIPGW</name>
<priority>255</priority>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<descr>SIP Gateway</descr>
</gateway_item>
</Gateways>
</OPNsense>
<gateways>
<gateway_group>
<name>GW_WAN</name>
<item>GW_WAN1|2</item>
<item>GW_WAN2|3</item>
<item>GW_FMP1_WAN|1</item>
<trigger>down</trigger>
<descr>WAN gateway group</descr>
</gateway_group>
</gateways>
</opnsense>
27 changes: 27 additions & 0 deletions test/gateways-test3.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0"?>
<opnsense>
<system>
</system>
<OPNsense>
<Gateways version="1.0.0"/>
</OPNsense>
<gateways>
<gateway_item>
<interface>opt6</interface>
<gateway>192.168.0.123</gateway>
<name>SIPGW</name>
<priority>255</priority>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<descr>SIP Gateway</descr>
</gateway_item>
<gateway_group>
<name>GW_WAN</name>
<item>GW_WAN1|2</item>
<item>GW_WAN2|3</item>
<item>GW_FMP1_WAN|1</item>
<trigger>down</trigger>
<descr>WAN gateway group</descr>
</gateway_group>
</gateways>
</opnsense>
20 changes: 20 additions & 0 deletions test/gateways-test3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

opn_gateways:
- interface: opt6
settings:
- key: gateway
value: 192.168.0.123
- key: name
value: SIPGW
- key: priority
value: '255'
- key: weight
value: '1'
- key: ipprotocol
value: inet
- key: descr
value: SIP Gateway


...
18 changes: 18 additions & 0 deletions test/gateways-test4-expect.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version='1.0' encoding='UTF-8'?>
<opnsense>
<system>
</system>
<OPNsense>
<Gateways version="1.0.0">
<gateway_item uuid="eb9d8a75-7d26-562d-8c0b-cde467eed23f">
<interface>opt6</interface>
<gateway>192.168.0.123</gateway>
<name>SIPGW</name>
<priority>255</priority>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<descr>SIP Gateway</descr>
</gateway_item>
</Gateways>
</OPNsense>
</opnsense>
19 changes: 19 additions & 0 deletions test/gateways-test4.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<opnsense>
<system>
</system>
<OPNsense>
<Gateways version="1.0.0"/>
</OPNsense>
<gateways>
<gateway_item>
<interface>opt6</interface>
<gateway>192.168.0.123</gateway>
<name>SIPGW</name>
<priority>255</priority>
<weight>1</weight>
<ipprotocol>inet</ipprotocol>
<descr>SIP Gateway</descr>
</gateway_item>
</gateways>
</opnsense>
20 changes: 20 additions & 0 deletions test/gateways-test4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---

opn_gateways:
- interface: opt6
settings:
- key: gateway
value: 192.168.0.123
- key: name
value: SIPGW
- key: priority
value: '255'
- key: weight
value: '1'
- key: ipprotocol
value: inet
- key: descr
value: SIP Gateway


...

0 comments on commit a2e194f

Please sign in to comment.