Skip to content

Commit

Permalink
[neighbour-mac-noptf] Fix issue 2414 by always using static arp/neigh…
Browse files Browse the repository at this point in the history
…bour entry (#1026)

* [neighbour-mac-noptf]
1. fix the issue which "when" doesn't work when it is in a nested "block" statement
2. don't use the hardcoded "Ethernet0" since in topo t1-lag it belongs a PortChannel and to set ip address on such kind of interface causes orchagent terminated.
   choice a valiable routed interface for test instead.
[show_interface.py]
1. add "vlan" to int_status dict

* [neighbour-mac-noptf]
don't use an ary/neighbour which is a bgp neighbour to do the updating neighbour's mac test,
doing in that way can cause bgp connection down and a large number of routing entries withdrawed,
failing orchagent to handle neighbour mac update in time.
use a newly added address and neighbor on an automatically selected routing interface for that test instead.

* remove unnecessary condition check

* [neighbour-mac-noptf] select routing_interface only from interfaces whose oper_state are 'up' and remove startup interface stuffs

* [neighbour-mac-noptf] select fixed interface for testing.

* [neighbour-mac-noptf]
1. fix the issue which "when" doesn't work when it is in a nested "block" statement
2. alway use a static arp/neighbour for testing, since the dynamic entries are of the BGP neighbors and to change their mac address causes bgp neighbour down and route withdrew, making system busy and unable to handle mac update in time.
   we use Ethernet0 for t0 and t1, PortChannel0002 for t1-lag

* Revert "[neighbour-mac-noptf] select fixed interface for testing."

This reverts commit 181a522.

* [neighbour-mac-noptf] add comment for item.value['vlan'] to avoid confusion.
  • Loading branch information
stephenxs authored and prsunny committed Aug 1, 2019
1 parent 8d2f4e0 commit c1761f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 52 deletions.
13 changes: 8 additions & 5 deletions ansible/library/show_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"name": "Ethernet0"
"speed": "40G"
"alias": "fortyGigE1/1/1"
"vlan": "routed"
"oper_state": "down"
"admin_state": "up"
}
Expand Down Expand Up @@ -82,7 +83,7 @@ def run(self):
self.module.exit_json(ansible_facts=self.facts)

def collect_interface_status(self):
regex_int = re.compile(r'(\S+)\s+[\d,]+\s+(\w+)\s+(\d+)\s+([\w\/]+)\s+(\w+)\s+(\w+)')
regex_int = re.compile(r'(\S+)\s+[\d,N\/A]+\s+(\w+)\s+(\d+)\s+([\w\/]+)\s+(\w+)\s+(\w+)\s+(\w+)')
self.int_status = {}
if self.m_args['interfaces'] is not None:
for interface in self.m_args['interfaces']:
Expand All @@ -96,8 +97,9 @@ def collect_interface_status(self):
self.int_status[interface]['name'] = regex_int.match(line).group(1)
self.int_status[interface]['speed'] = regex_int.match(line).group(2)
self.int_status[interface]['alias'] = regex_int.match(line).group(4)
self.int_status[interface]['oper_state'] = regex_int.match(line).group(5)
self.int_status[interface]['admin_state'] = regex_int.match(line).group(6)
self.int_status[interface]['vlan'] = regex_int.match(line).group(5)
self.int_status[interface]['oper_state'] = regex_int.match(line).group(6)
self.int_status[interface]['admin_state'] = regex_int.match(line).group(7)
self.facts['int_status'] = self.int_status
except Exception as e:
self.module.fail_json(msg=str(e))
Expand All @@ -114,8 +116,9 @@ def collect_interface_status(self):
self.int_status[interface]['name'] = interface
self.int_status[interface]['speed'] = regex_int.match(line).group(2)
self.int_status[interface]['alias'] = regex_int.match(line).group(4)
self.int_status[interface]['oper_state'] = regex_int.match(line).group(5)
self.int_status[interface]['admin_state'] = regex_int.match(line).group(6)
self.int_status[interface]['vlan'] = regex_int.match(line).group(5)
self.int_status[interface]['oper_state'] = regex_int.match(line).group(6)
self.int_status[interface]['admin_state'] = regex_int.match(line).group(7)
self.facts['int_status'] = self.int_status
except Exception as e:
self.module.fail_json(msg=str(e))
Expand Down
75 changes: 28 additions & 47 deletions ansible/roles/test/tasks/neighbour-mac-noptf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,35 +31,32 @@
- name: init loganalyzer for later syslog analysis
include: roles/test/files/tools/loganalyzer/loganalyzer_init.yml

