mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 05:12:45 +00:00
ios_ntp module (#50705)
* ios_ntp module * add execute_module for config func * fix units test * test empty list * update example * change want logic to follow have - removed try/except * update commands list for config test * add idempotent test case * add more test
This commit is contained in:
committed by
Nathaniel Case
parent
004d8b03d4
commit
f94378fc2f
2
test/integration/targets/ios_ntp/defaults/main.yaml
Normal file
2
test/integration/targets/ios_ntp/defaults/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
testcase: "*"
|
||||
2
test/integration/targets/ios_ntp/meta/main.yml
Normal file
2
test/integration/targets/ios_ntp/meta/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
- prepare_ios_tests
|
||||
22
test/integration/targets/ios_ntp/tasks/cli.yaml
Normal file
22
test/integration/targets/ios_ntp/tasks/cli.yaml
Normal file
@@ -0,0 +1,22 @@
|
||||
---
|
||||
- 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 cases (connection=network_cli)
|
||||
include: "{{ test_case_to_run }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
|
||||
- name: run test case (connection=local)
|
||||
include: "{{ test_case_to_run }} ansible_connection=local"
|
||||
with_first_found: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
||||
2
test/integration/targets/ios_ntp/tasks/main.yaml
Normal file
2
test/integration/targets/ios_ntp/tasks/main.yaml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
@@ -0,0 +1,75 @@
|
||||
---
|
||||
- name: remove NTP (if set)
|
||||
ios_ntp:
|
||||
server: 10.75.32.5
|
||||
source_int: Loopback0
|
||||
acl: NTP_ACL
|
||||
logging: true
|
||||
key_id: 10
|
||||
auth_key: 15435A030726242723273C21181319000A
|
||||
auth: true
|
||||
state: absent
|
||||
ignore_errors: true
|
||||
|
||||
- block:
|
||||
|
||||
- name: configure NTP
|
||||
ios_ntp: &config
|
||||
server: 10.75.32.5
|
||||
source_int: Loopback0
|
||||
state: present
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: idempotence check
|
||||
ios_ntp: *config
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
- name: configure NTP
|
||||
ios_ntp: &config1
|
||||
acl: NTP_ACL
|
||||
logging: true
|
||||
state: present
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: idempotence check
|
||||
ios_ntp: *config1
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: configure NTP with diffferen values
|
||||
ios_ntp: &config2
|
||||
key_id: 10
|
||||
auth_key: 15435A030726242723273C21181319000A
|
||||
auth: true
|
||||
state: present
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: idempotence check
|
||||
ios_ntp: *config2
|
||||
|
||||
- assert: *false
|
||||
|
||||
- name: remove part of config
|
||||
ios_ntp: &config3
|
||||
acl: NTP_ACL
|
||||
logging: true
|
||||
state: absent
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: idempotence check
|
||||
ios_ntp: *config3
|
||||
|
||||
- assert: *false
|
||||
|
||||
always:
|
||||
- name: Remove ntp config
|
||||
ios_ntp: *remove
|
||||
@@ -0,0 +1,7 @@
|
||||
ntp logging
|
||||
ntp authentication-key 10 md5 15435A030726242723273C21181319000A 7
|
||||
ntp authenticate
|
||||
ntp trusted-key 10
|
||||
ntp source Loopback0
|
||||
ntp access-group peer NTP_ACL
|
||||
ntp server 10.75.32.5
|
||||
99
test/units/modules/network/ios/test_ios_ntp.py
Normal file
99
test/units/modules/network/ios/test_ios_ntp.py
Normal file
@@ -0,0 +1,99 @@
|
||||
# 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
|
||||
|
||||
from units.compat.mock import patch
|
||||
from ansible.modules.network.ios import ios_ntp
|
||||
from units.modules.utils import set_module_args
|
||||
from .ios_module import TestIosModule, load_fixture
|
||||
|
||||
|
||||
class TestIosNtpModule(TestIosModule):
|
||||
|
||||
module = ios_ntp
|
||||
|
||||
def setUp(self):
|
||||
super(TestIosNtpModule, self).setUp()
|
||||
|
||||
self.mock_get_config = patch('ansible.modules.network.ios.ios_ntp.get_config')
|
||||
self.get_config = self.mock_get_config.start()
|
||||
|
||||
self.mock_load_config = patch('ansible.modules.network.ios.ios_ntp.load_config')
|
||||
self.load_config = self.mock_load_config.start()
|
||||
|
||||
def tearDown(self):
|
||||
super(TestIosNtpModule, self).tearDown()
|
||||
self.mock_get_config.stop()
|
||||
self.mock_load_config.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
self.get_config.return_value = load_fixture('ios_ntp_config.cfg').strip()
|
||||
self.load_config.return_value = dict(diff=None, session='session')
|
||||
|
||||
def test_ios_ntp_idempotent(self):
|
||||
set_module_args(dict(
|
||||
server='10.75.32.5',
|
||||
source_int='Loopback0',
|
||||
acl='NTP_ACL',
|
||||
logging=True,
|
||||
auth=True,
|
||||
auth_key='15435A030726242723273C21181319000A',
|
||||
key_id='10',
|
||||
state='present'
|
||||
))
|
||||
commands = []
|
||||
self.execute_module(changed=False, commands=commands)
|
||||
|
||||
def test_ios_ntp_config(self):
|
||||
set_module_args(dict(
|
||||
server='10.75.33.5',
|
||||
source_int='Vlan2',
|
||||
acl='NTP_ACL',
|
||||
logging=True,
|
||||
auth=True,
|
||||
auth_key='15435A030726242723273C21181319000A',
|
||||
key_id='10',
|
||||
state='present'
|
||||
))
|
||||
commands = [
|
||||
'ntp server 10.75.33.5',
|
||||
'ntp source Vlan2'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
|
||||
def test_ios_ntp_remove(self):
|
||||
set_module_args(dict(
|
||||
server='10.75.32.5',
|
||||
source_int='Loopback0',
|
||||
acl='NTP_ACL',
|
||||
logging=True,
|
||||
auth=True,
|
||||
auth_key='15435A030726242723273C21181319000A',
|
||||
key_id='10',
|
||||
state='absent'
|
||||
))
|
||||
commands = [
|
||||
'no ntp server 10.75.32.5',
|
||||
'no ntp source Loopback0',
|
||||
'no ntp access-group peer NTP_ACL',
|
||||
'no ntp logging',
|
||||
'no ntp authenticate',
|
||||
'no ntp trusted-key 10',
|
||||
'no ntp authentication-key 10 md5 15435A030726242723273C21181319000A 7'
|
||||
]
|
||||
self.execute_module(changed=True, commands=commands)
|
||||
Reference in New Issue
Block a user