diff --git a/ansible/library/bgp_facts.py b/ansible/library/bgp_facts.py index 13902dbce0e..108c952a985 100644 --- a/ansible/library/bgp_facts.py +++ b/ansible/library/bgp_facts.py @@ -86,7 +86,7 @@ def collect_neighbors(self): def parse_neighbors(self): - regex_ip = re.compile(r'^BGP neighbor is (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') + regex_ip = re.compile(r'^BGP neighbor is (\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}|[0-9a-fA-F:]+)') regex_remote_as = re.compile(r'.*remote AS (\d+)') regex_local_as = re.compile(r'.*local AS (\d+)') regex_desc = re.compile(r'.*Description: (.*)') @@ -113,7 +113,7 @@ def parse_neighbors(self): lines = n.splitlines() for line in lines: - if regex_ip.match(line): neighbor_ip = regex_ip.match(line).group(1) + if regex_ip.match(line): neighbor_ip = regex_ip.match(line).group(1).lower() if regex_remote_as.match(line): neighbor['remote AS'] = int(regex_remote_as.match(line).group(1)) if regex_local_as.match(line): neighbor['local AS'] = int(regex_local_as.match(line).group(1)) if regex_desc.match(line): neighbor['description'] = regex_desc.match(line).group(1) diff --git a/ansible/roles/test/tasks/bgp_fact.yml b/ansible/roles/test/tasks/bgp_fact.yml index 05d69a055c5..d4fd9e79783 100644 --- a/ansible/roles/test/tasks/bgp_fact.yml +++ b/ansible/roles/test/tasks/bgp_fact.yml @@ -18,17 +18,17 @@ - name: Verify bgp sessions are established assert: { that: "'{{ bgp_neighbors[item]['state'] }}' == 'established'" } - with_items: bgp_neighbors.keys() + with_items: "{{ bgp_neighbors.keys() }}" - name: Verify locat ASNs in bgp sessions assert: { that: "'{{ bgp_neighbors[item]['local AS'] }}' == '{{ minigraph_bgp_asn }}'" } - with_items: bgp_neighbors.keys() + with_items: "{{ bgp_neighbors.keys() }}" - name: Compare the bgp neighbors name with minigraph bgp neigbhors name - assert: { that: "'{{ item['name'] }}' == '{{ bgp_neighbors[item['addr']]['description'] }}'" } - with_items: minigraph_bgp + assert: { that: "'{{ item['name'] }}' == '{{ bgp_neighbors[item['addr'].lower()]['description'] }}'" } + with_items: "{{ minigraph_bgp }}" - name: Compare the bgp neighbors ASN with minigraph - assert: { that: "'{{ item['asn'] }}' == '{{ bgp_neighbors[item['addr']]['remote AS'] }}'" } - with_items: minigraph_bgp + assert: { that: "'{{ item['asn'] }}' == '{{ bgp_neighbors[item['addr'].lower()]['remote AS'] }}'" } + with_items: "{{ minigraph_bgp }}"