Fix minor issue in junos_vlan (#28218)

pull/28220/head
Ganesh Nalawade 7 years ago committed by GitHub
parent e9c9473819
commit 0c4706897c

@ -121,10 +121,11 @@ except ImportError:
from xml.etree.ElementTree import tostring from xml.etree.ElementTree import tostring
USE_PERSISTENT_CONNECTION = True USE_PERSISTENT_CONNECTION = True
DEFAULT_DESCRIPTION = "configured by junos_vlan"
def validate_vlan_id(value, module): def validate_vlan_id(value, module):
if not 1 <= value <= 4094: if value and not 1 <= value <= 4094:
module.fail_json(msg='vlan_id must be between 1 and 4094') module.fail_json(msg='vlan_id must be between 1 and 4094')
@ -144,7 +145,7 @@ def main():
element_spec = dict( element_spec = dict(
name=dict(), name=dict(),
vlan_id=dict(type='int'), vlan_id=dict(type='int'),
description=dict(), description=dict(default=DEFAULT_DESCRIPTION),
interfaces=dict(), interfaces=dict(),
state=dict(default='present', choices=['present', 'absent']), state=dict(default='present', choices=['present', 'absent']),
active=dict(default=True, type='bool') active=dict(default=True, type='bool')
@ -152,15 +153,12 @@ def main():
aggregate_spec = deepcopy(element_spec) aggregate_spec = deepcopy(element_spec)
aggregate_spec['name'] = dict(required=True) aggregate_spec['name'] = dict(required=True)
aggregate_spec['vlan_id'] = dict(required=True, type='int')
# remove default in aggregate spec, to handle common arguments # remove default in aggregate spec, to handle common arguments
remove_default_spec(aggregate_spec) remove_default_spec(aggregate_spec)
required_together = [['name', 'vlan_id']]
argument_spec = dict( argument_spec = dict(
aggregate=dict(type='list', elements='dict', options=aggregate_spec, required_together=required_together) aggregate=dict(type='list', elements='dict', options=aggregate_spec)
) )
argument_spec.update(element_spec) argument_spec.update(element_spec)
@ -171,7 +169,6 @@ def main():
module = AnsibleModule(argument_spec=argument_spec, module = AnsibleModule(argument_spec=argument_spec,
required_one_of=required_one_of, required_one_of=required_one_of,
required_together=required_together,
mutually_exclusive=mutually_exclusive, mutually_exclusive=mutually_exclusive,
supports_check_mode=True) supports_check_mode=True)

@ -3,7 +3,6 @@
- name: setup - remove vlan - name: setup - remove vlan
junos_vlan: junos_vlan:
vlan_id: 100
name: test-vlan name: test-vlan
description: test vlan description: test vlan
state: absent state: absent
@ -117,7 +116,7 @@
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } - name: test_vlan_2
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -127,13 +126,13 @@
- result.diff.prepared | search("\+ *test_vlan_1") - result.diff.prepared | search("\+ *test_vlan_1")
- result.diff.prepared | search("\+ *vlan-id 159") - result.diff.prepared | search("\+ *vlan-id 159")
- result.diff.prepared | search("\+ *test_vlan_2") - result.diff.prepared | search("\+ *test_vlan_2")
- result.diff.prepared | search("\+ *vlan-id 160") - result.diff.prepared | search("\+ *description \"configured by junos_vlan\"")
- name: Deactivate vlan configuration using aggregate - name: Deactivate vlan configuration using aggregate
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } - name: test_vlan_2
active: False active: False
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -148,7 +147,7 @@
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, description: test vlan-1 } - { vlan_id: 159, name: test_vlan_1, description: test vlan-1 }
- { vlan_id: 160, name: test_vlan_2, description: test vlan-2 } - name: test_vlan_2
active: True active: True
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -164,8 +163,7 @@
aggregate: aggregate:
- vlan_id: 159 - vlan_id: 159
name: test_vlan_1 name: test_vlan_1
- vlan_id: 160 - name: test_vlan_2
name: test_vlan_2
state: absent state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result
@ -176,13 +174,13 @@
- result.diff.prepared | search("\- *test_vlan_1") - result.diff.prepared | search("\- *test_vlan_1")
- result.diff.prepared | search("\- *vlan-id 159") - result.diff.prepared | search("\- *vlan-id 159")
- result.diff.prepared | search("\- *test_vlan_2") - result.diff.prepared | search("\- *test_vlan_2")
- result.diff.prepared | search("\- *vlan-id 160")
- name: Delete vlan configuration using aggregate (idempotent) - name: Delete vlan configuration using aggregate (idempotent)
junos_vlan: junos_vlan:
aggregate: aggregate:
- { vlan_id: 159, name: test_vlan_1, state: absent } - { vlan_id: 159, name: test_vlan_1 }
- { vlan_id: 160, name: test_vlan_2, state: absent } - name: test_vlan_2
state: absent
provider: "{{ netconf }}" provider: "{{ netconf }}"
register: result register: result

Loading…
Cancel
Save