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

Fix vyos_vlan aggregate issue & added tests #41638

Merged
merged 2 commits into from
Jun 19, 2018
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
8 changes: 6 additions & 2 deletions lib/ansible/modules/network/vyos/vyos_vlan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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'),
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions test/integration/targets/vyos_vlan/tests/cli/basic.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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