Fix snmp bugs on Nexus 3500 platform (#32773)

* Add n35 platform support

* Fix regex bug and add snmp_location it tests

* Enable nxos_snmp_location tests
pull/32680/head
Mike Wiebe 7 years ago committed by Trishna Guha
parent d97080174e
commit de8d00b401

@ -96,7 +96,7 @@ def flatten_list(command_lists):
def get_snmp_location(module):
location = {}
location_regex = r'^\s*snmp-server\slocation\s(?P<location>.+)$'
location_regex = r'^\s*snmp-server\s+location\s+(?P<location>.+)$'
body = execute_show_command('show run snmp', module)[0]
match_location = re.search(location_regex, body, re.M)

@ -139,23 +139,41 @@ def get_snmp_user(user, module):
resource = {}
try:
resource_table = body[0]['TABLE_snmp_users']['ROW_snmp_users']
# The TABLE and ROW keys differ between NXOS platforms.
if body[0].get('TABLE_snmp_user'):
tablekey = 'TABLE_snmp_user'
rowkey = 'ROW_snmp_user'
tablegrpkey = 'TABLE_snmp_group_names'
rowgrpkey = 'ROW_snmp_group_names'
authkey = 'auth_protocol'
privkey = 'priv_protocol'
grpkey = 'group_names'
elif body[0].get('TABLE_snmp_users'):
tablekey = 'TABLE_snmp_users'
rowkey = 'ROW_snmp_users'
tablegrpkey = 'TABLE_groups'
rowgrpkey = 'ROW_groups'
authkey = 'auth'
privkey = 'priv'
grpkey = 'group'
resource_table = body[0][tablekey][rowkey]
resource['user'] = str(resource_table['user'])
resource['authentication'] = str(resource_table['auth']).strip()
encrypt = str(resource_table['priv']).strip()
resource['authentication'] = str(resource_table[authkey]).strip()
encrypt = str(resource_table[privkey]).strip()
if encrypt.startswith('aes'):
resource['encrypt'] = 'aes-128'
else:
resource['encrypt'] = 'none'
group_table = resource_table['TABLE_groups']['ROW_groups']
group_table = resource_table[tablegrpkey][rowgrpkey]
groups = []
try:
for group in group_table:
groups.append(str(group['group']).strip())
groups.append(str(group[grpkey]).strip())
except TypeError:
groups.append(str(group_table['group']).strip())
groups.append(str(group_table[grpkey]).strip())
resource['group'] = groups

@ -472,6 +472,16 @@
- set_fact:
failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_community' ]"
test_failed: true
- block:
- include_role:
name: nxos_snmp_location
when: "limit_to in ['*', 'nxos_snmp_location']"
rescue:
- set_fact:
failed_modules: "{{ failed_modules }} + [ 'nxos_snmp_location' ]"
test_failed: true
###########
- debug: var=failed_modules
when: test_failed

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

@ -0,0 +1,15 @@
---
- name: collect all cli test cases
find:
paths: "{{ role_path }}/tests/cli"
patterns: "{{ testcase }}.yaml"
register: test_cases
- 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

@ -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'] }

@ -0,0 +1,28 @@
---
- name: collect all nxapi test cases
find:
paths: "{{ role_path }}/tests/nxapi"
patterns: "{{ testcase }}.yaml"
register: test_cases
- name: set test_items
set_fact: test_items="{{ test_cases.files | map(attribute='path') | list }}"
- name: enable nxapi
nxos_config:
lines:
- feature nxapi
- nxapi http port 80
provider: "{{ cli }}"
- name: run test case
include: "{{ test_case_to_run }}"
with_items: "{{ test_items }}"
loop_control:
loop_var: test_case_to_run
- name: disable nxapi
nxos_config:
lines:
- no feature nxapi
provider: "{{ cli }}"

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ cli }}"
- import_tasks: "{{ role_path }}/tests/common/sanity.yaml"

@ -0,0 +1,47 @@
---
- debug: msg="START TRANSPORT:{{ connection.transport }} nxos_snmp_location sanity test"
- name: Setup - Remove snmp_location if configured
nxos_snmp_location: &remove
location: Test
state: absent
timeout: 60
provider: "{{ connection }}"
ignore_errors: yes
- block:
- name: Configure snmp host
nxos_snmp_location: &config
location: Test
state: present
timeout: 60
provider: "{{ connection }}"
register: result
- assert: &true
that:
- "result.changed == true"
- name: Idempotence Check
nxos_snmp_location: *config
register: result
- assert: &false
that:
- "result.changed == false"
always:
- name: Cleanup
nxos_snmp_location: *remove
register: result
- assert: *true
- name: Cleanup Idempotence
nxos_snmp_location: *remove
register: result
- assert: *false
- debug: msg="END TRANSPORT:{{ connection.transport }} nxos_snmp_location sanity test"

@ -0,0 +1,4 @@
---
- set_fact: connection="{{ nxapi }}"
- import_tasks: "{{ role_path }}/tests/common/sanity.yaml"
Loading…
Cancel
Save