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