Fix vyos_vlan aggregate issue & added tests (#41638)

* Fix vyos_vlan aggregate issue & Added tests

* Fix #2 for vyos_vlan aggregate issue

(cherry picked from commit 837c216587)
This commit is contained in:
Nilashish Chakraborty 2018-06-19 18:50:28 +05:30 committed by Matt Clay
parent 82b0ee21f7
commit 7cb2486fad
2 changed files with 32 additions and 2 deletions

View file

@ -185,6 +185,10 @@ def map_params_to_obj(module):
item[key] = module.params[key]
d = item.copy()
if not d['vlan_id']:
module.fail_json(msg='vlan_id is required')
d['vlan_id'] = str(d['vlan_id'])
module._check_required_one_of(module.required_one_of, item)
@ -269,7 +273,7 @@ def main():
""" main entry point for module execution
"""
element_spec = dict(
vlan_id=dict(type='int', required=True),
vlan_id=dict(type='int'),
name=dict(),
address=dict(),
interfaces=dict(type='list'),
@ -293,7 +297,7 @@ def main():
argument_spec.update(vyos_argument_spec)
required_one_of = [['vlan_id', 'aggregate'],
['interfaces', 'associated_interfaces']]
['aggregate', 'interfaces', 'associated_interfaces']]
mutually_exclusive = [['vlan_id', 'aggregate']]
module = AnsibleModule(argument_spec=argument_spec,

View file

@ -7,6 +7,8 @@
- delete interfaces ethernet eth1 vif 100
- delete interfaces ethernet eth0 vif 5
- delete interfaces ethernet eth0 vif 100
- delete interfaces ethernet eth0 vif 101
- delete interfaces ethernet eth1 vif 201
- name: set vlan with name
vyos_vlan: &name
@ -68,8 +70,32 @@
that:
- "result.changed == false"
- name: Create VLANs using aggregate
vyos_vlan: &agg_vlan
aggregate:
- { vlan_id: 101, name: voice, interfaces: "eth0" }
- { vlan_id: 201, name: mgm, interfaces: "eth1" }
state: present
register: result
- assert:
that:
- "result.changed == true"
- "'set interfaces ethernet eth0 vif 101 description voice' in result.commands"
- "'set interfaces ethernet eth1 vif 201 description mgm' in result.commands"
- name: Create VLANs using aggregate (idempotent)
vyos_vlan: *agg_vlan
register: result
- assert:
that:
- "result.changed == false"
- name: teardown
vyos_config:
lines:
- delete interfaces ethernet eth1 vif 100
- delete interfaces ethernet eth0 vif 5
- delete interfaces ethernet eth0 vif 101
- delete interfaces ethernet eth1 vif 201