@@ -20,6 +20,7 @@ import (
20
20
"os"
21
21
"path/filepath"
22
22
"strconv"
23
+ "strings"
23
24
"testing"
24
25
25
26
"github.com/containerd/containerd"
@@ -39,11 +40,22 @@ const mib = 1024 * 1024
39
40
func TestVolumes_Isolated (t * testing.T ) {
40
41
integtest .Prepare (t )
41
42
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 ) {
42
53
const vmID = 0
54
+ testName := strings .ReplaceAll (t .Name (), "/" , "_" )
43
55
44
56
ctx := namespaces .WithNamespace (context .Background (), "default" )
45
57
46
- client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
58
+ client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (runtime ))
47
59
require .NoError (t , err , "unable to create client to containerd service at %s, is containerd running?" , containerdSockPath )
48
60
defer client .Close ()
49
61
@@ -54,7 +66,7 @@ func TestVolumes_Isolated(t *testing.T) {
54
66
require .NoError (t , err , "failed to create fccontrol client" )
55
67
56
68
// Make volumes.
57
- path , err := os .MkdirTemp ("" , t . Name () )
69
+ path , err := os .MkdirTemp ("" , testName )
58
70
require .NoError (t , err )
59
71
60
72
f , err := os .Create (filepath .Join (path , "hello.txt" ))
@@ -64,22 +76,27 @@ func TestVolumes_Isolated(t *testing.T) {
64
76
require .NoError (t , err )
65
77
66
78
const volName = "volume1"
67
- vs := volume .NewSet ()
79
+ vs := volume .NewSet (runtime )
68
80
vs .Add (volume .FromHost (volName , path ))
69
81
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
-
75
82
containers := []string {"c1" , "c2" }
76
83
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
+ }
83
100
84
101
// Make containers with the volume.
85
102
dir := "/path/in/container"
@@ -103,6 +120,8 @@ func TestVolumes_Isolated(t *testing.T) {
103
120
)
104
121
require .NoError (t , err , "failed to create container %s" , name )
105
122
123
+ defer container .Delete (ctx , containerd .WithSnapshotCleanup )
124
+
106
125
var stdout , stderr bytes.Buffer
107
126
108
127
task , err := container .NewTask (ctx , cio .NewCreator (cio .WithStreams (nil , & stdout , & stderr )))
@@ -135,6 +154,7 @@ func TestVolumes_Isolated(t *testing.T) {
135
154
),
136
155
)
137
156
require .NoError (t , err , "failed to create container %s" , name )
157
+ defer container .Delete (ctx , containerd .WithSnapshotCleanup )
138
158
139
159
var stdout , stderr bytes.Buffer
140
160
task , err := container .NewTask (ctx , cio .NewCreator (cio .WithStreams (nil , & stdout , & stderr )))
0 commit comments