@@ -132,37 +132,49 @@ var _ = Describe("Plugin - test CNI command flows", func() {
132132 })
133133
134134 Describe ("CmdAdd" , func () {
135- successfullyParseConfig := func () {
135+ successfullyParseConfig := func (_ bool ) {
136136 configMock .On ("ParseConf" , mock .Anything , mock .Anything ).Run (func (args mock.Arguments ) {
137137 * args [1 ].(* localtypes.PluginConf ) = * pluginConf
138138 }).Return (nil ).Once ()
139139 }
140- successfullyGetNS := func () {
141- successfullyParseConfig ()
140+ successfullyGetNS := func (withDeps bool ) {
141+ if withDeps {
142+ successfullyParseConfig (true )
143+ }
142144 nsMock .On ("GetNS" , testValidNSPath ).Return (netNSMock , nil ).Once ()
143145 netNSMock .On ("Path" ).Return (testValidNSPath ).Once ()
144146 }
145- successfullyAttachRepresentor := func () {
146- successfullyGetNS ()
147+ successfullyAttachRepresentor := func (withDeps bool ) {
148+ if withDeps {
149+ successfullyGetNS (true )
150+ }
147151 managerMock .On ("AttachRepresentor" , pluginConf ).Return (nil ).Once ()
148152 }
149- successfullyApplyVFConfig := func () {
150- successfullyAttachRepresentor ()
153+ successfullyApplyVFConfig := func (withDeps bool ) {
154+ if withDeps {
155+ successfullyAttachRepresentor (true )
156+ }
151157 managerMock .On ("ApplyVFConfig" , pluginConf ).Return (nil ).Once ()
152158 }
153- successfullySetupVF := func () {
154- successfullyApplyVFConfig ()
159+ successfullySetupVF := func (withDeps bool ) {
160+ if withDeps {
161+ successfullyApplyVFConfig (true )
162+ }
155163 managerMock .On ("SetupVF" ,
156164 pluginConf , testValidContIFNames , testValidContainerID , netNSMock ).
157165 Return (testValidMAC , nil ).Once ()
158166 }
159- successfullyExecAdd := func () {
160- successfullySetupVF ()
167+ successfullyExecAdd := func (withDeps bool ) {
168+ if withDeps {
169+ successfullySetupVF (true )
170+ }
161171 ipamMock .On ("ExecAdd" , pluginConf .IPAM .Type , cmdArgs .StdinData ).
162172 Return (getValidIPAMResult (), nil ).Once ()
163173 }
164- successfullyConfigureIface := func () {
165- successfullyExecAdd ()
174+ successfullyConfigureIface := func (withDeps bool ) {
175+ if withDeps {
176+ successfullyExecAdd (true )
177+ }
166178 ipamMock .On ("ConfigureIface" , cmdArgs .IfName ,
167179 mock .MatchedBy (func (conf * current.Result ) bool {
168180 return len (conf .Interfaces ) > 0 && conf .Interfaces [0 ].Mac == testValidMAC
@@ -178,8 +190,10 @@ var _ = Describe("Plugin - test CNI command flows", func() {
178190 cacheMock .On ("Save" , testValidCacheRef , pluginConf ).
179191 Return (nil ).Once ()
180192 }
181- successfullySave := func () {
182- successfullyConfigureIface ()
193+ successfullySave := func (withDeps bool ) {
194+ if withDeps {
195+ successfullyConfigureIface (true )
196+ }
183197 configureCacheMock ()
184198 }
185199 cleanupGetNS := func () {
@@ -205,39 +219,39 @@ var _ = Describe("Plugin - test CNI command flows", func() {
205219 Expect (plugin .CmdAdd (getValidCmdArgs ())).To (HaveOccurred ())
206220 })
207221 It ("Failed to get NS" , func () {
208- successfullyParseConfig ()
222+ successfullyParseConfig (true )
209223 nsMock .On ("GetNS" , testValidNSPath ).Return (nil , errTest ).Once ()
210224 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
211225 })
212226 It ("Failed to attach representor" , func () {
213- successfullyGetNS ()
227+ successfullyGetNS (true )
214228 managerMock .On ("AttachRepresentor" , pluginConf ).Return (errTest ).Once ()
215229 cleanupGetNS ()
216230 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
217231 })
218232 It ("Failed to ApplyVFConfig" , func () {
219- successfullyAttachRepresentor ()
233+ successfullyAttachRepresentor (true )
220234 managerMock .On ("ApplyVFConfig" , pluginConf ).Return (errTest ).Once ()
221235 cleanupAttachRepresentor ()
222236 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
223237 })
224238 It ("Failed to SetupVF" , func () {
225- successfullyApplyVFConfig ()
239+ successfullyApplyVFConfig (true )
226240 managerMock .On ("SetupVF" ,
227241 pluginConf , testValidContIFNames , testValidContainerID , netNSMock ).
228242 Return ("" , errTest ).Once ()
229243 cleanupSetupVFConfig ()
230244 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
231245 })
232246 It ("Failed to IPAM Add" , func () {
233- successfullySetupVF ()
247+ successfullySetupVF (true )
234248 ipamMock .On ("ExecAdd" , pluginConf .IPAM .Type , cmdArgs .StdinData ).
235249 Return (nil , errTest ).Once ()
236250 cleanupSetupVFConfig ()
237251 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
238252 })
239253 It ("IPAM add returns no IPs" , func () {
240- successfullySetupVF ()
254+ successfullySetupVF (true )
241255 result := getValidIPAMResult ()
242256 result .(* current.Result ).IPs = nil
243257 ipamMock .On ("ExecAdd" , pluginConf .IPAM .Type , cmdArgs .StdinData ).
@@ -246,7 +260,7 @@ var _ = Describe("Plugin - test CNI command flows", func() {
246260 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
247261 })
248262 It ("Failed to IPAM ConfigureIface" , func () {
249- successfullyExecAdd ()
263+ successfullyExecAdd (true )
250264 ipamMock .On ("ConfigureIface" , cmdArgs .IfName , mock .Anything ).
251265 Return (errTest ).Once ()
252266 netNSMock .On ("Do" , mock .Anything ).Return (func (f func (ns.NetNS ) error ) error {
@@ -256,7 +270,7 @@ var _ = Describe("Plugin - test CNI command flows", func() {
256270 Expect (plugin .CmdAdd (cmdArgs )).To (HaveOccurred ())
257271 })
258272 It ("Failed save cache" , func () {
259- successfullyConfigureIface ()
273+ successfullyConfigureIface (true )
260274 cacheMock .On ("GetStateRef" , pluginConf .Name , cmdArgs .ContainerID , cmdArgs .IfName ).
261275 Return (testValidCacheRef ).Once ()
262276 cacheMock .On ("Save" , testValidCacheRef , pluginConf ).
@@ -267,24 +281,32 @@ var _ = Describe("Plugin - test CNI command flows", func() {
267281 })
268282 Context ("Successful scenarios" , func () {
269283 It ("with IPAM" , func () {
270- successfullySave ()
284+ successfullySave (true )
271285 cleanupGetNS ()
272286 Expect (plugin .CmdAdd (cmdArgs )).ToNot (HaveOccurred ())
273287 })
274288 It ("no IPAM" , func () {
275289 pluginConf .IPAM = types.IPAM {}
276- successfullySetupVF ()
290+ successfullySetupVF (true )
277291 configureCacheMock ()
278292 cleanupGetNS ()
279293 Expect (plugin .CmdAdd (cmdArgs )).ToNot (HaveOccurred ())
280294 })
295+ It ("userspace driver" , func () {
296+ pluginConf .IsUserspaceDriver = true
297+ successfullyApplyVFConfig (true )
298+ successfullyExecAdd (false )
299+ successfullySave (false )
300+ cleanupGetNS ()
301+ Expect (plugin .CmdAdd (cmdArgs )).ToNot (HaveOccurred ())
302+ })
281303 })
282304 Context ("MAC address configuration" , func () {
283305
284306 var updatedPluginConf * localtypes.PluginConf
285307
286308 JustBeforeEach (func () {
287- successfullyGetNS ()
309+ successfullyGetNS (true )
288310 cleanupGetNS ()
289311 // workaround to access pluginConf
290312 managerMock .On ("AttachRepresentor" , mock .Anything ).Run (func (args mock.Arguments ) {
0 commit comments