@@ -104,7 +104,7 @@ func (p *mockPolicy) Start(s state.State) error {
104
104
return p .err
105
105
}
106
106
107
- func (p * mockPolicy ) AddContainer (s state.State , pod * v1.Pod , container * v1.Container ) error {
107
+ func (p * mockPolicy ) Allocate (s state.State , pod * v1.Pod , container * v1.Container ) error {
108
108
return p .err
109
109
}
110
110
@@ -223,34 +223,38 @@ func TestCPUManagerAdd(t *testing.T) {
223
223
cpuset .NewCPUSet (),
224
224
topologymanager .NewFakeManager ())
225
225
testCases := []struct {
226
- description string
227
- updateErr error
228
- policy Policy
229
- expCPUSet cpuset.CPUSet
230
- expErr error
226
+ description string
227
+ updateErr error
228
+ policy Policy
229
+ expCPUSet cpuset.CPUSet
230
+ expAllocateErr error
231
+ expAddContainerErr error
231
232
}{
232
233
{
233
- description : "cpu manager add - no error" ,
234
- updateErr : nil ,
235
- policy : testPolicy ,
236
- expCPUSet : cpuset .NewCPUSet (3 , 4 ),
237
- expErr : nil ,
234
+ description : "cpu manager add - no error" ,
235
+ updateErr : nil ,
236
+ policy : testPolicy ,
237
+ expCPUSet : cpuset .NewCPUSet (3 , 4 ),
238
+ expAllocateErr : nil ,
239
+ expAddContainerErr : nil ,
238
240
},
239
241
{
240
242
description : "cpu manager add - policy add container error" ,
241
243
updateErr : nil ,
242
244
policy : & mockPolicy {
243
245
err : fmt .Errorf ("fake reg error" ),
244
246
},
245
- expCPUSet : cpuset .NewCPUSet (1 , 2 , 3 , 4 ),
246
- expErr : fmt .Errorf ("fake reg error" ),
247
+ expCPUSet : cpuset .NewCPUSet (1 , 2 , 3 , 4 ),
248
+ expAllocateErr : fmt .Errorf ("fake reg error" ),
249
+ expAddContainerErr : nil ,
247
250
},
248
251
{
249
- description : "cpu manager add - container update error" ,
250
- updateErr : fmt .Errorf ("fake update error" ),
251
- policy : testPolicy ,
252
- expCPUSet : cpuset .NewCPUSet (1 , 2 , 3 , 4 ),
253
- expErr : fmt .Errorf ("fake update error" ),
252
+ description : "cpu manager add - container update error" ,
253
+ updateErr : fmt .Errorf ("fake update error" ),
254
+ policy : testPolicy ,
255
+ expCPUSet : cpuset .NewCPUSet (1 , 2 , 3 , 4 ),
256
+ expAllocateErr : nil ,
257
+ expAddContainerErr : fmt .Errorf ("fake update error" ),
254
258
},
255
259
}
256
260
@@ -271,10 +275,16 @@ func TestCPUManagerAdd(t *testing.T) {
271
275
272
276
pod := makePod ("fakePod" , "fakeContainer" , "2" , "2" )
273
277
container := & pod .Spec .Containers [0 ]
274
- err := mgr .AddContainer (pod , container , "fakeID" )
275
- if ! reflect .DeepEqual (err , testCase .expErr ) {
278
+ err := mgr .Allocate (pod , container )
279
+ if ! reflect .DeepEqual (err , testCase .expAllocateErr ) {
280
+ t .Errorf ("CPU Manager Allocate() error (%v). expected error: %v but got: %v" ,
281
+ testCase .description , testCase .expAllocateErr , err )
282
+ }
283
+
284
+ err = mgr .AddContainer (pod , container , "fakeID" )
285
+ if ! reflect .DeepEqual (err , testCase .expAddContainerErr ) {
276
286
t .Errorf ("CPU Manager AddContainer() error (%v). expected error: %v but got: %v" ,
277
- testCase .description , testCase .expErr , err )
287
+ testCase .description , testCase .expAddContainerErr , err )
278
288
}
279
289
if ! testCase .expCPUSet .Equals (mgr .state .GetDefaultCPUSet ()) {
280
290
t .Errorf ("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v" ,
@@ -494,7 +504,12 @@ func TestCPUManagerAddWithInitContainers(t *testing.T) {
494
504
testCase .expCSets ... )
495
505
496
506
for i := range containers {
497
- err := mgr .AddContainer (testCase .pod , & containers [i ], containerIDs [i ])
507
+ err := mgr .Allocate (testCase .pod , & containers [i ])
508
+ if err != nil {
509
+ t .Errorf ("StaticPolicy Allocate() error (%v). unexpected error for container id: %v: %v" ,
510
+ testCase .description , containerIDs [i ], err )
511
+ }
512
+ err = mgr .AddContainer (testCase .pod , & containers [i ], containerIDs [i ])
498
513
if err != nil {
499
514
t .Errorf ("StaticPolicy AddContainer() error (%v). unexpected error for container id: %v: %v" ,
500
515
testCase .description , containerIDs [i ], err )
@@ -970,25 +985,28 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
970
985
cpuset .NewCPUSet (0 ),
971
986
topologymanager .NewFakeManager ())
972
987
testCases := []struct {
973
- description string
974
- updateErr error
975
- policy Policy
976
- expCPUSet cpuset.CPUSet
977
- expErr error
988
+ description string
989
+ updateErr error
990
+ policy Policy
991
+ expCPUSet cpuset.CPUSet
992
+ expAllocateErr error
993
+ expAddContainerErr error
978
994
}{
979
995
{
980
- description : "cpu manager add - no error" ,
981
- updateErr : nil ,
982
- policy : testPolicy ,
983
- expCPUSet : cpuset .NewCPUSet (0 , 3 ),
984
- expErr : nil ,
996
+ description : "cpu manager add - no error" ,
997
+ updateErr : nil ,
998
+ policy : testPolicy ,
999
+ expCPUSet : cpuset .NewCPUSet (0 , 3 ),
1000
+ expAllocateErr : nil ,
1001
+ expAddContainerErr : nil ,
985
1002
},
986
1003
{
987
- description : "cpu manager add - container update error" ,
988
- updateErr : fmt .Errorf ("fake update error" ),
989
- policy : testPolicy ,
990
- expCPUSet : cpuset .NewCPUSet (0 , 1 , 2 , 3 ),
991
- expErr : fmt .Errorf ("fake update error" ),
1004
+ description : "cpu manager add - container update error" ,
1005
+ updateErr : fmt .Errorf ("fake update error" ),
1006
+ policy : testPolicy ,
1007
+ expCPUSet : cpuset .NewCPUSet (0 , 1 , 2 , 3 ),
1008
+ expAllocateErr : nil ,
1009
+ expAddContainerErr : fmt .Errorf ("fake update error" ),
992
1010
},
993
1011
}
994
1012
@@ -1009,10 +1027,16 @@ func TestCPUManagerAddWithResvList(t *testing.T) {
1009
1027
1010
1028
pod := makePod ("fakePod" , "fakeContainer" , "2" , "2" )
1011
1029
container := & pod .Spec .Containers [0 ]
1012
- err := mgr .AddContainer (pod , container , "fakeID" )
1013
- if ! reflect .DeepEqual (err , testCase .expErr ) {
1030
+ err := mgr .Allocate (pod , container )
1031
+ if ! reflect .DeepEqual (err , testCase .expAllocateErr ) {
1032
+ t .Errorf ("CPU Manager Allocate() error (%v). expected error: %v but got: %v" ,
1033
+ testCase .description , testCase .expAllocateErr , err )
1034
+ }
1035
+
1036
+ err = mgr .AddContainer (pod , container , "fakeID" )
1037
+ if ! reflect .DeepEqual (err , testCase .expAddContainerErr ) {
1014
1038
t .Errorf ("CPU Manager AddContainer() error (%v). expected error: %v but got: %v" ,
1015
- testCase .description , testCase .expErr , err )
1039
+ testCase .description , testCase .expAddContainerErr , err )
1016
1040
}
1017
1041
if ! testCase .expCPUSet .Equals (mgr .state .GetDefaultCPUSet ()) {
1018
1042
t .Errorf ("CPU Manager AddContainer() error (%v). expected cpuset: %v but got: %v" ,
0 commit comments