Skip to content

Commit

Permalink
CI fixes (#228) (#230)
Browse files Browse the repository at this point in the history
* switched to public common validation methods

* fixed / simplified regex matching

* added changelog fragment for {cnos,icx}_static_route modules fix

(cherry picked from commit 97c496f)

Co-authored-by: Deric Crago <[email protected]>
  • Loading branch information
patchback[bot] and dericcrago authored Mar 24, 2021
1 parent 75c5170 commit c13e5e0
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 23 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/228-static_route-devel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "{cnos,icx}_static_route modules - fix modules to work with ansible-core 2.11 (https://github.com/ansible-collections/community.network/pull/228)."
5 changes: 3 additions & 2 deletions plugins/modules/network/cnos/cnos_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
from copy import deepcopy
from re import findall
from ansible.module_utils.basic import AnsibleModule, missing_required_lib
from ansible.module_utils.common.validation import check_required_together
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import validate_ip_address
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import remove_default_spec
from ansible_collections.community.network.plugins.module_utils.network.cnos.cnos import get_config, load_config
Expand Down Expand Up @@ -218,10 +219,10 @@ def map_params_to_obj(module, required_together=None):
route[key] = module.params.get(key)

route = dict((k, v) for k, v in route.items() if v is not None)
module._check_required_together(required_together, route)
check_required_together(required_together, route)
obj.append(route)
else:
module._check_required_together(required_together, module.params)
check_required_together(required_together, module.params)
route = dict()
for key in keys:
if module.params.get(key) is not None:
Expand Down
5 changes: 3 additions & 2 deletions plugins/modules/network/icx/icx_static_route.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@

from ansible.module_utils._text import to_text
from ansible.module_utils.basic import AnsibleModule, env_fallback
from ansible.module_utils.common.validation import check_required_together
from ansible.module_utils.connection import ConnectionError
from ansible_collections.ansible.netcommon.plugins.module_utils.network.common.utils import remove_default_spec
from ansible_collections.community.network.plugins.module_utils.network.icx.icx import get_config, load_config
Expand Down Expand Up @@ -224,14 +225,14 @@ def map_params_to_obj(module, required_together=None):
if route.get(key) is None:
route[key] = module.params.get(key)

module._check_required_together(required_together, route)
check_required_together(required_together, route)

prefix, mask = prefix_length_parser(route['prefix'], route['mask'], module)
route.update({'prefix': prefix, 'mask': mask})

obj.append(route)
else:
module._check_required_together(required_together, module.params)
check_required_together(required_together, module.params)
prefix, mask = prefix_length_parser(module.params['prefix'], module.params['mask'], module)

obj.append({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,7 @@ def test_slxos_interface_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
'shawshank Supported parameters include: aggregate, '
'delay, description, enabled, mtu, name, neighbors, '
'rx_rate, speed, state, tx_rate',
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? '
'Supported parameters include: .+',
result['msg']
))
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,7 @@ def test_slxos_l2_interface_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
'shawshank Supported parameters include: access_vlan, aggregate, '
r'mode, name( \(interface\))?, native_vlan, state, '
'trunk_allowed_vlans, trunk_vlans',
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? '
'Supported parameters include: .+',
result['msg']
))
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ def test_slxos_l3_interface_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
'shawshank Supported parameters include: aggregate, ipv4, ipv6, '
'name, state',
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? '
'Supported parameters include: .+',
result['msg']
))
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ def test_slxos_linkagg_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.pyc|basic.py)\) module: '
'shawshank Supported parameters include: aggregate, group, '
'members, mode, purge, state',
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? '
'Supported parameters include: .+',
result['msg']
))
4 changes: 2 additions & 2 deletions tests/unit/plugins/modules/network/slxos/test_slxos_lldp.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_slxos_lldp_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
'shawshank Supported parameters include: state',
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? '
'Supported parameters include: .+',
result['msg']
), 'Output did not match. Got: %s' % result['msg'])
10 changes: 7 additions & 3 deletions tests/unit/plugins/modules/network/slxos/test_slxos_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,12 @@ def test_slxos_interface_invalid_argument(self, *args, **kwargs):
result = self.execute_module(failed=True)
self.assertEqual(result['failed'], True)
self.assertTrue(re.match(
r'Unsupported parameters for \((basic.py|basic.pyc)\) module: '
'shawshank Supported parameters include: aggregate, delay, '
'interfaces, name, purge, state, vlan_id',
'(?:'
# < ansible-core 2.11
r'Unsupported parameters for \(basic\.pyc?\) module: shawshank\.? Supported parameters include: .+'
'|'
# >= ansible-core 2.11
'one of the following is required: .+'
')',
result['msg']
), 'Result did not match expected output. Got: %s' % result['msg'])

0 comments on commit c13e5e0

Please sign in to comment.