mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-04-28 19:54:35 +00:00
runtime: Add contexts to calls in unit tests
Modify calls in unit tests to use context since many functions were updated to accept local context to fix trace span ordering. Fixes #1355 Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
This commit is contained in:
parent
9e4932a6e2
commit
4bf84b4b2f
@ -77,7 +77,7 @@ func TestAcrnCapabilities(t *testing.T) {
|
||||
arch: &acrnArchBase{},
|
||||
}
|
||||
|
||||
caps := a.capabilities()
|
||||
caps := a.capabilities(a.ctx)
|
||||
assert.True(caps.IsBlockDeviceSupported())
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
}
|
||||
@ -144,7 +144,7 @@ func TestAcrnHotplugUnsupportedDeviceType(t *testing.T) {
|
||||
config: acrnConfig,
|
||||
}
|
||||
|
||||
_, err := a.hotplugAddDevice(&memoryDevice{0, 128, uint64(0), false}, fsDev)
|
||||
_, err := a.hotplugAddDevice(a.ctx, &memoryDevice{0, 128, uint64(0), false}, fsDev)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@ -205,7 +205,7 @@ func TestAcrnGetSandboxConsole(t *testing.T) {
|
||||
sandboxID := "testSandboxID"
|
||||
expected := filepath.Join(a.store.RunVMStoragePath(), sandboxID, consoleSocket)
|
||||
|
||||
proto, result, err := a.getSandboxConsole(sandboxID)
|
||||
proto, result, err := a.getSandboxConsole(a.ctx, sandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(result, expected)
|
||||
assert.Equal(proto, consoleProtoUnix)
|
||||
|
@ -258,7 +258,7 @@ func createAndStartSandbox(ctx context.Context, config SandboxConfig) (sandbox V
|
||||
}
|
||||
|
||||
// Start sandbox
|
||||
err = sandbox.Start()
|
||||
err = sandbox.Start(ctx)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
@ -276,7 +276,7 @@ func TestReleaseSandbox(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, s)
|
||||
|
||||
err = s.Release()
|
||||
err = s.Release(ctx)
|
||||
assert.Nil(t, err, "sandbox release failed: %v", err)
|
||||
}
|
||||
|
||||
@ -295,7 +295,7 @@ func TestCleanupContainer(t *testing.T) {
|
||||
for _, contID := range contIDs {
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
|
||||
c, err := s.CreateContainer(context.Background(), contConfig)
|
||||
c, err := p.CreateContainer(ctx, contConfig)
|
||||
if c == nil || err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -133,13 +134,15 @@ func TestUpdateCgroups(t *testing.T) {
|
||||
config: &SandboxConfig{SandboxCgroupOnly: false},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// empty path
|
||||
err := s.cgroupsUpdate()
|
||||
err := s.cgroupsUpdate(ctx)
|
||||
assert.NoError(err)
|
||||
|
||||
// path doesn't exist
|
||||
s.state.CgroupPath = "/abc/123/rgb"
|
||||
err = s.cgroupsUpdate()
|
||||
err = s.cgroupsUpdate(ctx)
|
||||
assert.Error(err)
|
||||
|
||||
if os.Getuid() != 0 {
|
||||
@ -153,7 +156,7 @@ func TestUpdateCgroups(t *testing.T) {
|
||||
s.hypervisor = &mockHypervisor{mockPid: 0}
|
||||
|
||||
// bad pid
|
||||
err = s.cgroupsUpdate()
|
||||
err = s.cgroupsUpdate(ctx)
|
||||
assert.Error(err)
|
||||
|
||||
// fake workload
|
||||
@ -162,7 +165,7 @@ func TestUpdateCgroups(t *testing.T) {
|
||||
s.hypervisor = &mockHypervisor{mockPid: cmd.Process.Pid}
|
||||
|
||||
// no containers
|
||||
err = s.cgroupsUpdate()
|
||||
err = s.cgroupsUpdate(ctx)
|
||||
assert.NoError(err)
|
||||
|
||||
s.config = &SandboxConfig{}
|
||||
@ -189,7 +192,7 @@ func TestUpdateCgroups(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = s.cgroupsUpdate()
|
||||
err = s.cgroupsUpdate(context.Background())
|
||||
assert.NoError(err)
|
||||
|
||||
// cleanup
|
||||
|
@ -97,7 +97,7 @@ func TestContainerRemoveDrive(t *testing.T) {
|
||||
}
|
||||
|
||||
container.state.Fstype = ""
|
||||
err := container.removeDrive()
|
||||
err := container.removeDrive(sandbox.ctx)
|
||||
|
||||
// hotplugRemoveDevice for hypervisor should not be called.
|
||||
// test should pass without a hypervisor created for the container's sandbox.
|
||||
@ -116,12 +116,12 @@ func TestContainerRemoveDrive(t *testing.T) {
|
||||
assert.Nil(t, err)
|
||||
_, ok := device.(*drivers.BlockDevice)
|
||||
assert.True(t, ok)
|
||||
err = device.Attach(devReceiver)
|
||||
err = device.Attach(sandbox.ctx, devReceiver)
|
||||
assert.Nil(t, err)
|
||||
|
||||
container.state.Fstype = "xfs"
|
||||
container.state.BlockDeviceID = device.DeviceID()
|
||||
err = container.removeDrive()
|
||||
err = container.removeDrive(sandbox.ctx)
|
||||
assert.Nil(t, err, "remove drive should succeed")
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ func TestUnmountHostMountsRemoveBindHostPath(t *testing.T) {
|
||||
}
|
||||
defer syscall.Unmount(devPath, 0)
|
||||
|
||||
err := c.unmountHostMounts()
|
||||
err := c.unmountHostMounts(c.ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -341,7 +341,7 @@ func TestContainerAddDriveDir(t *testing.T) {
|
||||
|
||||
container.state.Fstype = ""
|
||||
|
||||
err = container.hotplugDrive()
|
||||
err = container.hotplugDrive(sandbox.ctx)
|
||||
assert.NoError(err)
|
||||
|
||||
assert.NotEmpty(container.state.Fstype)
|
||||
@ -380,14 +380,14 @@ func TestContainerRootfsPath(t *testing.T) {
|
||||
rootfsSuffix: "rootfs",
|
||||
}
|
||||
|
||||
container.hotplugDrive()
|
||||
container.hotplugDrive(sandbox.ctx)
|
||||
assert.Empty(t, container.rootfsSuffix)
|
||||
|
||||
// Reset the value to test the other case
|
||||
container.rootFs = RootFs{Target: fakeRootfs + "/rootfs", Mounted: true}
|
||||
container.rootfsSuffix = "rootfs"
|
||||
|
||||
container.hotplugDrive()
|
||||
container.hotplugDrive(sandbox.ctx)
|
||||
assert.Equal(t, container.rootfsSuffix, "rootfs")
|
||||
}
|
||||
|
||||
@ -428,18 +428,20 @@ func TestContainerEnterErrorsOnContainerStates(t *testing.T) {
|
||||
}
|
||||
cmd := types.Cmd{}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Container state undefined
|
||||
_, err := c.enter(cmd)
|
||||
_, err := c.enter(ctx, cmd)
|
||||
assert.Error(err)
|
||||
|
||||
// Container paused
|
||||
c.state.State = types.StatePaused
|
||||
_, err = c.enter(cmd)
|
||||
_, err = c.enter(ctx, cmd)
|
||||
assert.Error(err)
|
||||
|
||||
// Container stopped
|
||||
c.state.State = types.StateStopped
|
||||
_, err = c.enter(cmd)
|
||||
_, err = c.enter(ctx, cmd)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@ -454,18 +456,20 @@ func TestContainerWaitErrorState(t *testing.T) {
|
||||
}
|
||||
processID := "foobar"
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Container state undefined
|
||||
_, err := c.wait(processID)
|
||||
_, err := c.wait(ctx, processID)
|
||||
assert.Error(err)
|
||||
|
||||
// Container paused
|
||||
c.state.State = types.StatePaused
|
||||
_, err = c.wait(processID)
|
||||
_, err = c.wait(ctx, processID)
|
||||
assert.Error(err)
|
||||
|
||||
// Container stopped
|
||||
c.state.State = types.StateStopped
|
||||
_, err = c.wait(processID)
|
||||
_, err = c.wait(ctx, processID)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@ -478,13 +482,16 @@ func TestKillContainerErrorState(t *testing.T) {
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Container state undefined
|
||||
err := c.kill(syscall.SIGKILL, true)
|
||||
err := c.kill(ctx, syscall.SIGKILL, true)
|
||||
assert.Error(err)
|
||||
|
||||
// Container stopped
|
||||
c.state.State = types.StateStopped
|
||||
err = c.kill(syscall.SIGKILL, true)
|
||||
err = c.kill(ctx, syscall.SIGKILL, true)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@ -499,18 +506,20 @@ func TestWinsizeProcessErrorState(t *testing.T) {
|
||||
}
|
||||
processID := "foobar"
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
// Container state undefined
|
||||
err := c.winsizeProcess(processID, 100, 200)
|
||||
err := c.winsizeProcess(ctx, processID, 100, 200)
|
||||
assert.Error(err)
|
||||
|
||||
// Container paused
|
||||
c.state.State = types.StatePaused
|
||||
err = c.winsizeProcess(processID, 100, 200)
|
||||
err = c.winsizeProcess(ctx, processID, 100, 200)
|
||||
assert.Error(err)
|
||||
|
||||
// Container stopped
|
||||
c.state.State = types.StateStopped
|
||||
err = c.winsizeProcess(processID, 100, 200)
|
||||
err = c.winsizeProcess(ctx, processID, 100, 200)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ func TestAttachGenericDevice(t *testing.T) {
|
||||
assert.True(t, ok)
|
||||
|
||||
devReceiver := &api.MockDeviceReceiver{}
|
||||
err = device.Attach(devReceiver)
|
||||
err = device.Attach(context.Background(), devReceiver)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = device.Detach(context.Background(), devReceiver)
|
||||
@ -211,7 +211,7 @@ func TestAttachBlockDevice(t *testing.T) {
|
||||
dm.blockDriver = VirtioSCSI
|
||||
device, err = dm.NewDevice(deviceInfo)
|
||||
assert.Nil(t, err)
|
||||
err = device.Attach(devReceiver)
|
||||
err = device.Attach(context.Background(), devReceiver)
|
||||
assert.Nil(t, err)
|
||||
|
||||
err = device.Detach(context.Background(), devReceiver)
|
||||
|
@ -71,7 +71,7 @@ func Example_createAndStartSandbox() {
|
||||
}
|
||||
|
||||
// Start the sandbox
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
if err != nil {
|
||||
fmt.Printf("Could not start sandbox: %s", err)
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ func TestTemplateFactory(t *testing.T) {
|
||||
vm, err := f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// CloseFactory
|
||||
|
@ -42,7 +42,7 @@ func TestTemplateFactory(t *testing.T) {
|
||||
vm, err := f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// CloseFactory
|
||||
|
@ -184,7 +184,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err := f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
f.CloseFactory(ctx)
|
||||
@ -196,7 +196,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
f.CloseFactory(ctx)
|
||||
@ -211,7 +211,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
f.CloseFactory(ctx)
|
||||
@ -223,7 +223,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
f.CloseFactory(ctx)
|
||||
@ -235,7 +235,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// CPU hotplug
|
||||
@ -243,7 +243,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// Memory hotplug
|
||||
@ -251,7 +251,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// checkConfig fall back
|
||||
@ -259,7 +259,7 @@ func TestFactoryGetVM(t *testing.T) {
|
||||
vm, err = f.GetVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
f.CloseFactory(ctx)
|
||||
|
@ -63,7 +63,7 @@ func TestTemplateFactory(t *testing.T) {
|
||||
vm, err := f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// Fetch
|
||||
@ -93,13 +93,13 @@ func TestTemplateFactory(t *testing.T) {
|
||||
vm, err = tt.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
vm, err = f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
err = tt.createTemplateVM(ctx)
|
||||
@ -108,13 +108,13 @@ func TestTemplateFactory(t *testing.T) {
|
||||
vm, err = tt.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
vm, err = f.GetBaseVM(ctx, vmConfig)
|
||||
assert.Nil(err)
|
||||
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
// CloseFactory
|
||||
|
@ -63,7 +63,7 @@ func TestKataAgentConnect(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = k.connect()
|
||||
err = k.connect(context.Background())
|
||||
assert.NoError(err)
|
||||
assert.NotNil(k.client)
|
||||
}
|
||||
@ -86,8 +86,8 @@ func TestKataAgentDisconnect(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
assert.NoError(k.connect())
|
||||
assert.NoError(k.disconnect())
|
||||
assert.NoError(k.connect(context.Background()))
|
||||
assert.NoError(k.disconnect(context.Background()))
|
||||
assert.Nil(k.client)
|
||||
}
|
||||
|
||||
@ -123,8 +123,10 @@ func TestKataAgentSendReq(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
for _, req := range reqList {
|
||||
_, err = k.sendReq(req)
|
||||
_, err = k.sendReq(ctx, req)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
@ -132,52 +134,52 @@ func TestKataAgentSendReq(t *testing.T) {
|
||||
container := &Container{}
|
||||
execid := "processFooBar"
|
||||
|
||||
err = k.startContainer(sandbox, container)
|
||||
err = k.startContainer(ctx, sandbox, container)
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.signalProcess(container, execid, syscall.SIGKILL, true)
|
||||
err = k.signalProcess(ctx, container, execid, syscall.SIGKILL, true)
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.winsizeProcess(container, execid, 100, 200)
|
||||
err = k.winsizeProcess(ctx, container, execid, 100, 200)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.processListContainer(sandbox, Container{}, ProcessListOptions{})
|
||||
_, err = k.processListContainer(ctx, sandbox, Container{}, ProcessListOptions{})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.updateContainer(sandbox, Container{}, specs.LinuxResources{})
|
||||
err = k.updateContainer(ctx, sandbox, Container{}, specs.LinuxResources{})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.pauseContainer(sandbox, Container{})
|
||||
err = k.pauseContainer(ctx, sandbox, Container{})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.resumeContainer(sandbox, Container{})
|
||||
err = k.resumeContainer(ctx, sandbox, Container{})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.onlineCPUMem(1, true)
|
||||
err = k.onlineCPUMem(ctx, 1, true)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.statsContainer(sandbox, Container{})
|
||||
_, err = k.statsContainer(ctx, sandbox, Container{})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.check()
|
||||
err = k.check(ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.waitProcess(container, execid)
|
||||
_, err = k.waitProcess(ctx, container, execid)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.writeProcessStdin(container, execid, []byte{'c'})
|
||||
_, err = k.writeProcessStdin(ctx, container, execid, []byte{'c'})
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.closeProcessStdin(container, execid)
|
||||
err = k.closeProcessStdin(ctx, container, execid)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.readProcessStdout(container, execid, []byte{})
|
||||
_, err = k.readProcessStdout(ctx, container, execid, []byte{})
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.readProcessStderr(container, execid, []byte{})
|
||||
_, err = k.readProcessStderr(ctx, container, execid, []byte{})
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.getOOMEvent()
|
||||
_, err = k.getOOMEvent(ctx)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
@ -753,15 +755,16 @@ func TestAgentConfigure(t *testing.T) {
|
||||
h := &mockHypervisor{}
|
||||
c := KataAgentConfig{}
|
||||
id := "foobar"
|
||||
ctx := context.Background()
|
||||
|
||||
err = k.configure(h, id, dir, c)
|
||||
err = k.configure(ctx, h, id, dir, c)
|
||||
assert.Nil(err)
|
||||
|
||||
err = k.configure(h, id, dir, c)
|
||||
err = k.configure(ctx, h, id, dir, c)
|
||||
assert.Nil(err)
|
||||
assert.Empty(k.state.URL)
|
||||
|
||||
err = k.configure(h, id, dir, c)
|
||||
err = k.configure(ctx, h, id, dir, c)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
@ -864,11 +867,11 @@ func TestAgentCreateContainer(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
err = k.configure(&mockHypervisor{}, sandbox.id, dir, KataAgentConfig{})
|
||||
err = k.configure(context.Background(), &mockHypervisor{}, sandbox.id, dir, KataAgentConfig{})
|
||||
assert.Nil(err)
|
||||
|
||||
// We'll fail on container metadata file creation, but it helps increasing coverage...
|
||||
_, err = k.createContainer(sandbox, container)
|
||||
_, err = k.createContainer(context.Background(), sandbox, container)
|
||||
assert.Error(err)
|
||||
}
|
||||
|
||||
@ -890,16 +893,16 @@ func TestAgentNetworkOperation(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
_, err = k.updateInterface(nil)
|
||||
_, err = k.updateInterface(k.ctx, nil)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.listInterfaces()
|
||||
_, err = k.listInterfaces(k.ctx)
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.updateRoutes([]*pbTypes.Route{})
|
||||
_, err = k.updateRoutes(k.ctx, []*pbTypes.Route{})
|
||||
assert.Nil(err)
|
||||
|
||||
_, err = k.listRoutes()
|
||||
_, err = k.listRoutes(k.ctx)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
@ -938,7 +941,7 @@ func TestKataCopyFile(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
err = k.copyFile("/abc/xyz/123", "/tmp")
|
||||
err = k.copyFile(context.Background(), "/abc/xyz/123", "/tmp")
|
||||
assert.Error(err)
|
||||
|
||||
src, err := ioutil.TempFile("", "src")
|
||||
@ -961,7 +964,7 @@ func TestKataCopyFile(t *testing.T) {
|
||||
grpcMaxDataSize = orgGrpcMaxDataSize
|
||||
}()
|
||||
|
||||
err = k.copyFile(src.Name(), dst.Name())
|
||||
err = k.copyFile(context.Background(), src.Name(), dst.Name())
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@ -987,7 +990,7 @@ func TestKataCleanupSandbox(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
|
||||
k := &kataAgent{ctx: context.Background()}
|
||||
k.cleanup(&s)
|
||||
k.cleanup(context.Background(), &s)
|
||||
|
||||
_, err = os.Stat(dir)
|
||||
assert.False(os.IsExist(err))
|
||||
|
@ -53,7 +53,7 @@ func TestMockHypervisorStartSandbox(t *testing.T) {
|
||||
func TestMockHypervisorStopSandbox(t *testing.T) {
|
||||
var m *mockHypervisor
|
||||
|
||||
assert.NoError(t, m.stopSandbox())
|
||||
assert.NoError(t, m.stopSandbox(context.Background()))
|
||||
}
|
||||
|
||||
func TestMockHypervisorAddDevice(t *testing.T) {
|
||||
@ -67,7 +67,7 @@ func TestMockHypervisorGetSandboxConsole(t *testing.T) {
|
||||
|
||||
expected := ""
|
||||
expectedProto := ""
|
||||
proto, result, err := m.getSandboxConsole("testSandboxID")
|
||||
proto, result, err := m.getSandboxConsole(context.Background(), "testSandboxID")
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, result, expected)
|
||||
assert.Equal(t, proto, expectedProto)
|
||||
@ -82,7 +82,7 @@ func TestMockHypervisorSaveSandbox(t *testing.T) {
|
||||
func TestMockHypervisorDisconnect(t *testing.T) {
|
||||
var m *mockHypervisor
|
||||
|
||||
m.disconnect()
|
||||
m.disconnect(context.Background())
|
||||
}
|
||||
|
||||
func TestMockHypervisorCheck(t *testing.T) {
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
@ -25,11 +26,11 @@ func TestMonitorSuccess(t *testing.T) {
|
||||
|
||||
m := newMonitor(s)
|
||||
|
||||
ch, err := m.newWatcher()
|
||||
ch, err := m.newWatcher(context.Background())
|
||||
assert.Nil(err, "newWatcher failed: %v", err)
|
||||
|
||||
fakeErr := errors.New("foobar error")
|
||||
m.notify(fakeErr)
|
||||
m.notify(context.Background(), fakeErr)
|
||||
resultErr := <-ch
|
||||
assert.True(resultErr == fakeErr, "monitor notification mismatch %v vs. %v", resultErr, fakeErr)
|
||||
|
||||
@ -49,12 +50,12 @@ func TestMonitorClosedChannel(t *testing.T) {
|
||||
|
||||
m := newMonitor(s)
|
||||
|
||||
ch, err := m.newWatcher()
|
||||
ch, err := m.newWatcher(context.Background())
|
||||
assert.Nil(err, "newWatcher failed: %v", err)
|
||||
|
||||
close(ch)
|
||||
fakeErr := errors.New("foobar error")
|
||||
m.notify(fakeErr)
|
||||
m.notify(context.Background(), fakeErr)
|
||||
|
||||
m.stop()
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
package vcmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"syscall"
|
||||
|
@ -6,6 +6,7 @@
|
||||
package virtcontainers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
@ -146,12 +147,12 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
|
||||
q.bridges(1)
|
||||
for i := uint32(1); i <= types.PCIBridgeMaxCapacity; i++ {
|
||||
_, _, err := q.addDeviceToBridge(fmt.Sprintf("qemu-bridge-%d", i), types.PCI)
|
||||
_, _, err := q.addDeviceToBridge(context.Background(), fmt.Sprintf("qemu-bridge-%d", i), types.PCI)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
// fail to add device to bridge cause no more available bridge slot
|
||||
_, _, err := q.addDeviceToBridge("qemu-bridge-31", types.PCI)
|
||||
_, _, err := q.addDeviceToBridge(context.Background(), "qemu-bridge-31", types.PCI)
|
||||
exceptErr := errors.New("no more bridge slots available")
|
||||
assert.Equal(exceptErr.Error(), err.Error())
|
||||
|
||||
@ -159,7 +160,7 @@ func TestQemuAddDeviceToBridge(t *testing.T) {
|
||||
q = newQemuArchBase()
|
||||
q.qemuMachine.Type = QemuPCLite
|
||||
q.bridges(0)
|
||||
_, _, err = q.addDeviceToBridge("qemu-bridge", types.PCI)
|
||||
_, _, err = q.addDeviceToBridge(context.Background(), "qemu-bridge", types.PCI)
|
||||
if assert.Error(err) {
|
||||
exceptErr = errors.New("failed to get available address from bridges")
|
||||
assert.Equal(exceptErr.Error(), err.Error())
|
||||
|
@ -333,7 +333,7 @@ func TestQemuGetSandboxConsole(t *testing.T) {
|
||||
sandboxID := "testSandboxID"
|
||||
expected := filepath.Join(q.store.RunVMStoragePath(), sandboxID, consoleSocket)
|
||||
|
||||
proto, result, err := q.getSandboxConsole(sandboxID)
|
||||
proto, result, err := q.getSandboxConsole(q.ctx, sandboxID)
|
||||
assert.NoError(err)
|
||||
assert.Equal(result, expected)
|
||||
assert.Equal(proto, consoleProtoUnix)
|
||||
@ -346,7 +346,7 @@ func TestQemuCapabilities(t *testing.T) {
|
||||
arch: &qemuArchBase{},
|
||||
}
|
||||
|
||||
caps := q.capabilities()
|
||||
caps := q.capabilities(q.ctx)
|
||||
assert.True(caps.IsBlockDeviceHotplugSupported())
|
||||
}
|
||||
|
||||
@ -431,7 +431,7 @@ func TestQemuCleanup(t *testing.T) {
|
||||
config: newQemuConfig(),
|
||||
}
|
||||
|
||||
err := q.cleanup()
|
||||
err := q.cleanup(q.ctx)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
@ -444,7 +444,7 @@ func TestQemuGrpc(t *testing.T) {
|
||||
config: config,
|
||||
}
|
||||
|
||||
json, err := q.toGrpc()
|
||||
json, err := q.toGrpc(context.Background())
|
||||
assert.Nil(err)
|
||||
|
||||
var q2 qemu
|
||||
|
@ -68,11 +68,11 @@ func testCreateSandbox(t *testing.T, id string,
|
||||
return nil, fmt.Errorf("Could not create sandbox: %s", err)
|
||||
}
|
||||
|
||||
if err := sandbox.agent.startSandbox(sandbox); err != nil {
|
||||
if err := sandbox.agent.startSandbox(context.Background(), sandbox); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := sandbox.createContainers(); err != nil {
|
||||
if err := sandbox.createContainers(context.Background()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@ -365,7 +365,7 @@ func TestSandboxSetSandboxAndContainerState(t *testing.T) {
|
||||
assert.NoError(err)
|
||||
|
||||
// clean up
|
||||
err = p.Delete()
|
||||
err = p.Delete(context.Background())
|
||||
assert.NoError(err)
|
||||
}
|
||||
|
||||
@ -465,7 +465,7 @@ func TestSandboxGetContainer(t *testing.T) {
|
||||
|
||||
contID := "999"
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
nc, err := newContainer(p, &contConfig)
|
||||
nc, err := newContainer(context.Background(), p, &contConfig)
|
||||
assert.NoError(err)
|
||||
|
||||
err = p.addContainer(nc)
|
||||
@ -578,10 +578,10 @@ func TestSandboxAttachDevicesVFIO(t *testing.T) {
|
||||
|
||||
containers[c.id].sandbox = &sandbox
|
||||
|
||||
err = containers[c.id].attachDevices(c.devices)
|
||||
err = containers[c.id].attachDevices(context.Background(), c.devices)
|
||||
assert.Nil(t, err, "Error while attaching devices %s", err)
|
||||
|
||||
err = containers[c.id].detachDevices()
|
||||
err = containers[c.id].detachDevices(context.Background())
|
||||
assert.Nil(t, err, "Error while detaching devices %s", err)
|
||||
}
|
||||
|
||||
@ -673,10 +673,10 @@ func TestSandboxAttachDevicesVhostUserBlk(t *testing.T) {
|
||||
|
||||
containers[c.id].sandbox = &sandbox
|
||||
|
||||
err = containers[c.id].attachDevices(c.devices)
|
||||
err = containers[c.id].attachDevices(context.Background(), c.devices)
|
||||
assert.Nil(t, err, "Error while attaching vhost-user-blk devices %s", err)
|
||||
|
||||
err = containers[c.id].detachDevices()
|
||||
err = containers[c.id].detachDevices(context.Background())
|
||||
assert.Nil(t, err, "Error while detaching vhost-user-blk devices %s", err)
|
||||
}
|
||||
|
||||
@ -892,14 +892,14 @@ func TestDeleteContainer(t *testing.T) {
|
||||
defer cleanUp()
|
||||
|
||||
contID := "999"
|
||||
_, err = s.DeleteContainer(contID)
|
||||
_, err = s.DeleteContainer(context.Background(), contID)
|
||||
assert.NotNil(t, err, "Deletng non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(context.Background(), contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
_, err = s.DeleteContainer(contID)
|
||||
_, err = s.DeleteContainer(context.Background(), contID)
|
||||
assert.Nil(t, err, "Failed to delete container %s in sandbox %s: %v", contID, s.ID(), err)
|
||||
}
|
||||
|
||||
@ -912,7 +912,7 @@ func TestStartContainer(t *testing.T) {
|
||||
_, err = s.StartContainer(context.Background(), contID)
|
||||
assert.NotNil(t, err, "Starting non-existing container should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
@ -939,7 +939,7 @@ func TestStatusContainer(t *testing.T) {
|
||||
_, err = s.StatusContainer(contID)
|
||||
assert.Nil(t, err, "Status container failed: %v", err)
|
||||
|
||||
_, err = s.DeleteContainer(contID)
|
||||
_, err = s.DeleteContainer(context.Background(), contID)
|
||||
assert.Nil(t, err, "Failed to delete container %s in sandbox %s: %v", contID, s.ID(), err)
|
||||
}
|
||||
|
||||
@ -958,20 +958,20 @@ func TestEnterContainer(t *testing.T) {
|
||||
|
||||
contID := "999"
|
||||
cmd := types.Cmd{}
|
||||
_, _, err = s.EnterContainer(contID, cmd)
|
||||
_, _, err = s.EnterContainer(context.Background(), contID, cmd)
|
||||
assert.NotNil(t, err, "Entering non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(context.Background(), contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
_, _, err = s.EnterContainer(contID, cmd)
|
||||
_, _, err = s.EnterContainer(context.Background(), contID, cmd)
|
||||
assert.NotNil(t, err, "Entering non-running container should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
_, _, err = s.EnterContainer(contID, cmd)
|
||||
_, _, err = s.EnterContainer(context.Background(), contID, cmd)
|
||||
assert.Nil(t, err, "Enter container failed: %v", err)
|
||||
}
|
||||
|
||||
@ -1007,7 +1007,7 @@ func TestDeleteStoreWhenNewContainerFail(t *testing.T) {
|
||||
DevType: "",
|
||||
},
|
||||
}
|
||||
_, err = newContainer(p, &contConfig)
|
||||
_, err = newContainer(context.Background(), p, &contConfig)
|
||||
assert.NotNil(t, err, "New container with invalid device info should fail")
|
||||
storePath := filepath.Join(p.newStore.RunStoragePath(), testSandboxID, contID)
|
||||
_, err = os.Stat(storePath)
|
||||
@ -1019,16 +1019,16 @@ func TestMonitor(t *testing.T) {
|
||||
assert.Nil(t, err, "VirtContainers should not allow empty sandboxes")
|
||||
defer cleanUp()
|
||||
|
||||
_, err = s.Monitor()
|
||||
_, err = s.Monitor(context.Background())
|
||||
assert.NotNil(t, err, "Monitoring non-running container should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
_, err = s.Monitor()
|
||||
_, err = s.Monitor(context.Background())
|
||||
assert.Nil(t, err, "Monitor sandbox failed: %v", err)
|
||||
|
||||
_, err = s.Monitor()
|
||||
_, err = s.Monitor(context.Background())
|
||||
assert.Nil(t, err, "Monitor sandbox again failed: %v", err)
|
||||
|
||||
s.monitor.stop()
|
||||
@ -1041,26 +1041,26 @@ func TestWaitProcess(t *testing.T) {
|
||||
|
||||
contID := "foo"
|
||||
execID := "bar"
|
||||
_, err = s.WaitProcess(contID, execID)
|
||||
_, err = s.WaitProcess(context.Background(), contID, execID)
|
||||
assert.NotNil(t, err, "Wait process in stopped sandbox should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
_, err = s.WaitProcess(contID, execID)
|
||||
_, err = s.WaitProcess(context.Background(), contID, execID)
|
||||
assert.NotNil(t, err, "Wait process in non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(context.Background(), contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
_, err = s.WaitProcess(contID, execID)
|
||||
_, err = s.WaitProcess(context.Background(), contID, execID)
|
||||
assert.Nil(t, err, "Wait process in ready container failed: %v", err)
|
||||
|
||||
_, err = s.StartContainer(context.Background(), contID)
|
||||
assert.Nil(t, err, "Start container failed: %v", err)
|
||||
|
||||
_, err = s.WaitProcess(contID, execID)
|
||||
_, err = s.WaitProcess(context.Background(), contID, execID)
|
||||
assert.Nil(t, err, "Wait process failed: %v", err)
|
||||
}
|
||||
|
||||
@ -1071,26 +1071,26 @@ func TestSignalProcess(t *testing.T) {
|
||||
|
||||
contID := "foo"
|
||||
execID := "bar"
|
||||
err = s.SignalProcess(contID, execID, syscall.SIGKILL, true)
|
||||
err = s.SignalProcess(context.Background(), contID, execID, syscall.SIGKILL, true)
|
||||
assert.NotNil(t, err, "Wait process in stopped sandbox should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
err = s.SignalProcess(contID, execID, syscall.SIGKILL, false)
|
||||
err = s.SignalProcess(context.Background(), contID, execID, syscall.SIGKILL, false)
|
||||
assert.NotNil(t, err, "Wait process in non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(context.Background(), contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
err = s.SignalProcess(contID, execID, syscall.SIGKILL, true)
|
||||
err = s.SignalProcess(context.Background(), contID, execID, syscall.SIGKILL, true)
|
||||
assert.Nil(t, err, "Wait process in ready container failed: %v", err)
|
||||
|
||||
_, err = s.StartContainer(context.Background(), contID)
|
||||
assert.Nil(t, err, "Start container failed: %v", err)
|
||||
|
||||
err = s.SignalProcess(contID, execID, syscall.SIGKILL, false)
|
||||
err = s.SignalProcess(context.Background(), contID, execID, syscall.SIGKILL, false)
|
||||
assert.Nil(t, err, "Wait process failed: %v", err)
|
||||
}
|
||||
|
||||
@ -1101,26 +1101,26 @@ func TestWinsizeProcess(t *testing.T) {
|
||||
|
||||
contID := "foo"
|
||||
execID := "bar"
|
||||
err = s.WinsizeProcess(contID, execID, 100, 200)
|
||||
err = s.WinsizeProcess(context.Background(), contID, execID, 100, 200)
|
||||
assert.NotNil(t, err, "Winsize process in stopped sandbox should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
err = s.WinsizeProcess(contID, execID, 100, 200)
|
||||
err = s.WinsizeProcess(context.Background(), contID, execID, 100, 200)
|
||||
assert.NotNil(t, err, "Winsize process in non-existing container should fail")
|
||||
|
||||
contConfig := newTestContainerConfigNoop(contID)
|
||||
_, err = s.CreateContainer(context.Background(), contConfig)
|
||||
assert.Nil(t, err, "Failed to create container %+v in sandbox %+v: %v", contConfig, s, err)
|
||||
|
||||
err = s.WinsizeProcess(contID, execID, 100, 200)
|
||||
err = s.WinsizeProcess(context.Background(), contID, execID, 100, 200)
|
||||
assert.Nil(t, err, "Winsize process in ready container failed: %v", err)
|
||||
|
||||
_, err = s.StartContainer(context.Background(), contID)
|
||||
assert.Nil(t, err, "Start container failed: %v", err)
|
||||
|
||||
err = s.WinsizeProcess(contID, execID, 100, 200)
|
||||
err = s.WinsizeProcess(context.Background(), contID, execID, 100, 200)
|
||||
assert.Nil(t, err, "Winsize process failed: %v", err)
|
||||
}
|
||||
|
||||
@ -1134,7 +1134,7 @@ func TestContainerProcessIOStream(t *testing.T) {
|
||||
_, _, _, err = s.IOStream(contID, execID)
|
||||
assert.NotNil(t, err, "Winsize process in stopped sandbox should fail")
|
||||
|
||||
err = s.Start()
|
||||
err = s.Start(context.Background())
|
||||
assert.Nil(t, err, "Failed to start sandbox: %v", err)
|
||||
|
||||
_, _, _, err = s.IOStream(contID, execID)
|
||||
@ -1297,7 +1297,7 @@ func TestPreAddDevice(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
mounts, ignoreMounts, err := container.mountSharedDirMounts("", "", "")
|
||||
mounts, ignoreMounts, err := container.mountSharedDirMounts(context.Background(), "", "", "")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, len(mounts), 0,
|
||||
"mounts should contain nothing because it only contains a block device")
|
||||
@ -1344,7 +1344,7 @@ func TestStartNetworkMonitor(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
}
|
||||
|
||||
err = s.startNetworkMonitor()
|
||||
err = s.startNetworkMonitor(context.Background())
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
||||
@ -1353,7 +1353,7 @@ func TestSandboxStopStopped(t *testing.T) {
|
||||
ctx: context.Background(),
|
||||
state: types.SandboxState{State: types.StateStopped},
|
||||
}
|
||||
err := s.Stop(false)
|
||||
err := s.Stop(context.Background(), false)
|
||||
|
||||
assert.Nil(t, err)
|
||||
}
|
||||
|
@ -284,6 +284,6 @@ func (v *virtiofsdMock) Start(ctx context.Context) (int, error) {
|
||||
return 9999999, nil
|
||||
}
|
||||
|
||||
func (v *virtiofsdMock) Stop() error {
|
||||
func (v *virtiofsdMock) Stop(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
@ -41,25 +41,25 @@ func TestNewVM(t *testing.T) {
|
||||
assert.Nil(err)
|
||||
|
||||
// VM operations
|
||||
err = vm.Pause()
|
||||
err = vm.Pause(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.Resume()
|
||||
err = vm.Resume(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.Start()
|
||||
err = vm.Start(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.Disconnect()
|
||||
err = vm.Disconnect(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.Save()
|
||||
assert.Nil(err)
|
||||
err = vm.Stop()
|
||||
err = vm.Stop(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.AddCPUs(2)
|
||||
err = vm.AddCPUs(context.Background(), 2)
|
||||
assert.Nil(err)
|
||||
err = vm.AddMemory(128)
|
||||
err = vm.AddMemory(context.Background(), 128)
|
||||
assert.Nil(err)
|
||||
err = vm.OnlineCPUMemory()
|
||||
err = vm.OnlineCPUMemory(context.Background())
|
||||
assert.Nil(err)
|
||||
err = vm.ReseedRNG()
|
||||
err = vm.ReseedRNG(context.Background())
|
||||
assert.Nil(err)
|
||||
|
||||
// template VM
|
||||
|
Loading…
Reference in New Issue
Block a user