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

Vyos interface desc fix28 #57228

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/vyos_interface_fixbackport.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- vyos_interface fix <https://github.com/ansible/ansible/pull/57169>
6 changes: 5 additions & 1 deletion lib/ansible/modules/network/vyos/vyos_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def map_obj_to_commands(updates):
value = w.get(item)

if value and value != obj_in_have.get(item):
if item == 'description':
value = "\'" + str(value) + "\'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note, str is not safe to use like this if value can contain non-ascii characters. let me know if that's the case and I can help you test that case and fix it.

commands.append(set_interface + ' ' + item + ' ' + str(value))

if disable and not obj_in_have.get('disable', False):
Expand All @@ -215,6 +217,8 @@ def map_obj_to_commands(updates):
for item in params:
value = w.get(item)
if value:
if item == 'description':
value = "\'" + str(value) + "\'"
commands.append(set_interface + ' ' + item + ' ' + str(value))

if disable:
Expand Down Expand Up @@ -244,7 +248,7 @@ def map_config_to_obj(module):
if match:
param = match.group(1)
if param == 'description':
match = re.search(r'description (\S+)', line, re.M)
match = re.search(r'description (.+)', line, re.M)
description = match.group(1).strip("'")
interface['description'] = description
elif param == 'speed':
Expand Down
10 changes: 5 additions & 5 deletions test/integration/targets/vyos_interface/tests/cli/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1" in result.commands'
- '"set interfaces ethernet eth1 description test-interface" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface''" in result.commands'

- name: Configure interface params
vyos_interface:
Expand All @@ -39,7 +39,7 @@
- assert:
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1 description test-interface-1" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands'
- '"set interfaces ethernet eth1 speed 100" in result.commands'
- '"set interfaces ethernet eth1 duplex half" in result.commands'
- '"set interfaces ethernet eth1 mtu 256" in result.commands'
Expand Down Expand Up @@ -75,7 +75,7 @@
- assert:
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1 description test-interface-2" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface-2''" in result.commands'
- '"set interfaces ethernet eth1 speed 1000" in result.commands'
- '"set interfaces ethernet eth1 duplex full" in result.commands'
- '"set interfaces ethernet eth1 mtu 512" in result.commands'
Expand Down Expand Up @@ -141,11 +141,11 @@
- assert:
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1 description test-interface-1" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands'
- '"set interfaces ethernet eth1 speed 100" in result.commands'
- '"set interfaces ethernet eth1 duplex half" in result.commands'
- '"set interfaces ethernet eth1 mtu 512" in result.commands'
- '"set interfaces ethernet eth2 description test-interface-2" in result.commands'
- '"set interfaces ethernet eth2 description ''test-interface-2''" in result.commands'
- '"set interfaces ethernet eth2 speed 1000" in result.commands'
- '"set interfaces ethernet eth2 duplex full" in result.commands'
- '"set interfaces ethernet eth2 mtu 256" in result.commands'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1" in result.commands'
- '"set interfaces ethernet eth1 description test-interface" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface''" in result.commands'

- name: Configure interface params using platform agnostic module
net_interface:
Expand All @@ -42,7 +42,7 @@
- assert:
that:
- 'result.changed == true'
- '"set interfaces ethernet eth1 description test-interface-1" in result.commands'
- '"set interfaces ethernet eth1 description ''test-interface-1''" in result.commands'
- '"set interfaces ethernet eth1 speed 100" in result.commands'
- '"set interfaces ethernet eth1 duplex half" in result.commands'
- '"set interfaces ethernet eth1 mtu 256" in result.commands'
Expand Down