- name: gather DUT arp table
switch_arptable:

########## Test V4 mac address change #################
- name: pick IPv4 neighbor to test change mac behavior
- name: gather DUT interface table
show_interface: command='status'

# To pick an interface which is up and a routing interface for the test.
# For a routing interface, the item.value['vlan'] contains string 'routed'.
# The key name 'vlan' aligns with the title of column where its data comes.
# It doesn't mean to use a 'vlan' interface for the test.
- name: select A routing interface for testing
set_fact:
v4_nei: "{{ item.key }}"
v4_intf: "{{ item.value['interface'] }}"
with_dict: "{{ arptable.v4 }}"
routing_interface: "{{ item.key }}"
with_dict: "{{int_status}}"
when:
- ('Ethernet' in item.value['interface']) or ('PortChannel' in item.value['interface'])
- arptable.v4 | length != 0
- ('routed' in item.value['vlan'] and 'up' in item.value['oper_state'])
- int_status | length != 0

- block:
- name: select Ethernet0 if cannot find a v4 neighbor for test
set_fact:
v4_intf: "Ethernet0"
v4_nei: "{{ v4_intf_nei }}"

- name: startup Ethernet0
command: "config interface startup Ethernet0"

- name: add an ip entry for Ethernet0
command: "config interface ip add Ethernet0 {{ v4_intf_ip }}"
########## Test V4 mac address change #################
- name: pick {{routing_interface}} to test change mac behavior
set_fact:
v4_intf: "{{routing_interface}}"
v4_nei: "{{ v4_intf_nei }}"

- name: add neighbor of Ethernet0
command: "/sbin/ip neigh add {{ v4_intf_nei }} lladdr {{ v4_mac1 }} dev Ethernet0"
- name: add an ip entry for {{v4_intf}}
command: "config interface ip add {{ v4_intf }} {{ v4_intf_ip }}"

when: v4_nei is not defined
- name: add neighbor for {{v4_intf}}
command: "/sbin/ip neigh add {{ v4_intf_nei }} lladdr {{ v4_mac1 }} dev {{ v4_intf }}"

- name: change v4 neighbor mac address 1st time
command: "ip neigh change {{ v4_nei }} lladdr {{ v4_mac1 }} dev {{ v4_intf }}"
Expand Down Expand Up @@ -94,32 +91,16 @@
- assert: { that: "neighbour_mac.stdout | lower == v4_mac2" }

############## Test V6 mac change ##################
- name: pick IPv6 neighbor to test change mac address"
- name: pick {{routing_interface}} as test interface
set_fact:
v6_nei: "{{ item.key }}"
v6_intf: "{{ item.value['interface'] }}"
with_dict: "{{ arptable.v6 }}"
when:
- "'fe80::' not in item.key | lower"
- ('Ethernet' in item.value['interface']) or ('PortChannel' in item.value['interface'])
- arptable.v6 | length != 0

- block:
- name: pick Ethernet0 as test interface if cannot find v6 neighbor to test
set_fact:
v6_intf: "Ethernet0"
v6_nei: "{{ v6_intf_nei }}"

- name: startup Ethernet0
command: "config interface startup Ethernet0"

- name: add an ipv6 entry for Ethernet0 if no v6 neighbor was found
command: "config interface ip add Ethernet0 {{ v6_intf_ip }}"
v6_intf: "{{routing_interface}}"
v6_nei: "{{ v6_intf_nei }}"

- name: add an ipv6 neighbor for Ethernet0 if no v6 neighbor was found
command: "/sbin/ip neigh add {{ v6_intf_nei }} lladdr {{ v6_mac1 }} dev Ethernet0"
- name: add an ipv6 entry for {{v6_intf}}
command: "config interface ip add {{v6_intf}} {{ v6_intf_ip }}"

when: v6_nei is not defined
- name: add an ipv6 neighbor for {{v6_intf}}
command: "/sbin/ip neigh add {{ v6_intf_nei }} lladdr {{ v6_mac1 }} dev {{v6_intf}}"

- name: change v6 neighbor mac address 1st time
command: "ip -6 neigh change {{ v6_nei }} lladdr {{ v6_mac1 }} dev {{ v6_intf }}"
Expand Down

0 comments on commit c1761f3

Please sign in to comment.