Skip to content

Commit

Permalink
Interface description values such as 5j evaluated as complex, cast to…
Browse files Browse the repository at this point in the history
… string (#1017)

* Values such as 5j return as complex, cast to string

* update changes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* lint

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove comment

* space

---------

Co-authored-by: Sagar Paul <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 27, 2024
1 parent cd326fe commit d41e3f4
Show file tree
Hide file tree
Showing 8 changed files with 210 additions and 64 deletions.
7 changes: 7 additions & 0 deletions changelogs/fragments/json_serializable_issue.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
bugfixes:
- ios_interfaces - description attribute, evalutated as complex object casted to string.
- ios_prefix_lists - description attribute, evalutated as complex object casted to string.
- ios_route_maps - description attribute, evalutated as complex object casted to string.
- ios_bgp_address_family - description attribute, evalutated as complex object casted to string.
- ios_bgp_global - description attribute, evalutated as complex object casted to string.
210 changes: 163 additions & 47 deletions plugins/module_utils/network/ios/rm_templates/bgp_address_family.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions plugins/module_utils/network/ios/rm_templates/bgp_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def __init__(self, lines=None, module=None):
re.VERBOSE,
),
"setval": "description {{ route_server_context.description }}",
"result": {"route_server_context": {"description": "{{ description }}"}},
"result": {"route_server_context": {"description": "'{{ description }}'"}},
},
{
"name": "synchronization",
Expand Down Expand Up @@ -1482,7 +1482,7 @@ def __init__(self, lines=None, module=None):
"neighbors": {
"{{ neighbor_address }}": {
"neighbor_address": "{{ neighbor_address }}",
"description": "{{ description }}",
"description": "'{{ description }}'",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def __init__(self, lines=None, module=None):
"setval": "description {{ description }}",
"result": {
'{{ name }}': {
'description': '{{ description }}',
'description': "'{{ description }}'",
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def __init__(self, lines=None):
"{{ afi + name }}": {
"name": "{{ name }}",
"afi": "{{ 'ipv4' if afi is defined and afi=='ip' else 'ipv6' }}",
"description": "{{ description }}",
"description": "'{{ description }}'",
},
},
},
Expand Down
43 changes: 33 additions & 10 deletions plugins/module_utils/network/ios/rm_templates/route_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ def _tmplt_route_map_match(config_data):
cmd += " best {best}".format(**config_data["match"]["additional_paths"])
if config_data["match"]["additional_paths"].get("best_range"):
cmd += " best-range"
if config_data["match"]["additional_paths"]["best_range"].get("lower_limit"):
if config_data["match"]["additional_paths"]["best_range"].get(
"lower_limit",
):
cmd += " lower-limit {lower_limit}".format(
**config_data["match"]["additional_paths"]["best_range"],
)
if config_data["match"]["additional_paths"]["best_range"].get("upper_limit"):
if config_data["match"]["additional_paths"]["best_range"].get(
"upper_limit",
):
cmd += " upper-limit {upper_limit}".format(
**config_data["match"]["additional_paths"]["best_range"],
)
Expand Down Expand Up @@ -231,7 +235,10 @@ def construct_cmd_from_list(cmd, config):
config_data["match"]["ip"]["address"]["prefix_lists"],
)
elif config_data["match"]["ip"]["address"].get("acls"):
cmd = construct_cmd_from_list(cmd, config_data["match"]["ip"]["address"]["acls"])
cmd = construct_cmd_from_list(
cmd,
config_data["match"]["ip"]["address"]["acls"],
)
if config_data["match"]["ip"].get("flowspec"):
cmd += " flowspec"
if config_data["match"]["ip"]["flowspec"].get("dest_pfx"):
Expand All @@ -245,7 +252,10 @@ def construct_cmd_from_list(cmd, config):
config_data["match"]["ip"]["flowspec"]["prefix_lists"],
)
elif config_data["match"]["ip"]["flowspec"].get("acls"):
cmd = construct_cmd_from_list(cmd, config_data["match"]["ip"]["flowspec"]["acls"])
cmd = construct_cmd_from_list(
cmd,
config_data["match"]["ip"]["flowspec"]["acls"],
)
if config_data["match"]["ip"].get("next_hop"):
cmd += " next-hop"
if config_data["match"]["ip"]["next_hop"].get("prefix_lists"):
Expand All @@ -255,7 +265,10 @@ def construct_cmd_from_list(cmd, config):
config_data["match"]["ip"]["next_hop"]["prefix_lists"],
)
elif config_data["match"]["ip"]["next_hop"].get("acls"):
cmd = construct_cmd_from_list(cmd, config_data["match"]["ip"]["next_hop"]["acls"])
cmd = construct_cmd_from_list(
cmd,
config_data["match"]["ip"]["next_hop"]["acls"],
)
if config_data["match"]["ip"].get("redistribution_source"):
cmd += " redistribution-source"
if config_data["match"]["ip"]["redistribution_source"].get("prefix_lists"):
Expand Down Expand Up @@ -411,15 +424,19 @@ def _tmplt_route_map_set(config_data):
cmd += " additive"
command.append(cmd)
if set["extcommunity"].get("soo"):
command.append("set extcommunity soo {soo}".format(**set["extcommunity"]))
command.append(
"set extcommunity soo {soo}".format(**set["extcommunity"]),
)
if set["extcommunity"].get("vpn_distinguisher"):
cmd = "set extcommunity vpn-distinguisher"
if set["extcommunity"]["vpn_distinguisher"].get("range"):
cmd += " range {lower_limit} {upper_limit}".format(
**set["extcommunity"]["vpn_distinguisher"]["range"],
)
elif set["extcommunity"]["vpn_distinguisher"].get("address"):
cmd += " {address}".format(**set["extcommunity"]["vpn_distinguisher"])
cmd += " {address}".format(
**set["extcommunity"]["vpn_distinguisher"],
)
if set["extcommunity"]["vpn_distinguisher"].get("additive"):
cmd += " additive"
command.append(cmd)
Expand Down Expand Up @@ -525,7 +542,10 @@ def _tmplt_route_map_set_ip(config_data):
command.append("{0} dynamic dhcp".format(cmd))
if set_ip["next_hop"].get("encapsulate"):
command.append(
"{0} encapsulate l3vpn {encapsulate}".format(cmd, **set_ip["next_hop"]),
"{0} encapsulate l3vpn {encapsulate}".format(
cmd,
**set_ip["next_hop"],
),
)
if set_ip["next_hop"].get("peer_address"):
command.append("{0} peer-address".format(cmd))
Expand Down Expand Up @@ -649,7 +669,10 @@ def __init__(self, lines=None):
"{{ route_map }}": {
"route_map": "{{ route_map }}",
"{{ action|d() + '_' + sequence|d() }}": {
"entries": {"action": "{{ action }}", "sequence": "{{ sequence }}"},
"entries": {
"action": "{{ action }}",
"sequence": "{{ sequence }}",
},
},
},
},
Expand Down Expand Up @@ -691,7 +714,7 @@ def __init__(self, lines=None):
"result": {
"{{ route_map }}": {
"{{ action|d() + '_' + sequence|d() }}": {
"entries": {"description": "{{ description }}"},
"entries": {"description": "'{{ description }}'"},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
enabled: true

- name: GigabitEthernet3
description: Configured and Merged by Ansible-Network
description: 04j
enabled: false
state: merged

Expand Down
4 changes: 2 additions & 2 deletions tests/integration/targets/ios_interfaces/vars/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ merged:
- interface GigabitEthernet2
- description Configured and Merged by Ansible-Network
- interface GigabitEthernet3
- description Configured and Merged by Ansible-Network
- description 04j
- shutdown
after:
- enabled: true
Expand All @@ -30,7 +30,7 @@ merged:
enabled: true
name: GigabitEthernet2
speed: "1000"
- description: Configured and Merged by Ansible-Network
- description: 04j
enabled: false
name: GigabitEthernet3
speed: "1000"
Expand Down

0 comments on commit d41e3f4

Please sign in to comment.