diff options
author | Trishna Guha <trishnaguha17@gmail.com> | 2017-06-06 20:05:08 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-06 20:05:08 +0530 |
commit | f6a4803669548f3c4fdfd8fc26b8264e46fdc1f1 (patch) | |
tree | ca287d727465ae00405b545534d438b504106b94 /test/integration/targets | |
parent | 15104acc007be20cb6e7b3f51b592b00075f3f85 (diff) | |
download | ansible-f6a4803669548f3c4fdfd8fc26b8264e46fdc1f1.tar.gz |
New module: platform agnostic way to manage local users on network devices (network/net_user.) (#25259)
* Add net_user platform agnostic module
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
* Integration test for net_user
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
* modify eos_user module to support name param as alias to username
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
* Test collection of users
Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
Diffstat (limited to 'test/integration/targets')
12 files changed, 143 insertions, 0 deletions
diff --git a/test/integration/targets/net_user/aliases b/test/integration/targets/net_user/aliases new file mode 100644 index 0000000000..93151a8d9d --- /dev/null +++ b/test/integration/targets/net_user/aliases @@ -0,0 +1 @@ +network/ci diff --git a/test/integration/targets/net_user/defaults/main.yaml b/test/integration/targets/net_user/defaults/main.yaml new file mode 100644 index 0000000000..5f709c5aac --- /dev/null +++ b/test/integration/targets/net_user/defaults/main.yaml @@ -0,0 +1,2 @@ +--- +testcase: "*" diff --git a/test/integration/targets/net_user/tasks/cli.yaml b/test/integration/targets/net_user/tasks/cli.yaml new file mode 100644 index 0000000000..46d86dd698 --- /dev/null +++ b/test/integration/targets/net_user/tasks/cli.yaml @@ -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 diff --git a/test/integration/targets/net_user/tasks/main.yaml b/test/integration/targets/net_user/tasks/main.yaml new file mode 100644 index 0000000000..415c99d8b1 --- /dev/null +++ b/test/integration/targets/net_user/tasks/main.yaml @@ -0,0 +1,2 @@ +--- +- { include: cli.yaml, tags: ['cli'] } diff --git a/test/integration/targets/net_user/tests/cli/userprivilege.yaml b/test/integration/targets/net_user/tests/cli/userprivilege.yaml new file mode 100644 index 0000000000..3a2ae58d61 --- /dev/null +++ b/test/integration/targets/net_user/tests/cli/userprivilege.yaml @@ -0,0 +1,3 @@ +--- +- include: "{{ role_path }}/tests/eos/userprivilege.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos' diff --git a/test/integration/targets/net_user/tests/cli/userrole.yaml b/test/integration/targets/net_user/tests/cli/userrole.yaml new file mode 100644 index 0000000000..bc2254280c --- /dev/null +++ b/test/integration/targets/net_user/tests/cli/userrole.yaml @@ -0,0 +1,6 @@ +--- +- include: "{{ role_path }}/tests/nxos/userrole.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'nxos' + +- include: "{{ role_path }}/tests/eos/userrole.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos' diff --git a/test/integration/targets/net_user/tests/cli/users.yaml b/test/integration/targets/net_user/tests/cli/users.yaml new file mode 100644 index 0000000000..bd3de7894b --- /dev/null +++ b/test/integration/targets/net_user/tests/cli/users.yaml @@ -0,0 +1,6 @@ +--- +- include: "{{ role_path }}/tests/nxos/users.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'nxos' + +- include: "{{ role_path }}/tests/eos/users.yaml" + when: hostvars[inventory_hostname]['ansible_network_os'] == 'eos' diff --git a/test/integration/targets/net_user/tests/eos/userprivilege.yaml b/test/integration/targets/net_user/tests/eos/userprivilege.yaml new file mode 100644 index 0000000000..9ad6b67bbf --- /dev/null +++ b/test/integration/targets/net_user/tests/eos/userprivilege.yaml @@ -0,0 +1,19 @@ +--- +- name: Set user to privilege level 15 + net_user: + name: netop + privilege: 15 + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["username netop privilege 15"]' + +- name: tearDown + net_user: + purge: yes + provider: "{{ cli }}" diff --git a/test/integration/targets/net_user/tests/eos/userrole.yaml b/test/integration/targets/net_user/tests/eos/userrole.yaml new file mode 100644 index 0000000000..b85806a08f --- /dev/null +++ b/test/integration/targets/net_user/tests/eos/userrole.yaml @@ -0,0 +1,22 @@ +--- +- name: Set multiple users role + net_user: + collection: + - name: netop + - name: netend + role: network-operator + state: present + authorize: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["username netop role network-operator", "username netend role network-operator"]' + +- name: tearDown + net_user: + purge: yes + authorize: yes + provider: "{{ cli }}" diff --git a/test/integration/targets/net_user/tests/eos/users.yaml b/test/integration/targets/net_user/tests/eos/users.yaml new file mode 100644 index 0000000000..2719173d9e --- /dev/null +++ b/test/integration/targets/net_user/tests/eos/users.yaml @@ -0,0 +1,23 @@ +--- +- name: Create user + net_user: + name: netop + state: present + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["username netop"]' + +- name: Purge users + net_user: + purge: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["no username netop"]' diff --git a/test/integration/targets/net_user/tests/nxos/userrole.yaml b/test/integration/targets/net_user/tests/nxos/userrole.yaml new file mode 100644 index 0000000000..cd49e8e36d --- /dev/null +++ b/test/integration/targets/net_user/tests/nxos/userrole.yaml @@ -0,0 +1,20 @@ +--- +- name: Set multiple users role + net_user: + collection: + - name: netop + - name: netend + role: network-operator + state: present + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - '"role network-operator" in result.commands' + +- name: tearDown + net_user: + purge: yes + provider: "{{ cli }}" diff --git a/test/integration/targets/net_user/tests/nxos/users.yaml b/test/integration/targets/net_user/tests/nxos/users.yaml new file mode 100644 index 0000000000..2719173d9e --- /dev/null +++ b/test/integration/targets/net_user/tests/nxos/users.yaml @@ -0,0 +1,23 @@ +--- +- name: Create user + net_user: + name: netop + state: present + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["username netop"]' + +- name: Purge users + net_user: + purge: yes + provider: "{{ cli }}" + register: result + +- assert: + that: + - 'result.changed == true' + - 'result.commands == ["no username netop"]' |