Skip to content

Commit

Permalink
Added an integration test for the PauseVM and ResumeVM calls
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitrii Ustiugov <dmitrii.ustiugov@ed.ac.uk>
  • Loading branch information
ustiugov committed Feb 16, 2021
1 parent 2ac4770 commit 593dc36
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 3 deletions.
6 changes: 3 additions & 3 deletions runtime/cni_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/oci"
"github.com/containerd/containerd/pkg/ttrpcutil"
"github.com/shirou/gopsutil/cpu"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/firecracker-microvm/firecracker-containerd/config"
"github.com/firecracker-microvm/firecracker-containerd/internal"
"github.com/firecracker-microvm/firecracker-containerd/proto"
fccontrol "github.com/firecracker-microvm/firecracker-containerd/proto/service/fccontrol/ttrpc"
"github.com/firecracker-microvm/firecracker-containerd/runtime/firecrackeroci"
"github.com/shirou/gopsutil/cpu"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestCNISupport_Isolated(t *testing.T) {
Expand Down
87 changes: 87 additions & 0 deletions runtime/service_integ_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2032,6 +2032,93 @@ func TestCreateVM_Isolated(t *testing.T) {
}
}

func TestPauseResumeVM_Isolated(t *testing.T) {
prepareIntegTest(t)
client, err := containerd.New(containerdSockPath, containerd.WithDefaultRuntime(firecrackerRuntime))
require.NoError(t, err, "unable to create client to containerd service at %s, is containerd running?", containerdSockPath)
defer client.Close()

ctx := namespaces.WithNamespace(context.Background(), "default")

pluginClient, err := ttrpcutil.NewClient(containerdSockPath + ".ttrpc")
require.NoError(t, err, "failed to create ttrpc client")

fcClient := fccontrol.NewFirecrackerClient(pluginClient.Client())

type subtest struct {
name string
request proto.CreateVMRequest
validate func(*testing.T, error)
stopVM bool
}

subtests := []subtest{
{
name: "Happy Case",
request: proto.CreateVMRequest{},
validate: func(t *testing.T, err error) {
require.NoError(t, err)
},
stopVM: true,
},
}

runTest := func(t *testing.T, request proto.CreateVMRequest, s subtest) {
vmID := testNameToVMID(t.Name())

tempDir, err := ioutil.TempDir("", vmID)
require.NoError(t, err)
defer os.RemoveAll(tempDir)

logFile := filepath.Join(tempDir, "log.fifo")
metricsFile := filepath.Join(tempDir, "metrics.fifo")

request.VMID = vmID
request.LogFifoPath = logFile
request.MetricsFifoPath = metricsFile

resp, createVMErr := fcClient.CreateVM(ctx, &request)

// Even CreateVM fails, the log file and the metrics file must have some data.
requireNonEmptyFifo(t, logFile)
requireNonEmptyFifo(t, metricsFile)

// Some test cases are expected to have an error, some are not.
s.validate(t, createVMErr)

_, errPause := fcClient.PauseVM(ctx, &proto.PauseVMRequest{VMID: request.VMID})
require.NoError(t, errPause)

_, errResume := fcClient.ResumeVM(ctx, &proto.ResumeVMRequest{VMID: request.VMID})
require.NoError(t, errResume)

if createVMErr == nil && s.stopVM {
// Ensure the response fields are populated correctly
assert.Equal(t, request.VMID, resp.VMID)

_, err = fcClient.StopVM(ctx, &proto.StopVMRequest{VMID: request.VMID})
require.Equal(t, status.Code(err), codes.OK)
}
}

for _, _s := range subtests {
s := _s
request := s.request
t.Run(s.name, func(t *testing.T) {
runTest(t, request, s)
})

requestWithJailer := s.request
requestWithJailer.JailerConfig = &proto.JailerConfig{
UID: 30000,
GID: 30000,
}
t.Run(s.name+"/Jailer", func(t *testing.T) {
runTest(t, requestWithJailer, s)
})
}
}

func TestAttach_Isolated(t *testing.T) {
prepareIntegTest(t)

Expand Down

0 comments on commit 593dc36

Please sign in to comment.