Skip to content

Commit

Permalink
Fixes #236: Add missing parameters for the "ip firewall" subpaths and…
Browse files Browse the repository at this point in the history
… set the default value for the "disabled" parameter for most paths (#237)

* Fixes #236: Add missing parameters

The parameters "address-list", "address-list-timeout", and "realm" were
missing for some subpaths of "ip firewall" and are now added.
Additionally the default value of "False" for the "disabled" parameter
has been set so that an e.g. firewall rule, which was disabled
(disabled=True) is enabled (disabled=False) after removing the
"disabled" argument in the data.

Some more parameters can now be removed, e.g. "jump-target", "log", and "log-prefix",
which are not mandatory.

* Add missing changes for #236

Additionally fixed the PR id in the changelog fragment.

* Update changelogs/fragments/237-add-missing-ip-firewall-attributes.yml

Full stop added at the end of the changelog fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update changelogs/fragments/237-add-missing-ip-firewall-attributes.yml

Full stop added at the end of the changelog fragment

Co-authored-by: Felix Fontein <felix@fontein.de>

* Fix unit tests

---------

Co-authored-by: Johannes Münch <git@washiza.eu>
Co-authored-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
3 people authored Dec 3, 2023
1 parent 7de154e commit ad6faf2
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
minor_changes:
- api_info, api_modify - add missing parameters ``address-list``, ``address-list-timeout``, ``randomise-ports``, and ``realm`` to subpaths of the ``ip firewall`` path (https://github.com/ansible-collections/community.routeros/issues/236, https://github.com/ansible-collections/community.routeros/pull/237).
- api_info, api_modify - set the default value to ``false`` for the ``disabled`` parameter in some more paths where it can be seen in the documentation (https://github.com/ansible-collections/community.routeros/pull/237).
77 changes: 43 additions & 34 deletions plugins/module_utils/_api_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,7 @@ def join_path(path):
fields={
'name': KeyInfo(required=True),
'comment': KeyInfo(can_disable=True, remove_value=''),
'disabled': KeyInfo(can_disable=True),
'disabled': KeyInfo(default=False),
'fib': KeyInfo(),
},
)),
Expand Down Expand Up @@ -1007,7 +1007,7 @@ def join_path(path):
'client-to-client-forwarding': KeyInfo(can_disable=True),
'client-tx-limit': KeyInfo(can_disable=True),
'comment': KeyInfo(can_disable=True, remove_value=''),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'interface': KeyInfo(can_disable=True),
'mac-address': KeyInfo(can_disable=True),
'mac-address-mask': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -1941,6 +1941,8 @@ def join_path(path):
stratify_keys=('chain', ),
fields={
'action': KeyInfo(),
'address-list': KeyInfo(can_disable=True),
'address-list-timeout': KeyInfo(can_disable=True),
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'connection-bytes': KeyInfo(can_disable=True),
Expand All @@ -1951,7 +1953,7 @@ def join_path(path):
'connection-state': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand All @@ -1969,11 +1971,11 @@ def join_path(path):
'ingress-priority': KeyInfo(can_disable=True),
'ipsec-policy': KeyInfo(can_disable=True),
'ipv4-options': KeyInfo(can_disable=True),
'jump-target': KeyInfo(),
'jump-target': KeyInfo(can_disable=True),
'layer7-protocol': KeyInfo(can_disable=True),
'limit': KeyInfo(can_disable=True),
'log': KeyInfo(),
'log-prefix': KeyInfo(),
'log': KeyInfo(can_disable=True),
'log-prefix': KeyInfo(can_disable=True),
'nth': KeyInfo(can_disable=True),
'out-bridge-port': KeyInfo(can_disable=True),
'out-bridge-port-list': KeyInfo(can_disable=True),
Expand All @@ -1988,7 +1990,8 @@ def join_path(path):
'protocol': KeyInfo(can_disable=True),
'psd': KeyInfo(can_disable=True),
'random': KeyInfo(can_disable=True),
'reject-with': KeyInfo(),
'realm': KeyInfo(can_disable=True),
'reject-with': KeyInfo(can_disable=True),
'routing-mark': KeyInfo(can_disable=True),
'routing-table': KeyInfo(can_disable=True),
'src-address': KeyInfo(can_disable=True),
Expand All @@ -2010,6 +2013,8 @@ def join_path(path):
stratify_keys=('chain', ),
fields={
'action': KeyInfo(),
'address-list': KeyInfo(can_disable=True),
'address-list-timeout': KeyInfo(can_disable=True),
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'connection-bytes': KeyInfo(can_disable=True),
Expand All @@ -2020,7 +2025,7 @@ def join_path(path):
'connection-state': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand All @@ -2037,11 +2042,11 @@ def join_path(path):
'ingress-priority': KeyInfo(can_disable=True),
'ipsec-policy': KeyInfo(can_disable=True),
'ipv4-options': KeyInfo(can_disable=True),
'jump-target': KeyInfo(),
'jump-target': KeyInfo(can_disable=True),
'layer7-protocol': KeyInfo(can_disable=True),
'limit': KeyInfo(can_disable=True),
'log': KeyInfo(),
'log-prefix': KeyInfo(),
'log': KeyInfo(can_disable=True),
'log-prefix': KeyInfo(can_disable=True),
'new-connection-mark': KeyInfo(can_disable=True),
'new-dscp': KeyInfo(can_disable=True),
'new-mss': KeyInfo(can_disable=True),
Expand All @@ -2064,6 +2069,7 @@ def join_path(path):
'protocol': KeyInfo(can_disable=True),
'psd': KeyInfo(can_disable=True),
'random': KeyInfo(can_disable=True),
'realm': KeyInfo(can_disable=True),
'route-dst': KeyInfo(can_disable=True),
'routing-mark': KeyInfo(can_disable=True),
'routing-table': KeyInfo(can_disable=True),
Expand All @@ -2089,8 +2095,8 @@ def join_path(path):
stratify_keys=('chain', ),
fields={
'action': KeyInfo(),
'address-list': KeyInfo(),
'address-list-timeout': KeyInfo(),
'address-list': KeyInfo(can_disable=True),
'address-list-timeout': KeyInfo(can_disable=True),
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'connection-bytes': KeyInfo(can_disable=True),
Expand All @@ -2099,7 +2105,7 @@ def join_path(path):
'connection-rate': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand All @@ -2116,11 +2122,11 @@ def join_path(path):
'ingress-priority': KeyInfo(can_disable=True),
'ipsec-policy': KeyInfo(can_disable=True),
'ipv4-options': KeyInfo(can_disable=True),
'jump-target': KeyInfo(),
'jump-target': KeyInfo(can_disable=True),
'layer7-protocol': KeyInfo(can_disable=True),
'limit': KeyInfo(can_disable=True),
'log': KeyInfo(),
'log-prefix': KeyInfo(),
'log': KeyInfo(can_disable=True),
'log-prefix': KeyInfo(can_disable=True),
'nth': KeyInfo(can_disable=True),
'out-bridge-port': KeyInfo(can_disable=True),
'out-bridge-port-list': KeyInfo(can_disable=True),
Expand All @@ -2134,9 +2140,10 @@ def join_path(path):
'protocol': KeyInfo(can_disable=True),
'psd': KeyInfo(can_disable=True),
'random': KeyInfo(can_disable=True),
'randomise-ports': KeyInfo(can_disable=True),
'realm': KeyInfo(can_disable=True),
'routing-mark': KeyInfo(can_disable=True),
'same-not-by-dst': KeyInfo(),
'same-not-by-dst': KeyInfo(can_disable=True),
'src-address': KeyInfo(can_disable=True),
'src-address-list': KeyInfo(can_disable=True),
'src-address-type': KeyInfo(can_disable=True),
Expand All @@ -2157,12 +2164,12 @@ def join_path(path):
stratify_keys=('chain',),
fields={
'action': KeyInfo(),
'address-list': KeyInfo(),
'address-list-timeout': KeyInfo(),
'address-list': KeyInfo(can_disable=True),
'address-list-timeout': KeyInfo(can_disable=True),
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand All @@ -2179,10 +2186,10 @@ def join_path(path):
'ingress-priority': KeyInfo(can_disable=True),
'ipsec-policy': KeyInfo(can_disable=True),
'ipv4-options': KeyInfo(can_disable=True),
'jump-target': KeyInfo(),
'jump-target': KeyInfo(can_disable=True),
'limit': KeyInfo(can_disable=True),
'log': KeyInfo(),
'log-prefix': KeyInfo(),
'log': KeyInfo(can_disable=True),
'log-prefix': KeyInfo(can_disable=True),
'nth': KeyInfo(can_disable=True),
'out-bridge-port': KeyInfo(can_disable=True),
'out-bridge-port-list': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -2503,6 +2510,8 @@ def join_path(path):
stratify_keys=('chain', ),
fields={
'action': KeyInfo(),
'address-list': KeyInfo(can_disable=True),
'address-list-timeout': KeyInfo(can_disable=True),
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'connection-bytes': KeyInfo(can_disable=True),
Expand All @@ -2512,7 +2521,7 @@ def join_path(path):
'connection-state': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand All @@ -2528,10 +2537,10 @@ def join_path(path):
'in-interface-list': KeyInfo(can_disable=True),
'ingress-priority': KeyInfo(can_disable=True),
'ipsec-policy': KeyInfo(can_disable=True),
'jump-target': KeyInfo(),
'jump-target': KeyInfo(can_disable=True),
'limit': KeyInfo(can_disable=True),
'log': KeyInfo(),
'log-prefix': KeyInfo(),
'log': KeyInfo(can_disable=False),
'log-prefix': KeyInfo(can_disable=False),
'nth': KeyInfo(can_disable=True),
'out-bridge-port': KeyInfo(can_disable=True),
'out-bridge-port-list': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -2573,7 +2582,7 @@ def join_path(path):
'connection-state': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -2647,7 +2656,7 @@ def join_path(path):
'connection-state': KeyInfo(can_disable=True),
'connection-type': KeyInfo(can_disable=True),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -2703,7 +2712,7 @@ def join_path(path):
'chain': KeyInfo(),
'comment': KeyInfo(can_disable=True, remove_value=''),
'content': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'dscp': KeyInfo(can_disable=True),
'dst-address': KeyInfo(can_disable=True),
'dst-address-list': KeyInfo(can_disable=True),
Expand Down Expand Up @@ -2796,7 +2805,7 @@ def join_path(path):
'blackhole': KeyInfo(can_disable=True),
'check-gateway': KeyInfo(can_disable=True),
'comment': KeyInfo(can_disable=True, remove_value=''),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'distance': KeyInfo(default=1),
'dst-address': KeyInfo(),
'gateway': KeyInfo(),
Expand Down Expand Up @@ -3581,7 +3590,7 @@ def join_path(path):
'cluster-id': KeyInfo(),
'comment': KeyInfo(),
'connect': KeyInfo(default=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'hold-time': KeyInfo(),
'input.accept-communities': KeyInfo(),
'input.accept-ext-communities': KeyInfo(),
Expand Down Expand Up @@ -3640,7 +3649,7 @@ def join_path(path):
'client-to-client-reflection': KeyInfo(),
'cluster-id': KeyInfo(can_disable=True),
'confederation': KeyInfo(can_disable=True),
'disabled': KeyInfo(),
'disabled': KeyInfo(default=False),
'ignore-as-path-len': KeyInfo(),
'name': KeyInfo(),
'out-filter': KeyInfo(),
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/plugins/modules/test_api_find_and_modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,24 +619,28 @@ def test_change_remove_generic(self):
'chain': 'input',
'comment': 'defconf',
'protocol': 'icmp',
'disabled': False,
},
{
'.id': '*3',
'action': 'accept',
'chain': 'input',
'comment': 'defconf',
'disabled': False,
},
{
'.id': '*4',
'action': 'accept',
'chain': 'input',
'comment': 'defconf',
'disabled': False,
},
{
'.id': '*7',
'action': 'drop',
'chain': 'input',
'comment': 'defconf',
'disabled': False,
'in-interface': 'wan',
},
{
Expand All @@ -645,20 +649,23 @@ def test_change_remove_generic(self):
'chain': 'forward',
'comment': 'defconf',
'connection-state': 'established',
'disabled': False,
},
{
'.id': '*9',
'action': 'accept',
'chain': 'forward',
'comment': 'defconf',
'connection-state': 'related',
'disabled': False,
},
{
'.id': '*A',
'action': 'drop',
'chain': 'forward',
'comment': 'defconf',
'connection-status': 'invalid',
'disabled': False,
},
])
self.assertEqual(result['match_count'], 3)
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/plugins/modules/test_api_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def test_disabled_exclamation(self, mock_compose_api_path):
'chain': 'input',
'in-interface-list': 'LAN',
'!action': None,
'!address-list': None,
'!address-list-timeout': None,
'!comment': None,
'!connection-bytes': None,
'!connection-limit': None,
Expand Down Expand Up @@ -243,6 +245,7 @@ def test_disabled_exclamation(self, mock_compose_api_path):
'!protocol': None,
'!psd': None,
'!random': None,
'!realm': None,
'!reject-with': None,
'!routing-mark': None,
'!routing-table': None,
Expand Down Expand Up @@ -284,6 +287,8 @@ def test_disabled_null_value(self, mock_compose_api_path):
'chain': 'input',
'in-interface-list': 'LAN',
'action': None,
'address-list': None,
'address-list-timeout': None,
'comment': None,
'connection-bytes': None,
'connection-limit': None,
Expand Down Expand Up @@ -329,6 +334,7 @@ def test_disabled_null_value(self, mock_compose_api_path):
'protocol': None,
'psd': None,
'random': None,
'realm': None,
'reject-with': None,
'routing-mark': None,
'routing-table': None,
Expand Down

0 comments on commit ad6faf2

Please sign in to comment.