赵占旭的博客

SONiC testbed link_flap

在测试link_flap测试用例的时候出错了,所以了解一下link_flap是在测试什么。

目前的理解就是轮着down掉Leaf交换机的端口,然后确认DUT交换机的端口是不是也是down的状态。

首先查看ansible/roles/test/tasks/link_flap.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
# 通过调用ansible/library/conn_graph_facts.py获取交换机的信息
# 主要靠解析文件files/lab_connection_graph.xml
- name: Gathering lab graph facts about the device
conn_graph_facts: host={{ inventory_hostname }}
connection: local
tags: always

# 上面会得到device_conn信息
- set_fact:
neighbors: "{{device_conn}}"

- include: link_flap/link_flap_helper.yml
with_items: "{{ device_conn.keys() }}"

接着查看ansible/roles/test/tasks/link_flap/link_flap_helper.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
- block:
# 获取端口
- set_fact:
interface: "{{item}}"

- debug: msg={{interface}}

# 获取当前端口连接的设备以及端口
- set_fact:
peer_device: "{{neighbors[interface]['peerdevice']}}"
neighbor_interface: "{{neighbors[interface]['peerport']}}"

# 类似上面获取对端交换机的信息
- conn_graph_facts: host={{ peer_device }}
connection: local

# 设置一些需要的信息
- set_fact:
peer_host: "{{device_info['mgmtip']}}"
peer_hwsku: "{{device_info['HwSku']}}"
peer_type: "{{device_info['Type']}}"

- set_fact:
intfs_to_exclude: "{{interface}}"

# 如果对端是leaf的话,down掉指定的端口
# 这块容易出问题,因为交换机支持不全,命令也不一定匹配所有交换机
- name: Shut down neighbor interface {{neighbor_interface}} on {{peer_host}}
action: apswitch template=neighbor_interface_shut_single.j2
args:
host: "{{peer_host}}"
login: "{{switch_login[hwsku_map[peer_hwsku]]}}"
connection: switch
when: peer_type == "FanoutLeaf"

- name: find interface name mapping
port_alias: hwsku="{{peer_hwsku}}"
delegate_to: "{{peer_host}}"
when: peer_type == "FanoutLeafSonic"

- name: Shutting down neighbor interface {{neighbor_interface}} on {{peer_host}}
become: true
shell: ip link set {{port_alias_map[neighbor_interface]}} down
delegate_to: "{{peer_host}}"
when: peer_type == "FanoutLeafSonic"

- pause:
seconds: 20

- interface_facts: up_ports={{minigraph_ports | difference(intfs_to_exclude)}}

- debug: msg="Found link down ports {{ansible_interface_link_down_ports}} "
when: ansible_interface_link_down_ports | length > 0

# 确定所有其他的端口都是up
- name: Verify interfaces are up correctly
assert: { that: "ansible_interface_link_down_ports | length == 0" }

# 确定刚才down掉的端口对应的端口也是down的
- name: Verify {{intfs_to_exclude}} is down correctly
assert: { that: "ansible_interface_facts[intfs_to_exclude]['active'] == False" }

always:
# up之前down掉的端口
- name: Bring up neighbor interface {{neighbor_interface}} on {{peer_host}}
action: apswitch template=neighbor_interface_no_shut_single.j2
args:
host: "{{peer_host}}"
login: "{{switch_login[hwsku_map[peer_hwsku]]}}"
connection: switch
when: peer_type == "FanoutLeaf"

- name: Bring up neighbor interface {{neighbor_interface}} on {{peer_host}}
become: true
shell: ip link set {{port_alias_map[neighbor_interface]}} up
delegate_to: "{{peer_host}}"
when: peer_type == "FanoutLeafSonic"

- pause:
seconds: 20

- interface_facts: up_ports={{minigraph_ports}}

- debug: msg="Found link down ports {{ansible_interface_link_down_ports}} "
when: ansible_interface_link_down_ports | length > 0

- name: Verify all interfaces are up
assert: { that: "ansible_interface_link_down_ports | length == 0" }

注意:所有文章非特别说明皆为原创。为保证信息与源同步,转载时请务必注明文章出处!谢谢合作 :-)

原始链接:http://zhaozhanxu.com/2018/08/16/SONiC/2018-08-16-SONiC-link-flap/

许可协议: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。