From abb436199042784e96f0802676b35f4a148f5ba1 Mon Sep 17 00:00:00 2001 From: Ganesh Nalawade Date: Wed, 19 Jul 2017 13:01:56 +0530 Subject: [PATCH] Add vyos_interface default description (#27029) * Add default description string to vyos_interface * If `state=up` it should remove the `disable` configuration for interface. However, if no other interface parameter is configured this ends up deleting the interface itself which is not the desired behaviour. Hence adding a default description field to avoid such scenario's. * Minor changes * Add default description to aggregate --- lib/ansible/modules/network/vyos/vyos_interface.py | 5 ++++- .../integration/targets/vyos_interface/tests/cli/basic.yaml | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/network/vyos/vyos_interface.py b/lib/ansible/modules/network/vyos/vyos_interface.py index bd47f5ae015..1d5aad37a42 100644 --- a/lib/ansible/modules/network/vyos/vyos_interface.py +++ b/lib/ansible/modules/network/vyos/vyos_interface.py @@ -123,6 +123,8 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.vyos import load_config, get_config from ansible.module_utils.vyos import vyos_argument_spec, check_args +DEFAULT_DESCRIPTION = "'configured by vyos_interface'" + def search_obj_in_list(name, lst): for o in lst: @@ -232,6 +234,7 @@ def map_params_to_obj(module): if item not in d: d[item] = None + d['description'] = DEFAULT_DESCRIPTION if not d.get('state'): d['state'] = module.params['state'] @@ -269,7 +272,7 @@ def main(): """ argument_spec = dict( name=dict(), - description=dict(), + description=dict(default=DEFAULT_DESCRIPTION), speed=dict(), mtu=dict(type='int'), duplex=dict(choices=['full', 'half', 'auto']), diff --git a/test/integration/targets/vyos_interface/tests/cli/basic.yaml b/test/integration/targets/vyos_interface/tests/cli/basic.yaml index 5b8c44cb31f..1f3a65d0e73 100644 --- a/test/integration/targets/vyos_interface/tests/cli/basic.yaml +++ b/test/integration/targets/vyos_interface/tests/cli/basic.yaml @@ -49,7 +49,7 @@ vyos_interface: name: eth1 state: present - description: test-interface + description: test-interface-1 speed: 100 duplex: half mtu: 256 @@ -65,7 +65,7 @@ vyos_interface: name: eth1 state: present - description: test-interface-1 + description: test-interface-2 speed: 1000 duplex: full mtu: 512 @@ -75,7 +75,7 @@ - assert: that: - 'result.changed == true' - - '"set interfaces ethernet eth1 description test-interface-1" 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'