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
This commit is contained in:
Mike Wiebe 2017-11-13 03:03:06 -05:00 committed by Trishna Guha
commit de8d00b401
11 changed files with 144 additions and 7 deletions

View file

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

View file

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