17
17
netlink = False
18
18
print ("!!! Consider installing pyroute2 !!!" )
19
19
20
- def prepare_suite (obj , test ):
21
- original = obj .args .NAMES
22
-
23
- if 'skip' in test and test ['skip' ] == 'yes' :
24
- return
25
-
26
- if 'nsPlugin' not in test ['plugins' ]:
27
- return
28
-
29
- shadow = {}
30
- shadow ['IP' ] = original ['IP' ]
31
- shadow ['TC' ] = original ['TC' ]
32
- shadow ['NS' ] = '{}-{}' .format (original ['NS' ], test ['random' ])
33
- shadow ['DEV0' ] = '{}id{}' .format (original ['DEV0' ], test ['id' ])
34
- shadow ['DEV1' ] = '{}id{}' .format (original ['DEV1' ], test ['id' ])
35
- shadow ['DUMMY' ] = '{}id{}' .format (original ['DUMMY' ], test ['id' ])
36
- shadow ['DEV2' ] = original ['DEV2' ]
37
- obj .args .NAMES = shadow
38
-
39
- if netlink == True :
40
- obj ._nl_ns_create ()
41
- else :
42
- obj ._ns_create ()
43
-
44
- # Make sure the netns is visible in the fs
45
- while True :
46
- obj ._proc_check ()
47
- try :
48
- ns = obj .args .NAMES ['NS' ]
49
- f = open ('/run/netns/{}' .format (ns ))
50
- f .close ()
51
- break
52
- except :
53
- time .sleep (0.1 )
54
- continue
55
-
56
- obj .args .NAMES = original
57
-
58
20
class SubPlugin (TdcPlugin ):
59
21
def __init__ (self ):
60
22
self .sub_class = 'ns/SubPlugin'
@@ -65,19 +27,39 @@ def pre_suite(self, testcount, testlist):
65
27
66
28
super ().pre_suite (testcount , testlist )
67
29
68
- print ("Setting up namespaces and devices..." )
30
+ def prepare_test (self , test ):
31
+ if 'skip' in test and test ['skip' ] == 'yes' :
32
+ return
69
33
70
- with Pool (self .args .mp ) as p :
71
- it = zip (cycle ([self ]), testlist )
72
- p .starmap (prepare_suite , it )
34
+ if 'nsPlugin' not in test ['plugins' ]:
35
+ return
73
36
74
- def pre_case (self , caseinfo , test_skip ):
37
+ if netlink == True :
38
+ self ._nl_ns_create ()
39
+ else :
40
+ self ._ns_create ()
41
+
42
+ # Make sure the netns is visible in the fs
43
+ while True :
44
+ self ._proc_check ()
45
+ try :
46
+ ns = self .args .NAMES ['NS' ]
47
+ f = open ('/run/netns/{}' .format (ns ))
48
+ f .close ()
49
+ break
50
+ except :
51
+ time .sleep (0.1 )
52
+ continue
53
+
54
+ def pre_case (self , test , test_skip ):
75
55
if self .args .verbose :
76
56
print ('{}.pre_case' .format (self .sub_class ))
77
57
78
58
if test_skip :
79
59
return
80
60
61
+ self .prepare_test (test )
62
+
81
63
def post_case (self ):
82
64
if self .args .verbose :
83
65
print ('{}.post_case' .format (self .sub_class ))
0 commit comments