Whamcloud - gitweb
LU-10973 lnet: LUTF UDSP test suite and routing test suite
[fs/lustre-release.git] / lustre / tests / lutf / python / tests / suite_udsp / test_udsp_multi_net_01.py
1 """
2 @PRIMARY: N/A
3 @PRIMARY_DESC: Verify functionality of UDSP rule that prioritizes a source net
4 @SECONDARY: N/A
5 @DESIGN: N/A
6 @TESTCASE:
7 - configure two networks, multiple nids per network
8 - add udsp rule that gives one of the networks highest priority
9 - generate traffic
10 - verify that the network with the highest priority was used
11 """
12
13 import os
14 import yaml
15 import lnetconfig
16 from lutf import agents, me
17 from lutf_basetest import *
18 from lnet import TheLNet
19 from lutf_exception import LUTFError
20 from lnet_helpers import LNetHelpers
21 from lustre_node import SimpleLustreNode
22
23 MIN_NODES = 2
24 MIN_IFS_PER_NODE = 4
25 PING_TIMES = 10
26 PING_NID_NUM = 0
27 LOCAL_NETS = ['tcp', 'tcp1']
28 USE_NET_NUM = [0]
29
30 class TestLustreTraffic:
31         def __init__(self, target=None):
32                 self.lh = LNetHelpers(os.path.abspath(__file__), target=target)
33                 self.sln = SimpleLustreNode(os.path.abspath(__file__), target=target)
34
35 def getStatNet(stats_dict, net_list, net_num, nid_stat_str):
36         stat_val = 0
37         for x in stats_dict:
38                 if (x['net type'] == net_list[net_num]):
39                         for y in x['local NI(s)']:
40                                         stat_val += y['statistics'][nid_stat_str]
41         return stat_val
42
43
44 def run():
45         la = agents.keys()
46         if len(la) < MIN_NODES:
47                 return lutfrc(LUTF_TEST_SKIP, "Not enough agents to run the test")
48         nodes = []
49         try:
50                 for i in range(0, MIN_NODES):
51                         node = TestLustreTraffic(la[i])
52                         t = node.lh
53                         intfs = t.get_available_devs()
54                         if len(intfs) < MIN_IFS_PER_NODE:
55                                 return lutfrc(LUTF_TEST_SKIP, "Not enough interfaces")
56                         t.configure_lnet()
57                         if not t.check_udsp_present():
58                                 return lutfrc(LUTF_TEST_SKIP, "UDSP feature is missing")
59                         for j, net in enumerate(LOCAL_NETS):
60                                 half = len(intfs)//len(LOCAL_NETS)
61                                 net_intfs_list = intfs[half*(j):half*(j+1)]
62                                 t.configure_net(net, net_intfs_list)
63                         t.set_discovery(1)
64                         nodes.append(node)
65
66                 main = nodes[1]
67                 main_nids = main.lh.list_nids()
68                 agent = nodes[0]
69                 agent_nids = agent.lh.list_nids()
70
71                 # discover all the peers from main
72                 if len(main.lh.discover(agent_nids[0])) == 0:
73                         return lutfrc(LUTF_TEST_FAIL, "unable to discover" ,
74                                 target=agent_nids[0])
75
76                 rc = main.lh.check_udsp_empty()
77                 if not rc:
78                         return lutfrc(LUTF_TEST_FAIL, "UDSP list not empty")
79
80                 for net_num in USE_NET_NUM:
81                         rc = main.lh.exec_udsp_cmd(" add --src "+LOCAL_NETS[net_num])
82
83                 before_stats_main = main.lh.get_net_stats()
84                 print(before_stats_main)
85
86                 for i in range(0, PING_TIMES):
87                         rc = main.lh.exec_ping(agent_nids[PING_NID_NUM])
88                         if not rc:
89                                 return lutfrc(LUTF_TEST_FAIL, "ping failed")
90
91                 after_stats_main = main.lh.get_net_stats()
92                 print(after_stats_main)
93
94                 send_count_before = {}
95                 send_count_after = {}
96                 total_send_count_before = 0
97                 total_send_count_after = 0
98                 for net_num in USE_NET_NUM:
99                         send_count_before[net_num] = getStatNet(before_stats_main, LOCAL_NETS, net_num, 'send_count')
100                         total_send_count_before += send_count_before[net_num]
101                         send_count_after[net_num] = getStatNet(after_stats_main, LOCAL_NETS, net_num, 'send_count')
102                         total_send_count_after += send_count_after[net_num]
103
104                 print(send_count_before, send_count_after)
105
106
107                 # Check stats:
108                 # 1) expect the total send_count to be no less than the number of pings issued
109                 # 2) expect the send count on the preferred net to increase by no less than the
110                 #    number of pings issued
111                 if (total_send_count_after - total_send_count_before) < PING_TIMES:
112                         return lutfrc(LUTF_TEST_FAIL, "total send count mismatch")
113
114                 for net_num in USE_NET_NUM:
115                         if abs(send_count_after[net_num] - send_count_before[net_num]) < PING_TIMES:
116                                 print("send count increase on network ", LOCAL_NETS[net_num],
117                                       " insufficient. Expected ", PING_TIMES, " got",
118                                       abs(send_count_after[net_num] - send_count_before[net_num]))
119                                 return lutfrc(LUTF_TEST_FAIL, "send count increase insufficient")
120
121                 for n in nodes:
122                         n.lh.unconfigure_lnet()
123
124                 return lutfrc(LUTF_TEST_PASS)
125         except Exception as e:
126                 for n in nodes:
127                         n.lh.uninit()
128                 raise e
129