mirror of https://github.com/ansible/ansible.git
junos_linkagg implementation and junos modules refactor (#26587)
* junos_linkagg implementation and junos modules refactor * junos_linkagg implementation * junos_linkagg integration test * net_linkagg integration test for junos * decouple `load_config` and `commit` operations, to allow single commit (in case on confirm commit) and to perform batch commit (multiple `load_config` followed by single `commit`) * Other related refactor * Fix CI issues * Fix unit test failurepull/23466/merge
parent
82558baaf6
commit
be89ef3eb6
@ -0,0 +1,339 @@
|
||||
#!/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: junos_linkagg
|
||||
version_added: "2.4"
|
||||
author: "Ganesh Nalawade (@ganeshrn)"
|
||||
short_description: Manage link aggregation groups on Juniper JUNOS network devices
|
||||
description:
|
||||
- This module provides declarative management of link aggregation groups
|
||||
on Juniper JUNOS network devices.
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- Name of the link aggregation group.
|
||||
required: true
|
||||
mode:
|
||||
description:
|
||||
- Mode of the link aggregation group. A value of C(on) will enable LACP in C(passive) mode.
|
||||
C(active) configures the link to actively information about the state of the link,
|
||||
or it can be configured in C(passive) mode ie. send link state information only when
|
||||
received them from another link. A value of C(off) will disable LACP.
|
||||
default: off
|
||||
choices: ['on', 'off', 'active', 'passive']
|
||||
members:
|
||||
description:
|
||||
- List of members interfaces of the link aggregation group. The value can be
|
||||
single interface or list of interfaces.
|
||||
required: true
|
||||
min_links:
|
||||
description:
|
||||
- Minimum members that should be up
|
||||
before bringing up the link aggregation group.
|
||||
device_count:
|
||||
description:
|
||||
- Number of aggregated ethernet devices that can be configured.
|
||||
Acceptable integer value is between 1 and 128.
|
||||
description:
|
||||
description:
|
||||
- Description of Interface.
|
||||
collection:
|
||||
description: List of link aggregation definitions.
|
||||
purge:
|
||||
description:
|
||||
- Purge link aggregation groups not defined in the collections parameter.
|
||||
default: no
|
||||
state:
|
||||
description:
|
||||
- State of the link aggregation group.
|
||||
default: present
|
||||
choices: ['present', 'absent', 'up', 'down']
|
||||
active:
|
||||
description:
|
||||
- Specifies whether or not the configuration is active or deactivated
|
||||
default: True
|
||||
choices: [True, False]
|
||||
requirements:
|
||||
- ncclient (>=v0.5.2)
|
||||
notes:
|
||||
- This module requires the netconf system service be enabled on
|
||||
the remote device being managed
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: configure link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
members:
|
||||
- ge-0/0/5
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
lacp: active
|
||||
device_count: 4
|
||||
state: present
|
||||
|
||||
- name: delete link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
members:
|
||||
- ge-0/0/5
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
lacp: active
|
||||
device_count: 4
|
||||
state: delete
|
||||
|
||||
- name: deactivate link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
members:
|
||||
- ge-0/0/5
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
lacp: active
|
||||
device_count: 4
|
||||
state: present
|
||||
active: False
|
||||
|
||||
- name: Activate link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
members:
|
||||
- ge-0/0/5
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
lacp: active
|
||||
device_count: 4
|
||||
state: present
|
||||
active: True
|
||||
|
||||
- name: Disable link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
state: down
|
||||
|
||||
- name: Enable link aggregation
|
||||
junos_linkagg:
|
||||
name: ae11
|
||||
state: up
|
||||
"""
|
||||
|
||||
RETURN = """
|
||||
diff:
|
||||
description: Configuration difference before and after applying change.
|
||||
returned: when configuration is changed and diff option is enabled.
|
||||
type: string
|
||||
sample: >
|
||||
[edit interfaces]
|
||||
+ ge-0/0/6 {
|
||||
+ ether-options {
|
||||
+ 802.3ad ae0;
|
||||
+ }
|
||||
+ }
|
||||
[edit interfaces ge-0/0/7]
|
||||
+ ether-options {
|
||||
+ 802.3ad ae0;
|
||||
+ }
|
||||
[edit interfaces]
|
||||
+ ae0 {
|
||||
+ description "configured by junos_linkagg";
|
||||
+ aggregated-ether-options {
|
||||
+ lacp {
|
||||
+ active;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
"""
|
||||
import collections
|
||||
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
from ansible.module_utils.junos import junos_argument_spec, check_args
|
||||
from ansible.module_utils.junos import load_config, map_params_to_obj, map_obj_to_ele
|
||||
from ansible.module_utils.junos import commit_configuration, discard_changes, locked_config, get_configuration
|
||||
|
||||
try:
|
||||
from lxml.etree import tostring
|
||||
except ImportError:
|
||||
from xml.etree.ElementTree import tostring
|
||||
|
||||
USE_PERSISTENT_CONNECTION = True
|
||||
DEFAULT_COMMENT = 'configured by junos_linkagg'
|
||||
|
||||
|
||||
def validate_device_count(value, module):
|
||||
if value and not 1 <= value <= 128:
|
||||
module.fail_json(msg='device_count must be between 1 and 128')
|
||||
|
||||
|
||||
def validate_min_links(value, module):
|
||||
if value and not 1 <= value <= 8:
|
||||
module.fail_json(msg='min_links must be between 1 and 8')
|
||||
|
||||
|
||||
def validate_param_values(module, obj):
|
||||
for key in obj:
|
||||
# validate the param value (if validator func exists)
|
||||
validator = globals().get('validate_%s' % key)
|
||||
if callable(validator):
|
||||
validator(module.params.get(key), module)
|
||||
|
||||
|
||||
def configure_lag_params(module, warnings):
|
||||
top = 'interfaces/interface'
|
||||
param_lag_to_xpath_map = collections.OrderedDict()
|
||||
param_lag_to_xpath_map.update([
|
||||
('name', {'xpath': 'name', 'is_key': True}),
|
||||
('description', 'description'),
|
||||
('min_links', {'xpath': 'minimum-links', 'top': 'aggregated-ether-options'}),
|
||||
('disable', {'xpath': 'disable', 'tag_only': True}),
|
||||
('mode', {'xpath': module.params['mode'], 'tag_only': True, 'top': 'aggregated-ether-options/lacp'}),
|
||||
])
|
||||
|
||||
validate_param_values(module, param_lag_to_xpath_map)
|
||||
|
||||
want = map_params_to_obj(module, param_lag_to_xpath_map)
|
||||
ele = map_obj_to_ele(module, want, top)
|
||||
|
||||
diff = load_config(module, tostring(ele), warnings, action='replace')
|
||||
if module.params['device_count']:
|
||||
top = 'chassis/aggregated-devices/ethernet'
|
||||
device_count_to_xpath_map = {'device_count': {'xpath': 'device-count', 'leaf_only': True}}
|
||||
|
||||
validate_param_values(module, device_count_to_xpath_map)
|
||||
|
||||
want = map_params_to_obj(module, device_count_to_xpath_map)
|
||||
ele = map_obj_to_ele(module, want, top)
|
||||
|
||||
diff = load_config(module, tostring(ele), warnings, action='replace')
|
||||
|
||||
return diff
|
||||
|
||||
|
||||
def configure_member_params(module, warnings, diff=None):
|
||||
top = 'interfaces/interface'
|
||||
members = module.params['members']
|
||||
|
||||
if members:
|
||||
member_to_xpath_map = collections.OrderedDict()
|
||||
member_to_xpath_map.update([
|
||||
('name', {'xpath': 'name', 'is_key': True, 'parent_attrib': False}),
|
||||
('bundle', {'xpath': 'bundle', 'leaf_only': True, 'top': 'ether-options/ieee-802.3ad', 'is_key': True}),
|
||||
])
|
||||
|
||||
# link aggregation bundle assigned to member
|
||||
module.params['bundle'] = module.params['name']
|
||||
|
||||
for member in members:
|
||||
|
||||
if module.params['state'] == 'absent':
|
||||
# if link aggregate bundle is not assigned to member, trying to
|
||||
# delete it results in rpc-reply error, hence if is not assigned
|
||||
# skip deleting it and continue to next member.
|
||||
resp = get_configuration(module)
|
||||
bundle = resp.xpath("configuration/interfaces/interface[name='%s']/ether-options/"
|
||||
"ieee-802.3ad[bundle='%s']" % (member, module.params['bundle']))
|
||||
if not bundle:
|
||||
continue
|
||||
# Name of member to be assigned to link aggregation bundle
|
||||
module.params['name'] = member
|
||||
|
||||
validate_param_values(module, member_to_xpath_map)
|
||||
|
||||
want = map_params_to_obj(module, member_to_xpath_map)
|
||||
ele = map_obj_to_ele(module, want, top)
|
||||
diff = load_config(module, tostring(ele), warnings)
|
||||
|
||||
return diff
|
||||
|
||||
|
||||
def main():
|
||||
""" main entry point for module execution
|
||||
"""
|
||||
argument_spec = dict(
|
||||
name=dict(required=True),
|
||||
mode=dict(default='on', type='str', choices=['on', 'off', 'active', 'passive']),
|
||||
members=dict(type='list'),
|
||||
min_links=dict(type='int'),
|
||||
device_count=dict(type='int'),
|
||||
description=dict(default=DEFAULT_COMMENT),
|
||||
collection=dict(type='list'),
|
||||
purge=dict(type='bool'),
|
||||
state=dict(default='present', choices=['present', 'absent', 'up', 'down']),
|
||||
active=dict(default=True, type='bool')
|
||||
)
|
||||
|
||||
argument_spec.update(junos_argument_spec)
|
||||
required_one_of = [['name', 'collection']]
|
||||
mutually_exclusive = [['name', 'collection']]
|
||||
|
||||
module = AnsibleModule(argument_spec=argument_spec,
|
||||
required_one_of=required_one_of,
|
||||
mutually_exclusive=mutually_exclusive,
|
||||
supports_check_mode=True)
|
||||
|
||||
warnings = list()
|
||||
check_args(module, warnings)
|
||||
|
||||
result = {'changed': False}
|
||||
|
||||
if warnings:
|
||||
result['warnings'] = warnings
|
||||
|
||||
state = module.params.get('state')
|
||||
module.params['disable'] = True if state == 'down' else False
|
||||
|
||||
if state in ('present', 'up', 'down'):
|
||||
module.params['state'] = 'present'
|
||||
|
||||
else:
|
||||
module.params['disable'] = True
|
||||
|
||||
if module.params.get('mode') == 'off':
|
||||
module.params['mode'] = False
|
||||
elif module.params.get('mode') == 'on':
|
||||
module.params['mode'] = 'passive'
|
||||
|
||||
with locked_config(module):
|
||||
diff = configure_lag_params(module, warnings)
|
||||
diff = configure_member_params(module, warnings, diff)
|
||||
|
||||
commit = not module.check_mode
|
||||
if diff:
|
||||
if commit:
|
||||
commit_configuration(module)
|
||||
else:
|
||||
discard_changes(module)
|
||||
result['changed'] = True
|
||||
|
||||
if module._diff:
|
||||
result['diff'] = {'prepared': diff}
|
||||
|
||||
module.exit_json(**result)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@ -0,0 +1,2 @@
|
||||
---
|
||||
testcase: "*"
|
||||
@ -0,0 +1,2 @@
|
||||
---
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
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,252 @@
|
||||
---
|
||||
- debug: msg="START junos_linkagg netconf/basic.yaml"
|
||||
|
||||
- name: setup - remove linkagg
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
|
||||
- name: configure linkagg
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<name>ae0</name>' in config.xml"
|
||||
- "'<device-count>4</device-count>' in config.xml"
|
||||
- "'<bundle>ae0</bundle>' in config.xml"
|
||||
- "'<active/>' in config.xml"
|
||||
- "'<description>configured by junos_linkagg</description>' in config.xml"
|
||||
|
||||
- name: configure linkagg (idempotent)
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure lacp in passive
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: passive
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<passive/>' in config.xml"
|
||||
|
||||
- name: delete lacp
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: off
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<lacp/>' not in config.xml"
|
||||
|
||||
- name: Change device count
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
device_count: 2
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<device-count>2</device-count>' in config.xml"
|
||||
|
||||
- name: Disable linkagg interface
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
state: down
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<disable/>' in config.xml"
|
||||
- "'+ disable;' in result.diff.prepared"
|
||||
|
||||
- name: Enable linkagg interface
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
state: up
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<disable/>' not in config.xml"
|
||||
|
||||
- name: Deactivate linkagg
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
active: False
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<bundle inactive=\"inactive\">ae0</bundle>' in config.xml"
|
||||
- "'<device-count inactive=\"inactive\">4</device-count>' in config.xml"
|
||||
- "'inactive: ae0' in result.diff.prepared"
|
||||
|
||||
- name: Activate linkagg
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
active: True
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<active/>' in config.xml"
|
||||
- "'<bundle>ae0</bundle>' in config.xml"
|
||||
- "'active: device-count 4' in result.diff.prepared"
|
||||
- "'active: ae0' in result.diff.prepared"
|
||||
|
||||
- name: Delete linkagg
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<active/>' not in config.xml"
|
||||
- "'<bundle>ae0</bundle>' not in config.xml"
|
||||
- "'<device-count>4</device-count>' not in config.xml"
|
||||
- "'<name>ae0</name>' not in config.xml"
|
||||
|
||||
- name: Delete linkagg (idempotent)
|
||||
junos_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
@ -1,2 +1,3 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
---
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
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,181 @@
|
||||
---
|
||||
- debug: msg="START net_linkagg junos/basic.yaml"
|
||||
|
||||
- name: setup - remove linkagg
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
|
||||
- name: configure linkagg
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<name>ae0</name>' in config.xml"
|
||||
- "'<device-count>4</device-count>' in config.xml"
|
||||
- "'<bundle>ae0</bundle>' in config.xml"
|
||||
- "'<active/>' in config.xml"
|
||||
- "'<description>configured by junos_linkagg</description>' in config.xml"
|
||||
|
||||
- name: configure linkagg (idempotent)
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure lacp in passive
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: passive
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<passive/>' in config.xml"
|
||||
|
||||
- name: delete lacp
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: off
|
||||
device_count: 4
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<lacp/>' not in config.xml"
|
||||
|
||||
- name: Disable linkagg interface
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
state: down
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<disable/>' in config.xml"
|
||||
- "'+ disable;' in result.diff.prepared"
|
||||
|
||||
- name: Enable linkagg interface
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
state: up
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<disable/>' not in config.xml"
|
||||
|
||||
- name: Delete linkagg
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- name: Get running configuration
|
||||
junos_rpc:
|
||||
rpc: get-configuration
|
||||
provider: "{{ netconf }}"
|
||||
register: config
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<active/>' not in config.xml"
|
||||
- "'<bundle>ae0</bundle>' not in config.xml"
|
||||
- "'<device-count>4</device-count>' not in config.xml"
|
||||
- "'<name>ae0</name>' not in config.xml"
|
||||
|
||||
- name: Delete linkagg (idempotent)
|
||||
net_linkagg:
|
||||
name: ae0
|
||||
members:
|
||||
- ge-0/0/6
|
||||
- ge-0/0/7
|
||||
mode: active
|
||||
device_count: 4
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == false"
|
||||
@ -0,0 +1,3 @@
|
||||
---
|
||||
- include: "{{ role_path }}/tests/junos/basic.yaml"
|
||||
when: hostvars[inventory_hostname]['ansible_network_os'] == 'junos'
|
||||
Loading…
Reference in New Issue