mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 05:12:45 +00:00
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 failure
This commit is contained in:
@@ -106,6 +106,13 @@
|
||||
rescue:
|
||||
- set_fact: test_failed=true
|
||||
|
||||
- block:
|
||||
- include_role:
|
||||
name: junos_linkagg
|
||||
when: "limit_to in ['*', 'junos_linkagg']"
|
||||
rescue:
|
||||
- set_fact: test_failed=true
|
||||
|
||||
###########
|
||||
- name: Has any previous test failed?
|
||||
fail:
|
||||
|
||||
@@ -31,6 +31,16 @@
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: confirm previous commit
|
||||
junos_config:
|
||||
confirm_commit: yes
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: teardown
|
||||
junos_config:
|
||||
lines:
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
---
|
||||
testcase: "*"
|
||||
2
test/integration/targets/junos_linkagg/tasks/main.yaml
Normal file
2
test/integration/targets/junos_linkagg/tasks/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
16
test/integration/targets/junos_linkagg/tasks/netconf.yaml
Normal file
16
test/integration/targets/junos_linkagg/tasks/netconf.yaml
Normal file
@@ -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
|
||||
252
test/integration/targets/junos_linkagg/tests/netconf/basic.yaml
Normal file
252
test/integration/targets/junos_linkagg/tests/netconf/basic.yaml
Normal file
@@ -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"
|
||||
@@ -71,7 +71,7 @@
|
||||
that:
|
||||
- "result.changed == true"
|
||||
- "'<route inactive=\"inactive\">' in config.xml"
|
||||
- "'inactive: route 1.1.1.0/24' in result.diff"
|
||||
- "'inactive: route 1.1.1.0/24' in result.diff.prepared"
|
||||
|
||||
- name: Activate static route
|
||||
junos_static_route:
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
|
||||
16
test/integration/targets/net_linkagg/tasks/netconf.yaml
Normal file
16
test/integration/targets/net_linkagg/tasks/netconf.yaml
Normal file
@@ -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
|
||||
181
test/integration/targets/net_linkagg/tests/junos/basic.yaml
Normal file
181
test/integration/targets/net_linkagg/tests/junos/basic.yaml
Normal file
@@ -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'
|
||||
@@ -36,6 +36,15 @@ class TestJunosConfigModule(TestJunosModule):
|
||||
self.mock_load_config = patch('ansible.modules.network.junos.junos_config.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.junos.lock_configuration')
|
||||
self.lock_configuration = self.mock_lock_configuration.start()
|
||||
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.junos.unlock_configuration')
|
||||
self.unlock_configuration = self.mock_unlock_configuration.start()
|
||||
|
||||
self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_config.commit_configuration')
|
||||
self.commit_configuration = self.mock_commit_configuration.start()
|
||||
|
||||
self.mock_get_diff = patch('ansible.modules.network.junos.junos_config.get_diff')
|
||||
self.get_diff = self.mock_get_diff.start()
|
||||
|
||||
@@ -45,6 +54,10 @@ class TestJunosConfigModule(TestJunosModule):
|
||||
def tearDown(self):
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_lock_configuration.stop()
|
||||
self.mock_unlock_configuration.stop()
|
||||
self.mock_commit_configuration.stop()
|
||||
self.mock_get_diff.stop()
|
||||
self.mock_send_request.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, format='text', changed=False):
|
||||
@@ -83,8 +96,8 @@ class TestJunosConfigModule(TestJunosModule):
|
||||
def test_junos_config_confirm(self):
|
||||
src = load_fixture('junos_config.set', content='str')
|
||||
set_module_args(dict(src=src, confirm=40))
|
||||
self.execute_module()
|
||||
args, kwargs = self.load_config.call_args
|
||||
self.execute_module(changed=True)
|
||||
args, kwargs = self.commit_configuration.call_args
|
||||
self.assertEqual(kwargs['confirm_timeout'], 40)
|
||||
|
||||
def test_junos_config_rollback(self):
|
||||
@@ -144,3 +157,8 @@ class TestJunosConfigModule(TestJunosModule):
|
||||
self.execute_module()
|
||||
args, kwargs = self.load_config.call_args
|
||||
self.assertEqual(kwargs['format'], 'xml')
|
||||
|
||||
def test_junos_config_confirm_commit(self):
|
||||
set_module_args(dict(confirm_commit=True))
|
||||
self.execute_module(changed=True)
|
||||
self.assertEqual(self.commit_configuration.call_count, 1)
|
||||
|
||||
@@ -34,8 +34,20 @@ class TestJunosCommandModule(TestJunosModule):
|
||||
self.mock_exec_command = patch('ansible.modules.network.junos.junos_netconf.exec_command')
|
||||
self.exec_command = self.mock_exec_command.start()
|
||||
|
||||
self.mock_lock_configuration = patch('ansible.module_utils.junos.lock_configuration')
|
||||
self.lock_configuration = self.mock_lock_configuration.start()
|
||||
|
||||
self.mock_unlock_configuration = patch('ansible.module_utils.junos.unlock_configuration')
|
||||
self.unlock_configuration = self.mock_unlock_configuration.start()
|
||||
|
||||
self.mock_commit_configuration = patch('ansible.modules.network.junos.junos_netconf.commit_configuration')
|
||||
self.commit_configuration = self.mock_commit_configuration.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_exec_command.stop()
|
||||
self.mock_lock_configuration.stop()
|
||||
self.mock_unlock_configuration.stop()
|
||||
self.mock_commit_configuration.stop()
|
||||
|
||||
def test_junos_netconf_enable(self):
|
||||
self.exec_command.return_value = 0, '', None
|
||||
|
||||
Reference in New Issue
Block a user