Fix nxos_snmp_host bug (#32916)
* Fix nxos_snmp_host bug * Enable nxos_snmp_host tests
This commit is contained in:
parent
3f3c526026
commit
208208ab8f
10 changed files with 271 additions and 2 deletions
|
@ -102,6 +102,7 @@ commands:
|
|||
'''
|
||||
|
||||
|
||||
import re
|
||||
from ansible.module_utils.nxos import load_config, run_commands
|
||||
from ansible.module_utils.nxos import nxos_argument_spec, check_args
|
||||
from ansible.module_utils.basic import AnsibleModule
|
||||
|
@ -173,7 +174,9 @@ def get_snmp_host(host, module):
|
|||
host_resource = apply_key_map(host_map, each)
|
||||
|
||||
if src:
|
||||
host_resource['src_intf'] = src.split(':')[1].strip()
|
||||
host_resource['src_intf'] = src
|
||||
if re.search(r'interface:', src):
|
||||
host_resource['src_intf'] = src.split(':')[1].strip()
|
||||
|
||||
vrf_filt = each.get('TABLE_vrf_filters')
|
||||
if vrf_filt:
|
||||
|
@ -199,7 +202,9 @@ def get_snmp_host(host, module):
|
|||
host_resource = apply_key_map(host_map_5k, each)
|
||||
|
||||
if src:
|
||||
host_resource['src_intf'] = src.split(':')[1].strip()
|
||||
host_resource['src_intf'] = src
|
||||
if re.search(r'interface:', src):
|
||||
host_resource['src_intf'] = src.split(':')[1].strip()
|
||||
|
||||
vrf_filt = each.get('TABLE_filter_vrf')
|
||||
if vrf_filt:
|
||||
|
|
|
@ -482,6 +482,15 @@
|
|||
failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_location' ]"
|
||||
test_failed: true
|
||||
|
||||
- block:
|
||||
- include_role:
|
||||
name: nxos_snmp_host
|
||||
when: "limit_to in ['*', 'nxos_snmp_host']"
|
||||
rescue:
|
||||
- set_fact:
|
||||
failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_host' ]"
|
||||
test_failed: true
|
||||
|
||||
###########
|
||||
- debug: var=failed_modules
|
||||
when: test_failed
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
---
|
||||
testcase: "*"
|
2
test/integration/targets/nxos_snmp_host/meta/main.yml
Normal file
2
test/integration/targets/nxos_snmp_host/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- prepare_nxos_tests
|
25
test/integration/targets/nxos_snmp_host/tasks/cli.yaml
Normal file
25
test/integration/targets/nxos_snmp_host/tasks/cli.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: collect common cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/common"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
|
||||
- name: collect cli test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/cli"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: cli_cases
|
||||
|
||||
- set_fact:
|
||||
test_cases:
|
||||
files: "{{ test_cases.files }} + {{ cli_cases.files }}"
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case
|
||||
include: "{{ test_case_to_run }} connection={{ cli }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
7
test/integration/targets/nxos_snmp_host/tasks/main.yaml
Normal file
7
test/integration/targets/nxos_snmp_host/tasks/main.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
# Use block to ensure that both cli and nxapi tests
|
||||
# will run even if there are failures or errors.
|
||||
- block:
|
||||
- { include: cli.yaml, tags: ['cli'] }
|
||||
always:
|
||||
- { include: nxapi.yaml, tags: ['nxapi'] }
|
25
test/integration/targets/nxos_snmp_host/tasks/nxapi.yaml
Normal file
25
test/integration/targets/nxos_snmp_host/tasks/nxapi.yaml
Normal file
|
@ -0,0 +1,25 @@
|
|||
---
|
||||
- name: collect common nxapi test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/common"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: test_cases
|
||||
|
||||
- name: collect nxapi test cases
|
||||
find:
|
||||
paths: "{{ role_path }}/tests/nxapi"
|
||||
patterns: "{{ testcase }}.yaml"
|
||||
register: nxapi_cases
|
||||
|
||||
- set_fact:
|
||||
test_cases:
|
||||
files: "{{ test_cases.files }} + {{ nxapi_cases.files }}"
|
||||
|
||||
- name: set test_items
|
||||
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
|
||||
|
||||
- name: run test case
|
||||
include: "{{ test_case_to_run }} connection={{ nxapi }}"
|
||||
with_items: "{{ test_items }}"
|
||||
loop_control:
|
||||
loop_var: test_case_to_run
|
|
@ -0,0 +1,64 @@
|
|||
---
|
||||
- set_fact: snmp_type="trap"
|
||||
- set_fact: snmp_version="v2c"
|
||||
|
||||
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
||||
|
||||
# Select interface for test
|
||||
- set_fact: intname="{{ nxos_int1 }}"
|
||||
when: not (platform | match("N5K"))
|
||||
|
||||
- name: Setup - Remove snmp_host if configured
|
||||
nxos_snmp_host: &remove
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
src_intf: "{{ intname|default(omit) }}"
|
||||
state: absent
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- block:
|
||||
|
||||
- name: Configure snmp host
|
||||
nxos_snmp_host: &config
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
src_intf: "{{ intname|default(omit) }}"
|
||||
state: present
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Idempotence Check
|
||||
nxos_snmp_host: *config
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: Cleanup
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Cleanup Idempotence
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
|
@ -0,0 +1,69 @@
|
|||
---
|
||||
- set_fact: snmp_type="inform"
|
||||
- set_fact: snmp_version="v3"
|
||||
- set_fact: snmp_auth="noauth"
|
||||
|
||||
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
||||
|
||||
# Select interface for test
|
||||
- set_fact: intname="{{ nxos_int1 }}"
|
||||
when: not (platform | match("N5K"))
|
||||
|
||||
- name: Setup - Remove snmp_host if configured
|
||||
nxos_snmp_host: &remove
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
v3: "{{ snmp_auth|default(omit) }}"
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
src_intf: "{{ intname|default(omit) }}"
|
||||
state: absent
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- block:
|
||||
|
||||
- name: Configure snmp host
|
||||
nxos_snmp_host: &config
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
v3: "{{ snmp_auth|default(omit) }}"
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
src_intf: "{{ intname|default(omit) }}"
|
||||
state: present
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Idempotence Check
|
||||
nxos_snmp_host: *config
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
when: not (platform | match('N35'))
|
||||
|
||||
always:
|
||||
- name: Cleanup
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Cleanup Idempotence
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
|
@ -0,0 +1,61 @@
|
|||
---
|
||||
- set_fact: snmp_type="trap"
|
||||
- set_fact: snmp_version="v3"
|
||||
- set_fact: snmp_auth="noauth"
|
||||
|
||||
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
||||
|
||||
- name: Setup - Remove snmp_host if configured
|
||||
nxos_snmp_host: &remove
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
v3: "{{ snmp_auth|default(omit) }}"
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
state: absent
|
||||
provider: "{{ connection }}"
|
||||
ignore_errors: yes
|
||||
|
||||
- block:
|
||||
|
||||
- name: Configure snmp host
|
||||
nxos_snmp_host: &config
|
||||
snmp_host: 3.3.3.3
|
||||
community: TESTING
|
||||
v3: "{{ snmp_auth|default(omit) }}"
|
||||
version: "{{ snmp_version }}"
|
||||
snmp_type: "{{ snmp_type }}"
|
||||
vrf: management
|
||||
vrf_filter: management
|
||||
state: present
|
||||
provider: "{{ connection }}"
|
||||
register: result
|
||||
|
||||
- assert: &true
|
||||
that:
|
||||
- "result.changed == true"
|
||||
|
||||
- name: Idempotence Check
|
||||
nxos_snmp_host: *config
|
||||
register: result
|
||||
|
||||
- assert: &false
|
||||
that:
|
||||
- "result.changed == false"
|
||||
|
||||
always:
|
||||
- name: Cleanup
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *true
|
||||
|
||||
- name: Cleanup Idempotence
|
||||
nxos_snmp_host: *remove
|
||||
register: result
|
||||
|
||||
- assert: *false
|
||||
|
||||
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_snmp_host {{ snmp_type }} {{ snmp_version }}sanity test"
|
Loading…
Reference in a new issue