exos_l2_interfaces Resource module (#63113)
* Resource module for exos_l2_interfaces
This commit is contained in:
parent
dcec3d000e
commit
93280bd59c
18 changed files with 1980 additions and 1 deletions
|
@ -0,0 +1,48 @@
|
|||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
#############################################
|
||||
# WARNING #
|
||||
#############################################
|
||||
#
|
||||
# This file is auto generated by the resource
|
||||
# module builder playbook.
|
||||
#
|
||||
# Do not edit this file manually.
|
||||
#
|
||||
# Changes to this file will be over written
|
||||
# by the resource module builder.
|
||||
#
|
||||
# Changes should be made in the model used to
|
||||
# generate this file or in the resource module
|
||||
# builder template.
|
||||
#
|
||||
#############################################
|
||||
"""
|
||||
The arg spec for the exos_l2_interfaces module
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class L2_interfacesArgs(object): # pylint: disable=R0903
|
||||
"""The arg spec for the exos_l2_interfaces module
|
||||
"""
|
||||
def __init__(self, **kwargs):
|
||||
pass
|
||||
|
||||
argument_spec = {
|
||||
'config': {
|
||||
'elements': 'dict',
|
||||
'options': {
|
||||
'access': {'options': {'vlan': {'type': 'int'}},
|
||||
'type': 'dict'},
|
||||
'name': {'required': True, 'type': 'str'},
|
||||
'trunk': {'options': {'native_vlan': {'type': 'int'}, 'trunk_allowed_vlans': {'type': 'list'}},
|
||||
'type': 'dict'}},
|
||||
'type': 'list'},
|
||||
'state': {'choices': ['merged', 'replaced', 'overridden', 'deleted'], 'default': 'merged', 'type': 'str'}
|
||||
} # pylint: disable=C0301
|
|
@ -0,0 +1,294 @@
|
|||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
"""
|
||||
The exos_l2_interfaces class
|
||||
It is in this file where the current configuration (as dict)
|
||||
is compared to the provided configuration (as dict) and the command set
|
||||
necessary to bring the current configuration to it's desired end-state is
|
||||
created
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
from copy import deepcopy
|
||||
from ansible.module_utils.network.common.cfg.base import ConfigBase
|
||||
from ansible.module_utils.network.common.utils import to_list, dict_diff
|
||||
from ansible.module_utils.network.exos.facts.facts import Facts
|
||||
from ansible.module_utils.network.exos.exos import send_requests
|
||||
|
||||
|
||||
class L2_interfaces(ConfigBase):
|
||||
"""
|
||||
The exos_l2_interfaces class
|
||||
"""
|
||||
|
||||
gather_subset = [
|
||||
'!all',
|
||||
'!min',
|
||||
]
|
||||
|
||||
gather_network_resources = [
|
||||
'l2_interfaces',
|
||||
]
|
||||
|
||||
L2_INTERFACE_NATIVE = {
|
||||
"data": {
|
||||
"openconfig-vlan:config": {
|
||||
"interface-mode": "TRUNK",
|
||||
"native-vlan": None,
|
||||
"trunk-vlans": []
|
||||
}
|
||||
},
|
||||
"method": "PATCH",
|
||||
"path": None
|
||||
}
|
||||
|
||||
L2_INTERFACE_TRUNK = {
|
||||
"data": {
|
||||
"openconfig-vlan:config": {
|
||||
"interface-mode": "TRUNK",
|
||||
"trunk-vlans": []
|
||||
}
|
||||
},
|
||||
"method": "PATCH",
|
||||
"path": None
|
||||
}
|
||||
|
||||
L2_INTERFACE_ACCESS = {
|
||||
"data": {
|
||||
"openconfig-vlan:config": {
|
||||
"interface-mode": "ACCESS",
|
||||
"access-vlan": None
|
||||
}
|
||||
},
|
||||
"method": "PATCH",
|
||||
"path": None
|
||||
}
|
||||
|
||||
L2_PATH = "/rest/restconf/data/openconfig-interfaces:interfaces/interface="
|
||||
|
||||
def __init__(self, module):
|
||||
super(L2_interfaces, self).__init__(module)
|
||||
|
||||
def get_l2_interfaces_facts(self):
|
||||
""" Get the 'facts' (the current configuration)
|
||||
|
||||
:rtype: A dictionary
|
||||
:returns: The current configuration as a dictionary
|
||||
"""
|
||||
facts, _warnings = Facts(self._module).get_facts(
|
||||
self.gather_subset, self.gather_network_resources)
|
||||
l2_interfaces_facts = facts['ansible_network_resources'].get(
|
||||
'l2_interfaces')
|
||||
if not l2_interfaces_facts:
|
||||
return []
|
||||
return l2_interfaces_facts
|
||||
|
||||
def execute_module(self):
|
||||
""" Execute the module
|
||||
|
||||
:rtype: A dictionary
|
||||
:returns: The result from module execution
|
||||
"""
|
||||
result = {'changed': False}
|
||||
warnings = list()
|
||||
requests = list()
|
||||
|
||||
existing_l2_interfaces_facts = self.get_l2_interfaces_facts()
|
||||
requests.extend(self.set_config(existing_l2_interfaces_facts))
|
||||
if requests:
|
||||
if not self._module.check_mode:
|
||||
send_requests(self._module, requests=requests)
|
||||
result['changed'] = True
|
||||
result['requests'] = requests
|
||||
|
||||
changed_l2_interfaces_facts = self.get_l2_interfaces_facts()
|
||||
|
||||
result['before'] = existing_l2_interfaces_facts
|
||||
if result['changed']:
|
||||
result['after'] = changed_l2_interfaces_facts
|
||||
|
||||
result['warnings'] = warnings
|
||||
return result
|
||||
|
||||
def set_config(self, existing_l2_interfaces_facts):
|
||||
""" Collect the configuration from the args passed to the module,
|
||||
collect the current configuration (as a dict from facts)
|
||||
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
want = self._module.params['config']
|
||||
have = existing_l2_interfaces_facts
|
||||
resp = self.set_state(want, have)
|
||||
return to_list(resp)
|
||||
|
||||
def set_state(self, want, have):
|
||||
""" Select the appropriate function based on the state provided
|
||||
|
||||
:param want: the desired configuration as a dictionary
|
||||
:param have: the current configuration as a dictionary
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
state = self._module.params['state']
|
||||
if state == 'overridden':
|
||||
requests = self._state_overridden(want, have)
|
||||
elif state == 'deleted':
|
||||
requests = self._state_deleted(want, have)
|
||||
elif state == 'merged':
|
||||
requests = self._state_merged(want, have)
|
||||
elif state == 'replaced':
|
||||
requests = self._state_replaced(want, have)
|
||||
return requests
|
||||
|
||||
def _state_replaced(self, want, have):
|
||||
""" The request generator when state is replaced
|
||||
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
requests = []
|
||||
for w in want:
|
||||
for h in have:
|
||||
if w["name"] == h["name"]:
|
||||
if dict_diff(w, h):
|
||||
l2_request = self._update_patch_request(w, h)
|
||||
l2_request["data"] = json.dumps(l2_request["data"])
|
||||
requests.append(l2_request)
|
||||
break
|
||||
|
||||
return requests
|
||||
|
||||
def _state_overridden(self, want, have):
|
||||
""" The request generator when state is overridden
|
||||
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to migrate the current configuration
|
||||
to the desired configuration
|
||||
"""
|
||||
requests = []
|
||||
have_copy = []
|
||||
for w in want:
|
||||
for h in have:
|
||||
if w["name"] == h["name"]:
|
||||
if dict_diff(w, h):
|
||||
l2_request = self._update_patch_request(w, h)
|
||||
l2_request["data"] = json.dumps(l2_request["data"])
|
||||
requests.append(l2_request)
|
||||
have_copy.append(h)
|
||||
break
|
||||
|
||||
for h in have:
|
||||
if h not in have_copy:
|
||||
l2_delete = self._update_delete_request(h)
|
||||
if l2_delete["path"]:
|
||||
l2_delete["data"] = json.dumps(l2_delete["data"])
|
||||
requests.append(l2_delete)
|
||||
|
||||
return requests
|
||||
|
||||
def _state_merged(self, want, have):
|
||||
""" The request generator when state is merged
|
||||
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to merge the provided into
|
||||
the current configuration
|
||||
"""
|
||||
requests = []
|
||||
for w in want:
|
||||
for h in have:
|
||||
if w["name"] == h["name"]:
|
||||
if dict_diff(h, w):
|
||||
l2_request = self._update_patch_request(w, h)
|
||||
l2_request["data"] = json.dumps(l2_request["data"])
|
||||
requests.append(l2_request)
|
||||
break
|
||||
|
||||
return requests
|
||||
|
||||
def _state_deleted(self, want, have):
|
||||
""" The request generator when state is deleted
|
||||
|
||||
:rtype: A list
|
||||
:returns: the requests necessary to remove the current configuration
|
||||
of the provided objects
|
||||
"""
|
||||
requests = []
|
||||
if want:
|
||||
for w in want:
|
||||
for h in have:
|
||||
if w["name"] == h["name"]:
|
||||
l2_delete = self._update_delete_request(h)
|
||||
if l2_delete["path"]:
|
||||
l2_delete["data"] = json.dumps(l2_delete["data"])
|
||||
requests.append(l2_delete)
|
||||
break
|
||||
|
||||
else:
|
||||
for h in have:
|
||||
l2_delete = self._update_delete_request(h)
|
||||
if l2_delete["path"]:
|
||||
l2_delete["data"] = json.dumps(l2_delete["data"])
|
||||
requests.append(l2_delete)
|
||||
|
||||
return requests
|
||||
|
||||
def _update_patch_request(self, want, have):
|
||||
|
||||
facts, _warnings = Facts(self._module).get_facts(
|
||||
self.gather_subset, ['vlans', ])
|
||||
vlans_facts = facts['ansible_network_resources'].get('vlans')
|
||||
|
||||
vlan_id = []
|
||||
|
||||
for vlan in vlans_facts:
|
||||
vlan_id.append(vlan['vlan_id'])
|
||||
|
||||
if want.get("access"):
|
||||
if want["access"]["vlan"] in vlan_id:
|
||||
l2_request = deepcopy(self.L2_INTERFACE_ACCESS)
|
||||
l2_request["data"]["openconfig-vlan:config"]["access-vlan"] = want["access"]["vlan"]
|
||||
l2_request["path"] = self.L2_PATH + str(want["name"]) + "/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config"
|
||||
else:
|
||||
self._module.fail_json(msg="VLAN %s does not exist" % (want["access"]["vlan"]))
|
||||
|
||||
elif want.get("trunk"):
|
||||
if want["trunk"]["native_vlan"]:
|
||||
if want["trunk"]["native_vlan"] in vlan_id:
|
||||
l2_request = deepcopy(self.L2_INTERFACE_NATIVE)
|
||||
l2_request["data"]["openconfig-vlan:config"]["native-vlan"] = want["trunk"]["native_vlan"]
|
||||
l2_request["path"] = self.L2_PATH + str(want["name"]) + "/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config"
|
||||
for vlan in want["trunk"]["trunk_allowed_vlans"]:
|
||||
if int(vlan) in vlan_id:
|
||||
l2_request["data"]["openconfig-vlan:config"]["trunk-vlans"].append(int(vlan))
|
||||
else:
|
||||
self._module.fail_json(msg="VLAN %s does not exist" % (vlan))
|
||||
else:
|
||||
self._module.fail_json(msg="VLAN %s does not exist" % (want["trunk"]["native_vlan"]))
|
||||
else:
|
||||
l2_request = deepcopy(self.L2_INTERFACE_TRUNK)
|
||||
l2_request["path"] = self.L2_PATH + str(want["name"]) + "/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config"
|
||||
for vlan in want["trunk"]["trunk_allowed_vlans"]:
|
||||
if int(vlan) in vlan_id:
|
||||
l2_request["data"]["openconfig-vlan:config"]["trunk-vlans"].append(int(vlan))
|
||||
else:
|
||||
self._module.fail_json(msg="VLAN %s does not exist" % (vlan))
|
||||
return l2_request
|
||||
|
||||
def _update_delete_request(self, have):
|
||||
|
||||
l2_request = deepcopy(self.L2_INTERFACE_ACCESS)
|
||||
|
||||
if have["access"] and have["access"]["vlan"] != 1 or have["trunk"] or not have["access"]:
|
||||
l2_request["data"]["openconfig-vlan:config"]["access-vlan"] = 1
|
||||
l2_request["path"] = self.L2_PATH + str(have["name"]) + "/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config"
|
||||
|
||||
return l2_request
|
|
@ -17,7 +17,7 @@ from ansible.module_utils.network.exos.facts.lldp_global.lldp_global import Lldp
|
|||
from ansible.module_utils.network.exos.facts.vlans.vlans import VlansFacts
|
||||
from ansible.module_utils.network.exos.facts.legacy.base import Default, Hardware, Interfaces, Config
|
||||
from ansible.module_utils.network.exos.facts.lldp_interfaces.lldp_interfaces import Lldp_interfacesFacts
|
||||
|
||||
from ansible.module_utils.network.exos.facts.l2_interfaces.l2_interfaces import L2_interfacesFacts
|
||||
|
||||
FACT_LEGACY_SUBSETS = dict(
|
||||
default=Default,
|
||||
|
@ -29,6 +29,7 @@ FACT_RESOURCE_SUBSETS = dict(
|
|||
lldp_global=Lldp_globalFacts,
|
||||
vlans=VlansFacts,
|
||||
lldp_interfaces=Lldp_interfacesFacts,
|
||||
l2_interfaces=L2_interfacesFacts,
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,92 @@
|
|||
#
|
||||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2019 Red Hat
|
||||
# GNU General Public License v3.0+
|
||||
# (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
"""
|
||||
The exos l2_interfaces fact class
|
||||
It is in this file the configuration is collected from the device
|
||||
for a given resource, parsed, and the facts tree is populated
|
||||
based on the configuration.
|
||||
"""
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
||||
import re
|
||||
from copy import deepcopy
|
||||
|
||||
from ansible.module_utils.network.common import utils
|
||||
from ansible.module_utils.network.exos.argspec.l2_interfaces.l2_interfaces import L2_interfacesArgs
|
||||
from ansible.module_utils.network.exos.exos import send_requests
|
||||
|
||||
|
||||
class L2_interfacesFacts(object):
|
||||
""" The exos l2_interfaces fact class
|
||||
"""
|
||||
def __init__(self, module, subspec='config', options='options'):
|
||||
self._module = module
|
||||
self.argument_spec = L2_interfacesArgs.argument_spec
|
||||
spec = deepcopy(self.argument_spec)
|
||||
if subspec:
|
||||
if options:
|
||||
facts_argument_spec = spec[subspec][options]
|
||||
else:
|
||||
facts_argument_spec = spec[subspec]
|
||||
else:
|
||||
facts_argument_spec = spec
|
||||
|
||||
self.generated_spec = utils.generate_dict(facts_argument_spec)
|
||||
|
||||
def populate_facts(self, connection, ansible_facts, data=None):
|
||||
""" Populate the facts for l2_interfaces
|
||||
:param connection: the device connection
|
||||
:param ansible_facts: Facts dictionary
|
||||
:param data: previously collected conf
|
||||
:rtype: dictionary
|
||||
:returns: facts
|
||||
"""
|
||||
|
||||
if not data:
|
||||
request = [{
|
||||
"path": "/rest/restconf/data/openconfig-interfaces:interfaces",
|
||||
"method": "GET"
|
||||
}]
|
||||
data = send_requests(self._module, requests=request)
|
||||
|
||||
objs = []
|
||||
if data:
|
||||
for d in data[0]["openconfig-interfaces:interfaces"]["interface"]:
|
||||
obj = self.render_config(self.generated_spec, d)
|
||||
if obj:
|
||||
objs.append(obj)
|
||||
|
||||
ansible_facts['ansible_network_resources'].pop('l2_interfaces', None)
|
||||
facts = {}
|
||||
if objs:
|
||||
params = utils.validate_config(self.argument_spec, {'config': objs})
|
||||
facts['l2_interfaces'] = params['config']
|
||||
|
||||
ansible_facts['ansible_network_resources'].update(facts)
|
||||
return ansible_facts
|
||||
|
||||
def render_config(self, spec, conf):
|
||||
"""
|
||||
Render config as dictionary structure and delete keys
|
||||
from spec for null values
|
||||
|
||||
:param spec: The facts tree, generated from the argspec
|
||||
:param conf: The configuration
|
||||
:rtype: dictionary
|
||||
:returns: The generated config
|
||||
"""
|
||||
config = deepcopy(spec)
|
||||
if conf["config"]["type"] == "ethernetCsmacd":
|
||||
conf_dict = conf["openconfig-if-ethernet:ethernet"]["openconfig-vlan:switched-vlan"]["config"]
|
||||
config["name"] = conf["name"]
|
||||
if conf_dict["interface-mode"] == "ACCESS":
|
||||
config["access"]["vlan"] = conf_dict.get("access-vlan")
|
||||
else:
|
||||
if 'native-vlan' in conf_dict:
|
||||
config["trunk"]["native_vlan"] = conf_dict.get("native-vlan")
|
||||
config["trunk"]["trunk_allowed_vlans"] = conf_dict.get("trunk-vlans")
|
||||
return utils.remove_empties(config)
|
1137
lib/ansible/modules/network/exos/exos_l2_interfaces.py
Normal file
1137
lib/ansible/modules/network/exos/exos_l2_interfaces.py
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "[^_].*"
|
||||
test_items: []
|
|
@ -0,0 +1,19 @@
|
|||
---
|
||||
- name: Collect all httpapi test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/httpapi"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
use_regex: true
|
||||
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 (connection=httpapi)
|
||||
include: "{{ test_case_to_run }}"
|
||||
vars:
|
||||
ansible_connection: httpapi
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: httpapi.yaml, tags: ['httpapi'] }
|
|
@ -0,0 +1,12 @@
|
|||
---
|
||||
- name: Populate config
|
||||
exos_config:
|
||||
lines:
|
||||
- create vlan vlan_10 tag 10
|
||||
- create vlan vlan_20 tag 20
|
||||
- create vlan vlan_30 tag 30
|
||||
- create vlan vlan_40 tag 40
|
||||
- configure vlan 10 add ports 1 untagged
|
||||
- configure vlan 20 add ports 2 tagged
|
||||
- configure vlan 20 add ports 3 untagged
|
||||
- configure vlan 30 add ports 3 tagged
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
- name: Reset config
|
||||
exos_config:
|
||||
lines:
|
||||
- configure vlan Default add ports all untagged
|
||||
- configure vlan 2-4094 delete ports all
|
||||
- delete vlan 2-4094
|
|
@ -0,0 +1,96 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "Start exos_l2_interfaces deleted integration tests ansible_connection={{ ansible_connection }}"
|
||||
|
||||
- include_tasks: _reset_config.yaml
|
||||
ignore_errors: yes
|
||||
|
||||
- include_tasks: _populate_config.yaml
|
||||
|
||||
- set_fact:
|
||||
config:
|
||||
- access:
|
||||
vlan: 1
|
||||
name: '2'
|
||||
trunk: null
|
||||
- access:
|
||||
vlan: 1
|
||||
name: '3'
|
||||
trunk: null
|
||||
config_all:
|
||||
- access:
|
||||
vlan: 1
|
||||
name: '1'
|
||||
trunk: null
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- block:
|
||||
- name: Delete L2 interface configuration
|
||||
exos_l2_interfaces: &deleted
|
||||
config:
|
||||
- name: '2'
|
||||
- name: '3'
|
||||
state: deleted
|
||||
register: result
|
||||
|
||||
- name: Assert that correct set of results were generated
|
||||
assert:
|
||||
that:
|
||||
- "deleted['requests_1']|symmetric_difference(result['requests']) == []"
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that after dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.after) == []"
|
||||
- "config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Delete L2 interface configuration
|
||||
exos_l2_interfaces:
|
||||
config:
|
||||
state: deleted
|
||||
register: result
|
||||
|
||||
- name: Assert that correct set of results were generated
|
||||
assert:
|
||||
that:
|
||||
- "deleted['requests_2']|symmetric_difference(result['requests']) == []"
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that after dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.after) == []"
|
||||
- "config_all|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Delete attributes of all configured interfaces (IDEMPOTENT)
|
||||
exos_l2_interfaces: *deleted
|
||||
register: result
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that the before dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- set_fact:
|
||||
expected_config: "{{ config }} + {{ config_all }}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "expected_config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
|
@ -0,0 +1,85 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START exos_l2_interfaces merged integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- include_tasks: _reset_config.yaml
|
||||
ignore_errors: yes
|
||||
|
||||
- include_tasks: _populate_config.yaml
|
||||
|
||||
- set_fact:
|
||||
config:
|
||||
- access:
|
||||
vlan: 20
|
||||
name: '1'
|
||||
trunk: null
|
||||
- access: null
|
||||
name: '2'
|
||||
trunk:
|
||||
native_vlan: 10
|
||||
trunk_allowed_vlans:
|
||||
- 20
|
||||
- 30
|
||||
invalid_config:
|
||||
- access: null
|
||||
name: '3'
|
||||
trunk:
|
||||
trunk_allowed_vlans:
|
||||
- 50
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- block:
|
||||
- name: Merge the provided configuration with the existing running configuration
|
||||
exos_l2_interfaces: &merged
|
||||
config: "{{ config }}"
|
||||
state: merged
|
||||
register: result
|
||||
|
||||
- name: Assert that correct set of results were generated
|
||||
assert:
|
||||
that:
|
||||
- "merged['requests']|symmetric_difference(result['requests']) == []"
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that after dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.after) == []"
|
||||
- "config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Merge the provided configuration with the existing running configuration (IDEMPOTENT)
|
||||
exos_l2_interfaces: *merged
|
||||
register: result
|
||||
|
||||
- name: Assert that the previous task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that the before dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
- "config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Merge provided configuration with existing configuration
|
||||
exos_l2_interfaces:
|
||||
config: "{{ invalid_config }}"
|
||||
state: merged
|
||||
register: result
|
||||
ignore_errors: yes
|
||||
|
||||
- name: Assert that the previous task failed
|
||||
assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
- "result.failed == true"
|
||||
- "result.msg == 'VLAN 50 does not exist'"
|
|
@ -0,0 +1,76 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "Start exos_l2_interfaces overridden integration tests ansible_connection={{ ansible_connection }}"
|
||||
|
||||
- include_tasks: _reset_config.yaml
|
||||
ignore_errors: yes
|
||||
|
||||
- include_tasks: _populate_config.yaml
|
||||
|
||||
- set_fact:
|
||||
config:
|
||||
- access: null
|
||||
name: '1'
|
||||
trunk:
|
||||
native_vlan: 10
|
||||
trunk_allowed_vlans:
|
||||
- 20
|
||||
- 30
|
||||
config_all:
|
||||
- access:
|
||||
vlan: 1
|
||||
name: '2'
|
||||
trunk: null
|
||||
- access:
|
||||
vlan: 1
|
||||
name: '3'
|
||||
trunk: null
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- block:
|
||||
- name: Override device L2 interface configuration with provided configurations
|
||||
exos_l2_interfaces: &overridden
|
||||
config: "{{ config }}"
|
||||
state: overridden
|
||||
register: result
|
||||
|
||||
- name: Assert that correct set of results were generated
|
||||
assert:
|
||||
that:
|
||||
- "overridden['requests']|symmetric_difference(result['requests']) == []"
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that after dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.after) == []"
|
||||
|
||||
- set_fact:
|
||||
expected_config: "{{ config }} + {{ config_all }}"
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "expected_config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Override device LLDP interface configuration with provided configurations (IDEMPOTENT)
|
||||
exos_l2_interfaces: *overridden
|
||||
register: result
|
||||
|
||||
- name: Assert that task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that the before dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
- "expected_config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
|
@ -0,0 +1,63 @@
|
|||
---
|
||||
- debug:
|
||||
msg: "START exos_l2_interfaces replaced integration tests on connection={{ ansible_connection }}"
|
||||
|
||||
- include_tasks: _reset_config.yaml
|
||||
|
||||
- include_tasks: _populate_config.yaml
|
||||
|
||||
- set_fact:
|
||||
config:
|
||||
- access: null
|
||||
name: '2'
|
||||
trunk:
|
||||
native_vlan: 30
|
||||
trunk_allowed_vlans:
|
||||
- 40
|
||||
- access:
|
||||
vlan: 10
|
||||
name: '3'
|
||||
trunk: null
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- block:
|
||||
- name: Replace L2 interface configuration with provided configuration
|
||||
exos_l2_interfaces: &replaced
|
||||
config: "{{ config }}"
|
||||
state: replaced
|
||||
register: result
|
||||
|
||||
- name: Assert that correct set of results were generated
|
||||
assert:
|
||||
that:
|
||||
- "replaced['requests']|symmetric_difference(result['requests']) == []"
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that after dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.after) == []"
|
||||
- "config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
||||
|
||||
- name: Replace L2 interface configuration with provided configuration (IDEMPOTENT)
|
||||
exos_l2_interfaces: *replaced
|
||||
register: result
|
||||
|
||||
- name: Assert that task was idempotent
|
||||
assert:
|
||||
that:
|
||||
- "result['changed'] == false"
|
||||
|
||||
- exos_facts:
|
||||
gather_network_resources: l2_interfaces
|
||||
|
||||
- name: Assert that the before dicts were correctly generated
|
||||
assert:
|
||||
that:
|
||||
- "ansible_facts.network_resources.l2_interfaces|symmetric_difference(result.before) == []"
|
||||
- "config|difference(ansible_facts.network_resources.l2_interfaces) == []"
|
44
test/integration/targets/exos_l2_interfaces/vars/main.yaml
Normal file
44
test/integration/targets/exos_l2_interfaces/vars/main.yaml
Normal file
|
@ -0,0 +1,44 @@
|
|||
---
|
||||
merged:
|
||||
requests:
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 20}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=1/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
- data: '{"openconfig-vlan:config": {"trunk-vlans": [20, 30], "interface-mode": "TRUNK", "native-vlan": 10}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=2/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
|
||||
replaced:
|
||||
requests:
|
||||
- data: '{"openconfig-vlan:config": {"trunk-vlans": [40], "interface-mode": "TRUNK", "native-vlan": 30}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=2/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 10}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=3/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
|
||||
overridden:
|
||||
requests:
|
||||
- data: '{"openconfig-vlan:config": {"trunk-vlans": [20, 30], "interface-mode": "TRUNK", "native-vlan": 10}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=1/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 1}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=2/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 1}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=3/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
|
||||
deleted:
|
||||
requests_1:
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 1}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=2/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 1}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=3/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
||||
|
||||
requests_2:
|
||||
- data: '{"openconfig-vlan:config": {"interface-mode": "ACCESS", "access-vlan": 1}}'
|
||||
method: PATCH
|
||||
path: /rest/restconf/data/openconfig-interfaces:interfaces/interface=1/openconfig-if-ethernet:ethernet/openconfig-vlan:switched-vlan/config
|
Loading…
Add table
Reference in a new issue