Skip to content

Commit 9e876ea

Browse files
committed
Test all StopVM cases with Jailer
Jailing must not affect the contracts StopVM has. Signed-off-by: Kazuyoshi Kato <[email protected]>
1 parent 47c3192 commit 9e876ea

File tree

1 file changed

+24
-48
lines changed

1 file changed

+24
-48
lines changed

runtime/service_integ_test.go

Lines changed: 24 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ const (
7676
var (
7777
findShim = findProcWithName(shimProcessName)
7878
findFirecracker = findProcWithName(firecrackerProcessName)
79-
findJailer = findProcWithName(jailerProcessName)
8079
)
8180

8281
// Images are presumed by the isolated tests to have already been pulled
@@ -1380,49 +1379,6 @@ func TestStopVM_Isolated(t *testing.T) {
13801379
},
13811380
},
13821381

1383-
{
1384-
name: "Jailer",
1385-
withStopVM: true,
1386-
1387-
createVMRequest: proto.CreateVMRequest{
1388-
JailerConfig: &proto.JailerConfig{
1389-
UID: 300000,
1390-
GID: 300000,
1391-
},
1392-
},
1393-
stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, vmID string) {
1394-
_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: vmID})
1395-
require.Equal(status.Code(err), codes.OK)
1396-
},
1397-
},
1398-
{
1399-
name: "Jailer SIGKILL",
1400-
createVMRequest: proto.CreateVMRequest{
1401-
JailerConfig: &proto.JailerConfig{
1402-
UID: 300000,
1403-
GID: 300000,
1404-
},
1405-
},
1406-
stopFunc: func(ctx context.Context, fcClient fccontrol.FirecrackerService, vmID string) {
1407-
firecrackerProcesses, err := internal.WaitForProcessToExist(ctx, time.Second, findJailer)
1408-
require.NoError(err, "failed waiting for expected firecracker process %q to come up", firecrackerProcessName)
1409-
require.Len(firecrackerProcesses, 1, "expected only one firecracker process to exist")
1410-
firecrackerProcess := firecrackerProcesses[0]
1411-
1412-
err = firecrackerProcess.KillWithContext(ctx)
1413-
require.NoError(err, "failed to kill firecracker process")
1414-
1415-
// Sleep here to ensure runc finishes execution
1416-
time.Sleep(500 * time.Millisecond)
1417-
1418-
// ensure that the jailer has cleaned up all of the containers
1419-
runcClient := &runc.Runc{}
1420-
containers, err := runcClient.List(ctx)
1421-
require.NoError(err, "failed to run 'runc list'")
1422-
assert.Equal(0, len(containers))
1423-
},
1424-
},
1425-
14261382
// Firecracker is too fast to test a case where we hit the timeout on a StopVMRequest.
14271383
// The rootfs below explicitly sleeps 60 seconds after shutting down the agent to simulate the case.
14281384
{
@@ -1493,13 +1449,12 @@ func TestStopVM_Isolated(t *testing.T) {
14931449

14941450
for _, test := range tests {
14951451
test := test
1496-
t.Run(test.name, func(t *testing.T) {
1452+
1453+
testFunc := func(t *testing.T, createVMRequest proto.CreateVMRequest) {
14971454
ctx, cancel := context.WithTimeout(ctx, 60*time.Second)
14981455
defer cancel()
14991456

1500-
vmID := testNameToVMID(t.Name())
1501-
createVMRequest := test.createVMRequest
1502-
createVMRequest.VMID = vmID
1457+
vmID := createVMRequest.VMID
15031458

15041459
fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())
15051460
_, err = fcClient.CreateVM(ctx, &createVMRequest)
@@ -1542,6 +1497,27 @@ func TestStopVM_Isolated(t *testing.T) {
15421497
// But it should be dead eventually.
15431498
err = internal.WaitForPidToExit(ctx, time.Second, shimProcess.Pid)
15441499
require.NoError(err, "shim hasn't been terminated")
1500+
}
1501+
1502+
t.Run(test.name, func(t *testing.T) {
1503+
req := test.createVMRequest
1504+
req.VMID = testNameToVMID(test.name)
1505+
testFunc(t, req)
1506+
})
1507+
1508+
t.Run(test.name+"/Jailer", func(t *testing.T) {
1509+
req := test.createVMRequest
1510+
req.VMID = testNameToVMID(test.name) + "_Jailer"
1511+
req.JailerConfig = &proto.JailerConfig{
1512+
UID: 300000,
1513+
GID: 300000,
1514+
}
1515+
testFunc(t, req)
1516+
1517+
runcClient := &runc.Runc{}
1518+
containers, err := runcClient.List(ctx)
1519+
require.NoError(err, "failed to run 'runc list'")
1520+
assert.Equal(0, len(containers))
15451521
})
15461522
}
15471523
}

0 commit comments

Comments
 (0)