mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-22 00:00:22 -07:00
iosxr_user refactor for cliconf and netconf (#34892)
* * refactor iosxr_user for cliconf and netconf (cherry picked from commit 5d0994ef598f1601fca00a0c1eff4ebb05ebbf1b) * * Purge and units test changes
This commit is contained in:
parent
db61f8f967
commit
0f692f1fe7
9 changed files with 669 additions and 274 deletions
|
@ -4,13 +4,6 @@
|
|||
# Add minimal testcase to check args are passed correctly to
|
||||
# implementation module and module run is successful.
|
||||
|
||||
- name: Enable Netconf service
|
||||
iosxr_netconf:
|
||||
netconf_port: 830
|
||||
netconf_vrf: 'default'
|
||||
state: present
|
||||
register: result
|
||||
|
||||
- name: Setup interface
|
||||
net_interface:
|
||||
name: GigabitEthernet0/0/0/1
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
---
|
||||
- name: collect all common test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/common"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: common_test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: collect all cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
|
@ -6,6 +13,10 @@
|
|||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- set_fact:
|
||||
test_cases:
|
||||
files: "{{ common_test_cases.files }} + {{ test_cases.files }}"
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
|
|
|
@ -1,2 +1,3 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
- { include: netconf.yaml, tags: ['netconf'] }
|
||||
|
|
33
test/integration/targets/iosxr_user/tasks/netconf.yaml
Normal file
33
test/integration/targets/iosxr_user/tasks/netconf.yaml
Normal file
|
@ -0,0 +1,33 @@
|
|||
---
|
||||
- name: collect all common test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/common"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: common_test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- name: collect all netconf test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/netconf"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
delegate_to: localhost
|
||||
|
||||
- set_fact:
|
||||
test_cases:
|
||||
files: "{{ common_test_cases.files }} + {{ test_cases.files }}"
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case (connection=local)
|
||||
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
|
||||
#- name: run test case (connection=netconf)
|
||||
#include: "{{ test_case_to_run }} ansible_connection=network_cli"
|
||||
#with_items: "{{ test_items }}"
|
||||
#loop_control:
|
||||
# loop_var: test_case_to_run
|
170
test/integration/targets/iosxr_user/tests/netconf/basic.yaml
Normal file
170
test/integration/targets/iosxr_user/tests/netconf/basic.yaml
Normal file
|
@ -0,0 +1,170 @@
|
|||
---
|
||||
- name: Remove users prior to tests
|
||||
iosxr_config:
|
||||
lines:
|
||||
- no username ansible1
|
||||
- no username ansible2
|
||||
- no username ansible3
|
||||
provider: "{{ cli }}"
|
||||
|
||||
- name: Create user (SetUp)
|
||||
iosxr_user:
|
||||
name: ansible1
|
||||
configured_password: password
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible1" in result.xml[0]'
|
||||
- '"secret" in result.xml[0]'
|
||||
|
||||
- name: Create user with update_password always (not idempotent)
|
||||
iosxr_user:
|
||||
name: ansible1
|
||||
configured_password: password
|
||||
update_password: always
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible1" in result.xml[0]'
|
||||
- '"secret" in result.xml[0]'
|
||||
|
||||
- name: Create user again with update_password on_create (idempotent)
|
||||
iosxr_user:
|
||||
name: ansible1
|
||||
configured_password: password
|
||||
update_password: on_create
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- 'result.xml | length == 0'
|
||||
|
||||
- name: Modify user group
|
||||
iosxr_user:
|
||||
name: ansible1
|
||||
configured_password: password
|
||||
update_password: on_create
|
||||
group: sysadmin
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible1" in result.xml[0]'
|
||||
- '"sysadmin" in result.xml[0]'
|
||||
|
||||
- name: Modify user group again (idempotent)
|
||||
iosxr_user:
|
||||
name: ansible1
|
||||
configured_password: password
|
||||
update_password: on_create
|
||||
group: sysadmin
|
||||
state: present
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- 'result.xml | length == 0'
|
||||
|
||||
- name: Collection of users (SetUp)
|
||||
iosxr_user:
|
||||
aggregate:
|
||||
- name: ansible2
|
||||
- name: ansible3
|
||||
configured_password: password
|
||||
state: present
|
||||
group: sysadmin
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible2" in result.xml[0]'
|
||||
- '"secret" in result.xml[0]'
|
||||
- '"sysadmin" in result.xml[1]'
|
||||
- '"ansible2" in result.xml[0]'
|
||||
- '"secret" in result.xml[0]'
|
||||
- '"sysadmin" in result.xml[1]'
|
||||
|
||||
- name: Add collection of users again with update_password always (not idempotent)
|
||||
iosxr_user:
|
||||
aggregate:
|
||||
- name: ansible2
|
||||
- name: ansible3
|
||||
configured_password: password
|
||||
state: present
|
||||
group: sysadmin
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible2" in result.xml[0]'
|
||||
- '"ansible3" in result.xml[0]'
|
||||
- '"secret" in result.xml[0]'
|
||||
|
||||
- name: Add collection of users again with update_password on_create (idempotent)
|
||||
iosxr_user:
|
||||
aggregate:
|
||||
- name: ansible2
|
||||
- name: ansible3
|
||||
configured_password: password
|
||||
update_password: on_create
|
||||
state: present
|
||||
group: sysadmin
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- 'result.xml | length == 0'
|
||||
|
||||
- name: Delete collection of users
|
||||
iosxr_user:
|
||||
aggregate:
|
||||
- name: ansible1
|
||||
- name: ansible2
|
||||
- name: ansible3
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == true'
|
||||
- '"ansible1" in result.xml[0]'
|
||||
- '"ansible2" in result.xml[0]'
|
||||
- '"ansible3" in result.xml[0]'
|
||||
|
||||
- name: Delete collection of users again (idempotent)
|
||||
iosxr_user:
|
||||
aggregate:
|
||||
- name: ansible1
|
||||
- name: ansible2
|
||||
- name: ansible3
|
||||
state: absent
|
||||
provider: "{{ netconf }}"
|
||||
register: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- 'result.changed == false'
|
||||
- 'result.xml | length == 0'
|
|
@ -38,15 +38,20 @@ class TestIosxrUserModule(TestIosxrModule):
|
|||
self.mock_load_config = patch('ansible.modules.network.iosxr.iosxr_user.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
self.mock_is_cliconf = patch('ansible.modules.network.iosxr.iosxr_user.is_cliconf')
|
||||
self.is_cliconf = self.mock_is_cliconf.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestIosxrUserModule, self).tearDown()
|
||||
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
self.mock_is_cliconf.stop()
|
||||
|
||||
def load_fixtures(self, commands=None, transport='cli'):
|
||||
self.get_config.return_value = load_fixture('iosxr_user_config.cfg')
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
self.is_cliconf.return_value = True
|
||||
|
||||
def test_iosxr_user_delete(self):
|
||||
set_module_args(dict(name='ansible', state='absent'))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue