@@ -70,6 +70,8 @@ type fakeExec struct {
70
70
delIndex int
71
71
chkIndex int
72
72
plugins []* fakePlugin
73
+
74
+ failFind bool
73
75
}
74
76
75
77
type TestConf struct {
@@ -167,6 +169,10 @@ func (f *fakeExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData
167
169
168
170
func (f * fakeExec ) FindInPath (plugin string , paths []string ) (string , error ) {
169
171
Expect (len (paths )).To (BeNumerically (">" , 0 ))
172
+
173
+ if f .failFind {
174
+ return "" , fmt .Errorf ("failed to find plugin %q in path %s" , plugin , paths )
175
+ }
170
176
return filepath .Join (paths [0 ], plugin ), nil
171
177
}
172
178
@@ -180,6 +186,7 @@ func ensureCIDR(cidr string) *net.IPNet {
180
186
var _ = Describe ("ocicni operations" , func () {
181
187
var (
182
188
tmpDir string
189
+ tmpBinDir string
183
190
cacheDir string
184
191
networkNS ns.NetNS
185
192
)
@@ -188,6 +195,8 @@ var _ = Describe("ocicni operations", func() {
188
195
var err error
189
196
tmpDir , err = ioutil .TempDir ("" , "ocicni_tmp" )
190
197
Expect (err ).NotTo (HaveOccurred ())
198
+ tmpBinDir , err = ioutil .TempDir ("" , "ocicni_tmp_bin" )
199
+ Expect (err ).NotTo (HaveOccurred ())
191
200
cacheDir , err = ioutil .TempDir ("" , "ocicni_cache" )
192
201
Expect (err ).NotTo (HaveOccurred ())
193
202
@@ -201,6 +210,8 @@ var _ = Describe("ocicni operations", func() {
201
210
202
211
err := os .RemoveAll (tmpDir )
203
212
Expect (err ).NotTo (HaveOccurred ())
213
+ err = os .RemoveAll (tmpBinDir )
214
+ Expect (err ).NotTo (HaveOccurred ())
204
215
err = os .RemoveAll (cacheDir )
205
216
Expect (err ).NotTo (HaveOccurred ())
206
217
})
@@ -247,6 +258,41 @@ var _ = Describe("ocicni operations", func() {
247
258
ocicni .Shutdown ()
248
259
})
249
260
261
+ It ("finds an asynchronously written default network configuration whose plugin is written later" , func () {
262
+ fExec := & fakeExec {failFind : true }
263
+ ocicni , err := initCNI (fExec , "" , "test" , tmpDir , true , tmpBinDir )
264
+ Expect (err ).NotTo (HaveOccurred ())
265
+
266
+ _ , _ , err = writeConfig (tmpDir , "10-test.conf" , "test" , "myplugin" , "0.3.1" )
267
+ Expect (err ).NotTo (HaveOccurred ())
268
+ Consistently (ocicni .Status , 5 ).ShouldNot (Succeed ())
269
+
270
+ // Write a file in the bindir to trigger the fsnotify code to resync
271
+ fExec .failFind = false
272
+ err = ioutil .WriteFile (filepath .Join (tmpBinDir , "myplugin" ), []byte ("adsfasdfsafd" ), 0755 )
273
+ Expect (err ).NotTo (HaveOccurred ())
274
+
275
+ tmp := ocicni .(* cniNetworkPlugin )
276
+ Eventually (func () error {
277
+ net := tmp .getDefaultNetwork ()
278
+ if net == nil {
279
+ return fmt .Errorf ("no default net" )
280
+ }
281
+ if net .name != "test" {
282
+ return fmt .Errorf ("name not test" )
283
+ }
284
+ if len (net .config .Plugins ) == 0 {
285
+ return fmt .Errorf ("no plugins" )
286
+ }
287
+ if net .config .Plugins [0 ].Network .Type != "myplugin" {
288
+ return fmt .Errorf ("wrong plugin type" )
289
+ }
290
+ return nil
291
+ }, 10 ).Should (Succeed ())
292
+
293
+ ocicni .Shutdown ()
294
+ })
295
+
250
296
It ("finds and refinds an asynchronously written default network configuration" , func () {
251
297
ocicni , err := initCNI (& fakeExec {}, "" , "test" , tmpDir , true , "/opt/cni/bin" )
252
298
Expect (err ).NotTo (HaveOccurred ())
0 commit comments