Platform agnostic module for VRFs (#25383)

* WIP VRF platform agnostic module

* Fixed examples refering vlans instead of vrfs

* Add integration tests
pull/25520/merge
Ricardo Carrillo Cruz 8 years ago committed by GitHub
parent d83f254bb6
commit 72e65e4290

@ -0,0 +1,74 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Ansible by Red Hat, inc
#
# This file is part of Ansible by Red Hat
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'core'}
DOCUMENTATION = """
---
module: net_vrf
version_added: "2.4"
author: "Ricardo Carrillo Cruz (@rcarrillocruz)"
short_description: Manage VRFs on network devices
description:
- This module provides declarative management of VRFs
on network devices.
options:
name:
description:
- Name of the VRF.
interfaces:
description:
- List of interfaces the VRF should be configured on.
collection:
description: List of VRFs definitions
purge:
description:
- Purge VRFs not defined in the collections parameter.
default: no
state:
description:
- State of the VRF configuration.
default: present
choices: ['present', 'absent']
"""
EXAMPLES = """
- name: Create VRF named MANAGEMENT
net_vrf:
name: MANAGEMENT
- name: remove VRF named MANAGEMENT
net_vrf:
name: MANAGEMENT
state: absent
"""
RETURN = """
commands:
description: The list of configuration mode commands to send to the device
returned: always
type: list
sample:
- vrf definition MANAGEMENT
"""

@ -0,0 +1,27 @@
# (c) 2017, Ansible Inc,
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from ansible.plugins.action.net_base import ActionModule as _ActionModule
class ActionModule(_ActionModule):
def run(self, tmp=None, task_vars=None):
result = super(ActionModule, self).run(tmp, task_vars)
return result

@ -13,3 +13,4 @@
- { role: net_command, when: "limit_to in ['*', 'net_command']" }
- { role: net_user, when: "limit_to_in ['*', 'net_user']" }
- { role: net_vlan, when: "limit_to in ['*', 'net_vlan']" }
- { role: net_vrf, when: "limit_to_in ['*', 'net_vrf']" }

@ -0,0 +1,16 @@
---
- name: collect all cli test cases
find:
paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml"
register: test_cases
delegate_to: localhost
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run

@ -0,0 +1,2 @@
---
- { include: cli.yaml, tags: ['cli'] }

@ -0,0 +1,7 @@
---
- debug: msg="START cli/set_name_servers.yaml"
- include: "{{ role_path }}/tests/eos/basic.yaml"
when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos'
- debug: msg="END cli/set_name_servers.yaml"

@ -0,0 +1,116 @@
---
- name: setup - remove vrf
eos_vrf:
name: test
state: absent
authorize: yes
provider: "{{ cli }}"
- name: Create vrf
net_vrf:
name: test
rd: 1:200
state: present
authorize: yes
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- "'vrf definition test' in result.commands"
- "'rd 1:200' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name"
- name: Create vrf again (idempotent)
net_vrf:
name: test
rd: 1:200
state: present
authorize: yes
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "result.session_name is not defined"
- name: Modify rd
net_vrf:
name: test
rd: 1:201
state: present
authorize: yes
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- "'vrf definition test' in result.commands"
- "'rd 1:201' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name"
- name: Modify rd again (idempotent)
net_vrf:
name: test
rd: 1:201
state: present
authorize: yes
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "result.session_name is not defined"
- name: Add Ethernet2 to vrf
net_vrf:
name: test
rd: 1:201
state: present
authorize: yes
interfaces:
- Ethernet2
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == true"
- "'interface Ethernet2' in result.commands"
- "'vrf forwarding test' in result.commands"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "'ansible_1' in result.session_name"
- name: Add Ethernet2 to vrf again (idempotent)
net_vrf:
name: test
rd: 1:201
state: present
authorize: yes
interfaces:
- Ethernet2
provider: "{{ cli }}"
register: result
- assert:
that:
- "result.changed == false"
- "result.commands | length == 0"
# Ensure sessions contains epoc. Will fail after 18th May 2033
- "result.session_name is not defined"
# FIXME add in tests for everything defined in docs
# FIXME Test state:absent + test:
# FIXME Without powers ensure "privileged mode required"
Loading…
Cancel
Save