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_single_net_02.py
1 """
2 @PRIMARY: N/A
3 @PRIMARY_DESC: N/A
4 @PRIMARY_DESC: Verify that multiple local nids can be prioritized for sending via UDSP
5 @SECONDARY: N/A
6 @DESIGN: N/A
7 @TESTCASE:
8 - configure one lnet and more than two nids
9 - turn on LNet discovery
10 - run lnetctl discover
11 - verify that udsp list is empty
12 - add udsp rule that gives two of the local nids higher priority
13 - get lnet stats (lnetctl net show -v 4)
14 - generate traffic by running lnetctl ping multiple times
15 - get lnet stats again
16 - verify that all sends were done using the prioritized nids
17 """
18
19 import os
20 import yaml
21 import lnetconfig
22 from lutf import agents, me
23 from lutf_basetest import *
24 from lnet import TheLNet
25 from lutf_exception import LUTFError
26 from lnet_helpers import LNetHelpers
27 from lustre_node import SimpleLustreNode
28
29 MIN_NODES = 2
30 MIN_IFS_PER_NODE = 3
31 PING_TIMES = 10
32 PING_NID_NUM = 0
33 LOCAL_NET = 'tcp'
34 USE_NID_NUM = [0, 1]
35
36 class TestLustreTraffic:
37         def __init__(self, target=None):
38                 self.lh = LNetHelpers(os.path.abspath(__file__), target=target)
39                 self.sln = SimpleLustreNode(os.path.abspath(__file__), target=target)
40
41 def getStatNID(stats_dict, nid_list, nid_num, nid_stat_str):
42         for x in stats_dict:
43                 if (x['net type'] == LOCAL_NET):
44                         for y in x['local NI(s)']:
45                                 if y['nid'] == nid_list[nid_num]:
46                                         return y['statistics'][nid_stat_str]
47         return -1
48
49
50 def run():
51         la = agents.keys()
52         if len(la) < MIN_NODES:
53                 return lutfrc(LUTF_TEST_SKIP, "Not enough agents to run the test")
54         nodes = []
55         try:
56                 for i in range(0, MIN_NODES):
57                         node = TestLustreTraffic(la[i])
58                         t = node.lh
59                         intfs = t.get_available_devs()
60                         if len(intfs) < MIN_IFS_PER_NODE:
61                                 return lutfrc(LUTF_TEST_SKIP, "Not enough interfaces")
62                         if not t.check_udsp_present():
63                                 return lutfrc(LUTF_TEST_SKIP, "UDSP feature is missing")
64                         t.configure_lnet()
65                         t.configure_net(LOCAL_NET, intfs)
66                         t.set_discovery(1)
67                         nodes.append(node)
68
69                 main = nodes[1]
70                 main_nids = main.lh.list_nids()
71                 agent = nodes[0]
72                 agent_nids = agent.lh.list_nids()
73                 print("nids: ", main_nids)
74
75                 # discover all the peers from main
76                 if len(main.lh.discover(agent_nids[0])) == 0:
77                         return lutfrc(LUTF_TEST_FAIL, "unable to discover" ,
78                                 target=agent_nids[0])
79
80                 rc = main.lh.check_udsp_empty()
81                 if not rc:
82                         print("UDSP list not empty")
83                         return lutfrc(LUTF_TEST_FAIL)
84
85                 for nid_num in USE_NID_NUM:
86                         rc = main.lh.exec_udsp_cmd(" add --src "+main_nids[nid_num])
87
88                 before_stats_main = main.sln.get_lnet().get_net_stats()
89                 print(before_stats_main)
90
91                 for i in range(0, PING_TIMES):
92                         rc = main.lh.exec_ping(agent_nids[PING_NID_NUM])
93                         if not rc:
94                                 print("ping failed")
95                                 return lutfrc(LUTF_TEST_FAIL)
96
97                 after_stats_main = main.sln.get_lnet().get_net_stats()
98                 print(after_stats_main)
99
100                 send_count_before = {}
101                 send_count_after = {}
102                 total_send_count_before = 0
103                 total_send_count_after = 0
104                 for nid_num in USE_NID_NUM:
105                         #print({nid_num: getStatNID(before_stats_main, main_nids, nid_num, 'send_count')})
106                         #print({nid_num: getStatNID(after_stats_main, main_nids, nid_num, 'send_count')})
107                         send_count_before[nid_num] = getStatNID(before_stats_main, main_nids, nid_num, 'send_count')
108                         total_send_count_before += send_count_before[nid_num]
109                         send_count_after[nid_num] = getStatNID(after_stats_main, main_nids, nid_num, 'send_count')
110                         total_send_count_after += send_count_after[nid_num]
111
112                 """
113                 for x in before_stats_main:
114                         if (x['net type'] == LOCAL_NET):
115                                 for y in x['local NI(s)']:
116                                         if y['nid'] == main_nids[USE_NID_NUM]:
117                                                 send_count_before = y['statistics']['send_count']
118                 for x in after_stats_main:
119                         if (x['net type'] == LOCAL_NET):
120                                 for y in x['local NI(s)']:
121                                         if y['nid'] == main_nids[USE_NID_NUM]:
122                                                 send_count_after = y['statistics']['send_count']
123                 if send_count_before < 0 or send_count_after < 0:
124                         print("failed to parse net stats")
125                         return lutfrc(LUTF_TEST_FAIL)
126
127                 if send_count_after - send_count_before < PING_TIMES:
128                         print("Unexpected number of sends: ", send_count_after - send_count_before)
129                         return lutfrc(LUTF_TEST_FAIL)
130                 """
131
132                 print(send_count_before, send_count_after)
133
134                 # Check stats:
135                 # 1) expect send counts on both interfaces to increase
136                 # 2) expect the total send_count to be no less than the number of pings issued
137                 # 3) expect the send counts on the two interfaces used to be close (diff < 2)
138                 if (total_send_count_after - total_send_count_before) < PING_TIMES:
139                         print("total send count mismatch")
140                         return lutfrc(LUTF_TEST_FAIL)
141
142                 if abs(send_count_after[0] - send_count_after[1]) > 1:
143                         print("uneven tx traffic distribution across interfaces")
144                         return lutfrc(LUTF_TEST_FAIL)
145
146
147                 for n in nodes:
148                         n.lh.unconfigure_lnet()
149
150                 return lutfrc(LUTF_TEST_PASS)
151         except Exception as e:
152                 for n in nodes:
153                         n.lh.uninit()
154                 raise e
155