Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[neighbour-mac-noptf] Fix issue 2414 by always using static arp/neighbour entry #1026

Merged
merged 9 commits into from
Aug 1, 2019
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'])
stephenxs marked this conversation as resolved.
Show resolved Hide resolved
- 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