From e76902f06d32337a26f948f6bf526db8adc8d3b6 Mon Sep 17 00:00:00 2001 From: REDMONDmasun Date: Fri, 17 Nov 2017 01:05:10 +0000 Subject: [PATCH] fix issue 354 --- ansible/library/bgp_facts.py | 2 +- ansible/library/bgp_route.py | 8 ++++---- ansible/library/interface_facts.py | 6 +++++- ansible/roles/test/tasks/interface.yml | 2 +- ansible/roles/test/tasks/link_flap/link_flap_helper.yml | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/ansible/library/bgp_facts.py b/ansible/library/bgp_facts.py index f777f5a5cd..0ee851b332 100644 --- a/ansible/library/bgp_facts.py +++ b/ansible/library/bgp_facts.py @@ -73,7 +73,7 @@ def collect_data(self, command_str): Collect bgp information by reading output of 'vtysh' command line tool """ try: - rc, self.out, err = self.module.run_command('vtysh -c "show ip bgp ' + command_str + '"', + rc, self.out, err = self.module.run_command('docker exec -i bgp vtysh -c "show ip bgp ' + command_str + '"', executable='/bin/bash', use_unsafe_shell=True) except Exception as e: self.module.fail_json(msg=str(e)) diff --git a/ansible/library/bgp_route.py b/ansible/library/bgp_route.py index 673e61badd..57aab870bb 100644 --- a/ansible/library/bgp_route.py +++ b/ansible/library/bgp_route.py @@ -322,9 +322,9 @@ def main(): if prefix: if regex_ipv4.match(prefix): - command = "vtysh -c 'show ip bgp " + str(prefix) + "'" + command = "docker exec -i bgp vtysh -c 'show ip bgp " + str(prefix) + "'" else: - command = "vtysh -c 'show ipv6 bgp " + str(prefix) + "'" + command = "docker exec -i bgp vtysh -c 'show ipv6 bgp " + str(prefix) + "'" rc, out, err = module.run_command(command) if rc != 0: err_message = "command %s failed rc=%d, out=%s, err=%s" %(command, rt, out, err) @@ -334,9 +334,9 @@ def main(): elif neighbor: if netaddr.valid_ipv4(neighbor): - command = "vtysh -c 'show ip bgp neighbor " + str(neighbor) + " " + str(direction) + "'" + command = "docker exec -i bgp vtysh -c 'show ip bgp neighbor " + str(neighbor) + " " + str(direction) + "'" else: - command = "vtysh -c 'show ipv6 bgp neighbor " + str(neighbor) + " " + str(direction) + "'" + command = "docker exec -i bgp vtysh -c 'show ipv6 bgp neighbor " + str(neighbor) + " " + str(direction) + "'" rc, out, err = module.run_command(command) if rc != 0: err_message = "command %s failed rc=%d, out=%s, err=%s" %(command, rt, out, err) diff --git a/ansible/library/interface_facts.py b/ansible/library/interface_facts.py index e9870ffd87..83729d820f 100644 --- a/ansible/library/interface_facts.py +++ b/ansible/library/interface_facts.py @@ -296,8 +296,12 @@ def parse_ip_output(module, output, secondary=False): down_ports = [] for name in up_ports: - if not interfaces[name]['link']: + try: + if not interfaces[name]['link']: + down_ports += [name] + except: down_ports += [name] + pass results['ansible_interface_facts'] = interfaces results['ansible_interface_ips'] = ips diff --git a/ansible/roles/test/tasks/interface.yml b/ansible/roles/test/tasks/interface.yml index 6279f70d95..8e9616bf03 100644 --- a/ansible/roles/test/tasks/interface.yml +++ b/ansible/roles/test/tasks/interface.yml @@ -5,7 +5,7 @@ when: ansible_interface_link_down_ports | length > 0 - name: Verify interfaces are up correctly - assert: { that: "{{ ansible_interface_link_down_ports }}|length == 0" } + assert: { that: "{{ ansible_interface_link_down_ports | length }} == 0" } - name: Verify port channel interfaces are up correctly assert: { that: "'{{ ansible_interface_facts[item]['active'] }}' == 'True'" } diff --git a/ansible/roles/test/tasks/link_flap/link_flap_helper.yml b/ansible/roles/test/tasks/link_flap/link_flap_helper.yml index aec3eac27f..83c48928ed 100644 --- a/ansible/roles/test/tasks/link_flap/link_flap_helper.yml +++ b/ansible/roles/test/tasks/link_flap/link_flap_helper.yml @@ -38,7 +38,7 @@ when: ansible_interface_link_down_ports | length > 0 - name: Verify interfaces are up correctly - assert: { that: "{{ ansible_interface_link_down_ports }}|length == 0" } + assert: { that: "{{ ansible_interface_link_down_ports | length }} == 0" } - name: Verify {{intfs_to_exclude}} is down correctly assert: { that: "'{{ ansible_interface_facts[intfs_to_exclude]['active'] }}' == 'False'" }