From d9a1c8954fbeedf3e95f1c873a9834b004ff41f9 Mon Sep 17 00:00:00 2001 From: Anil Kumar Muraleedharan Date: Wed, 1 May 2019 20:27:05 +0530 Subject: [PATCH] Coverity Bug Fix for cnos_vrf.py (#55954) * Coverity Bug Fix for cnos_vrf.py * Update cnos_vrf.py --- lib/ansible/modules/network/cnos/cnos_vrf.py | 40 ++++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/ansible/modules/network/cnos/cnos_vrf.py b/lib/ansible/modules/network/cnos/cnos_vrf.py index b8d0970b56..5196af0cab 100644 --- a/lib/ansible/modules/network/cnos/cnos_vrf.py +++ b/lib/ansible/modules/network/cnos/cnos_vrf.py @@ -228,27 +228,27 @@ def map_obj_to_commands(updates, module): def map_config_to_obj(module): objs = [] output = run_commands(module, {'command': 'show vrf'}) - if output is None: + if output is not None: + vrfText = output[0].strip() + vrfList = vrfText.split('VRF') + for vrfItem in vrfList: + if 'FIB ID' in vrfItem: + obj = dict() + list_of_words = vrfItem.split() + vrfName = list_of_words[0] + obj['name'] = vrfName[:-1] + obj['rd'] = list_of_words[list_of_words.index('RD') + 1] + start = False + obj['interfaces'] = [] + for intName in list_of_words: + if 'Interfaces' in intName: + start = True + if start is True: + if '!' not in intName and 'Interfaces' not in intName: + obj['interfaces'].append(intName.strip().lower()) + objs.append(obj) + else: module.fail_json(msg='Could not fetch VRF details from device') - vrfText = output[0].strip() - vrfList = vrfText.split('VRF') - for vrfItem in vrfList: - if 'FIB ID' in vrfItem: - obj = dict() - list_of_words = vrfItem.split() - vrfName = list_of_words[0] - obj['name'] = vrfName[:-1] - obj['rd'] = list_of_words[list_of_words.index('RD') + 1] - start = False - obj['interfaces'] = [] - for intName in list_of_words: - if 'Interfaces' in intName: - start = True - if start is True: - if '!' not in intName and 'Interfaces' not in intName: - obj['interfaces'].append(intName.strip().lower()) - objs.append(obj) - return objs