Add iosxr_user implementation module (#25615)

* Add iosxr_user implementation module

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* iosxr_user Integration test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* iosxr_user Unit test

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>

* Modify integration test with idempotent case

Signed-off-by: Trishna Guha <trishnaguha17@gmail.com>
This commit is contained in:
Trishna Guha
2017-06-15 22:07:03 +05:30
committed by GitHub
parent b3c22a96bd
commit 44687bb917
9 changed files with 488 additions and 0 deletions

View File

@@ -13,3 +13,4 @@
- { role: iosxr_facts, when: "limit_to in ['*', 'iosxr_facts']" }
- { role: iosxr_template, when: "limit_to in ['*', 'iosxr_template']" }
- { role: iosxr_system, when: "limit_to in ['*', 'iosxr_system']" }
- { role: iosxr_user, when: "limit_to in ['*', 'iosxr_user']" }

View File

@@ -0,0 +1,3 @@
---
testcase: "*"
test_items: []

View File

@@ -0,0 +1,2 @@
dependencies:
- prepare_iosxr_tests

View File

@@ -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

View File

@@ -0,0 +1,2 @@
---
- { include: cli.yaml, tags: ['cli'] }

View File

@@ -0,0 +1,71 @@
---
- name: Create user (SetUp)
iosxr_user:
name: ansibletest1
password: test
state: present
provider: "{{ cli }}"
register: result
- assert:
that:
- 'result.changed == true'
- '"username ansibletest1 secret" in result.commands'
- name: Collection of users (SetUp)
iosxr_user:
users:
- name: ansibletest2
- name: ansibletest3
state: present
group: sysadmin
provider: "{{ cli }}"
register: result
- assert:
that:
- 'result.changed == true'
- 'result.commands == ["username ansibletest2 group sysadmin", "username ansibletest3 group sysadmin"]'
- name: Add user again (Idempotent)
iosxr_user:
name: ansibletest1
password: test
state: present
provider: "{{ cli }}"
register: result
- assert:
that:
- 'result.changed == false'
- 'result.commands | length == 0'
- name: Add collection of users again (Idempotent)
iosxr_user:
users:
- name: ansibletest2
- name: ansibletest3
state: present
group: sysadmin
provider: "{{ cli }}"
register: result
- assert:
that:
- 'result.changed == false'
- 'result.commands | length == 0'
- name: tearDown
iosxr_user:
users:
- name: ansibletest1
- name: ansibletest2
- name: ansibletest3
state: absent
provider: "{{ cli }}"
register: result
- assert:
that:
- 'result.changed == true'
- 'result.commands == ["no username ansibletest1", "no username ansibletest2", "no username ansibletest3"]'

View File

@@ -0,0 +1,2 @@
username admin secret 5 $1$mdQIUxjg$3t3lzBpfKfITKvFm1uEIY. group sysadmin
username ansible secret 5 $1$3yWSXiIi$VdzV59ChiurrNdGxlDeAW/ group sysadmin

View File

@@ -0,0 +1,80 @@
# (c) 2016 Red Hat Inc.
#
# This file is part of Ansible
#
# 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/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from ansible.compat.tests.mock import patch
from ansible.modules.network.iosxr import iosxr_user
from .iosxr_module import TestIosxrModule, load_fixture, set_module_args
class TestIosxrUserModule(TestIosxrModule):
module = iosxr_user
def setUp(self):
self.mock_get_config = patch('ansible.modules.network.iosxr.iosxr_user.get_config')
self.get_config = self.mock_get_config.start()
self.mock_load_config = patch('ansible.modules.network.iosxr.iosxr_user.load_config')
self.load_config = self.mock_load_config.start()
def tearDown(self):
self.mock_get_config.stop()
self.mock_load_config.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')
def test_iosxr_user_delete(self):
set_module_args(dict(name='ansible', state='absent'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['no username ansible'])
def test_iosxr_user_password(self):
set_module_args(dict(name='ansible', password='test'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible secret test'])
def test_iosxr_user_purge(self):
set_module_args(dict(purge=True))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['no username ansible'])
def test_iosxr_user_group(self):
set_module_args(dict(name='ansible', group='sysadmin'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible group sysadmin'])
def test_iosxr_user_update_password_changed(self):
set_module_args(dict(name='test', password='test', update_password='on_create'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username test secret test'])
def test_iosxr_user_update_password_on_create_ok(self):
set_module_args(dict(name='ansible', password='test', update_password='on_create'))
self.execute_module()
def test_iosxr_user_update_password_always(self):
set_module_args(dict(name='ansible', password='test', update_password='always'))
result = self.execute_module(changed=True)
self.assertEqual(result['commands'], ['username ansible secret test'])