@@ -20,6 +20,7 @@ import (
2020 "os"
2121 "path/filepath"
2222 "strconv"
23+ "strings"
2324 "testing"
2425
2526 "github.com/containerd/containerd"
@@ -39,11 +40,22 @@ const mib = 1024 * 1024
3940func TestVolumes_Isolated (t * testing.T ) {
4041 integtest .Prepare (t )
4142
43+ runtimes := []string {firecrackerRuntime , "io.containerd.runc.v2" }
44+
45+ for _ , rt := range runtimes {
46+ t .Run (rt , func (t * testing.T ) {
47+ testVolumes (t , rt )
48+ })
49+ }
50+ }
51+
52+ func testVolumes (t * testing.T , runtime string ) {
4253 const vmID = 0
54+ testName := strings .ReplaceAll (t .Name (), "/" , "_" )
4355
4456 ctx := namespaces .WithNamespace (context .Background (), "default" )
4557
46- client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
58+ client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (runtime ))
4759 require .NoError (t , err , "unable to create client to containerd service at %s, is containerd running?" , containerdSockPath )
4860 defer client .Close ()
4961
@@ -54,7 +66,7 @@ func TestVolumes_Isolated(t *testing.T) {
5466 require .NoError (t , err , "failed to create fccontrol client" )
5567
5668 // Make volumes.
57- path , err := os .MkdirTemp ("" , t . Name () )
69+ path , err := os .MkdirTemp ("" , testName )
5870 require .NoError (t , err )
5971
6072 f , err := os .Create (filepath .Join (path , "hello.txt" ))
@@ -64,22 +76,27 @@ func TestVolumes_Isolated(t *testing.T) {
6476 require .NoError (t , err )
6577
6678 const volName = "volume1"
67- vs := volume .NewSet ()
79+ vs := volume .NewSet (runtime )
6880 vs .Add (volume .FromHost (volName , path ))
6981
70- // Since CreateVM doesn't take functional options, we need to explicitly create
71- // a FirecrackerDriveMount
72- mount , err := vs .PrepareDriveMount (ctx , 10 * mib )
73- require .NoError (t , err )
74-
7582 containers := []string {"c1" , "c2" }
7683
77- _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
78- VMID : strconv .Itoa (vmID ),
79- ContainerCount : int32 (len (containers )),
80- DriveMounts : []* proto.FirecrackerDriveMount {mount },
81- })
82- require .NoError (t , err , "failed to create VM" )
84+ if runtime == firecrackerRuntime {
85+ // Since CreateVM doesn't take functional options, we need to explicitly create
86+ // a FirecrackerDriveMount
87+ mount , err := vs .PrepareDriveMount (ctx , 10 * mib )
88+ require .NoError (t , err )
89+
90+ _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
91+ VMID : strconv .Itoa (vmID ),
92+ ContainerCount : int32 (len (containers )),
93+ DriveMounts : []* proto.FirecrackerDriveMount {mount },
94+ })
95+ require .NoError (t , err , "failed to create VM" )
96+ } else {
97+ err := vs .PrepareDirectory (ctx )
98+ require .NoError (t , err )
99+ }
83100
84101 // Make containers with the volume.
85102 dir := "/path/in/container"
@@ -103,6 +120,8 @@ func TestVolumes_Isolated(t *testing.T) {
103120 )
104121 require .NoError (t , err , "failed to create container %s" , name )
105122
123+ defer container .Delete (ctx , containerd .WithSnapshotCleanup )
124+
106125 var stdout , stderr bytes.Buffer
107126
108127 task , err := container .NewTask (ctx , cio .NewCreator (cio .WithStreams (nil , & stdout , & stderr )))
@@ -135,6 +154,7 @@ func TestVolumes_Isolated(t *testing.T) {
135154 ),
136155 )
137156 require .NoError (t , err , "failed to create container %s" , name )
157+ defer container .Delete (ctx , containerd .WithSnapshotCleanup )
138158
139159 var stdout , stderr bytes.Buffer
140160 task , err := container .NewTask (ctx , cio .NewCreator (cio .WithStreams (nil , & stdout , & stderr )))
0 commit comments