mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-24 13:04:00 -07:00
IOS Ping: Add new module to support ping tests from IOS devices (#28557)
* IOS Ping: Add new module to support ping tests from IOS devices * Add tests * Add fixtures for ios_ping
This commit is contained in:
parent
11b1ad0928
commit
1c4fe510d0
10 changed files with 353 additions and 0 deletions
|
|
@ -94,6 +94,15 @@
|
|||
failed_modules: "{{ failed_modules }} + [ 'ios_logging' ]"
|
||||
test_failed: true
|
||||
|
||||
- block:
|
||||
- include_role:
|
||||
name: ios_ping
|
||||
when: "limit_to in ['*', 'ios_ping']"
|
||||
rescue:
|
||||
- set_fact:
|
||||
failed_modules: "{{ failed_modules }} + [ 'ios_ping' ]"
|
||||
test_failed: true
|
||||
|
||||
###########
|
||||
- debug: var=failed_modules
|
||||
when: test_failed
|
||||
|
|
|
|||
3
test/integration/targets/ios_ping/defaults/main.yaml
Normal file
3
test/integration/targets/ios_ping/defaults/main.yaml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
testcase: "*"
|
||||
test_items: []
|
||||
2
test/integration/targets/ios_ping/meta/main.yaml
Normal file
2
test/integration/targets/ios_ping/meta/main.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_ios_tests
|
||||
16
test/integration/targets/ios_ping/tasks/cli.yaml
Normal file
16
test/integration/targets/ios_ping/tasks/cli.yaml
Normal 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
|
||||
2
test/integration/targets/ios_ping/tasks/main.yaml
Normal file
2
test/integration/targets/ios_ping/tasks/main.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
31
test/integration/targets/ios_ping/tests/cli/ping.yaml
Normal file
31
test/integration/targets/ios_ping/tests/cli/ping.yaml
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
- debug: msg="START cli/ping.yaml"
|
||||
|
||||
- name: expected successful ping
|
||||
ios_ping: &valid_ip
|
||||
dest: '8.8.8.8'
|
||||
register: esp
|
||||
|
||||
- name: unexpected unsuccessful ping
|
||||
ios_ping: &invalid_ip
|
||||
dest: '10.255.255.250'
|
||||
timeout: 45
|
||||
register: uup
|
||||
|
||||
- name: unexpected successful ping
|
||||
ios_ping:
|
||||
<<: *valid_ip
|
||||
state: 'absent'
|
||||
register: usp
|
||||
|
||||
- name: expected unsuccessful ping
|
||||
ios_ping:
|
||||
<<: *invalid_ip
|
||||
state: 'absent'
|
||||
register: eup
|
||||
|
||||
- name: assert
|
||||
assert:
|
||||
that:
|
||||
- esp.failed == eup.failed == false
|
||||
- usp.failed == uup.failed == true
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Type escape sequence to abort.
|
||||
Sending 2, 100-byte ICMP Echos to 10.255.255.250, timeout is 2 seconds:
|
||||
..
|
||||
Success rate is 0 percent (0/2)
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
Type escape sequence to abort.
|
||||
Sending 2, 100-byte ICMP Echos to 8.8.8.8, timeout is 2 seconds:
|
||||
!!
|
||||
Success rate is 100 percent (2/2), round-trip min/avg/max = 25/25/25 ms
|
||||
70
test/units/modules/network/ios/test_ios_ping.py
Normal file
70
test/units/modules/network/ios/test_ios_ping.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#
|
||||
# (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
|
||||
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.modules.network.ios import ios_ping
|
||||
from .ios_module import TestIosModule, load_fixture, set_module_args
|
||||
|
||||
|
||||
class TestIosPingModule(TestIosModule):
|
||||
''' Class used for Unit Tests agains ios_ping module '''
|
||||
module = ios_ping
|
||||
|
||||
def setUp(self):
|
||||
self.mock_run_commands = patch('ansible.modules.network.ios.ios_ping.run_commands')
|
||||
self.run_commands = self.mock_run_commands.start()
|
||||
|
||||
def tearDown(self):
|
||||
self.mock_run_commands.stop()
|
||||
|
||||
def load_fixtures(self, commands=None):
|
||||
def load_from_file(*args, **kwargs):
|
||||
module = args
|
||||
commands = kwargs['commands']
|
||||
output = list()
|
||||
|
||||
for command in commands:
|
||||
filename = str(command).split(' | ')[0].replace(' ', '_')
|
||||
output.append(load_fixture('ios_ping_%s' % filename))
|
||||
return output
|
||||
|
||||
self.run_commands.side_effect = load_from_file
|
||||
|
||||
def test_ios_ping_expected_success(self):
|
||||
''' Test for successful pings when destination should be reachable '''
|
||||
set_module_args(dict(count=2, dest="8.8.8.8"))
|
||||
self.execute_module()
|
||||
|
||||
def test_ios_ping_expected_failure(self):
|
||||
''' Test for unsuccessful pings when destination should not be reachable '''
|
||||
set_module_args(dict(count=2, dest="10.255.255.250", state="absent", timeout=45))
|
||||
self.execute_module()
|
||||
|
||||
def test_ios_ping_unexpected_success(self):
|
||||
''' Test for successful pings when destination should not be reachable - FAIL. '''
|
||||
set_module_args(dict(count=2, dest="8.8.8.8", state="absent"))
|
||||
self.execute_module(failed=True)
|
||||
|
||||
def test_ios_ping_unexpected_failure(self):
|
||||
''' Test for unsuccessful pings when destination should be reachable - FAIL. '''
|
||||
set_module_args(dict(count=2, dest="10.255.255.250", timeout=45))
|
||||
self.execute_module(failed=True)
|
||||
Loading…
Add table
Add a link
Reference in a new issue