mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-24 01:24:26 +01:00
Fixed logic used to handle static agent tracing. For a standard (untraced) hypervisor shutdown, the runtime kills the VM process once the workload has finished. But if static agent tracing is enabled, the agent running inside the VM is responsible for the shutdown. The existing code handled this scenario but did not wait for the hypervisor process to end. The outcome of this being that the console watcher thread was killed too early. Although not a problem for an untraced system, if static agent tracing was enabled, the logs from the hypervisor would be truncated, missing the crucial final stages of the agents shutdown sequence. The fix necessitated adding a new parameter to the `stopSandbox()` API, which if true requests the runtime hypervisor logic simply to wait for the hypervisor process to exit rather than killing it. Fixes: #1696. Signed-off-by: James O. D. Hunt <james.o.hunt@intel.com>
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
// Copyright (c) 2016 Intel Corporation
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package virtcontainers
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestMockHypervisorCreateSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
assert := assert.New(t)
|
|
|
|
sandbox := &Sandbox{
|
|
config: &SandboxConfig{
|
|
ID: "mock_sandbox",
|
|
HypervisorConfig: HypervisorConfig{
|
|
KernelPath: "",
|
|
ImagePath: "",
|
|
HypervisorPath: "",
|
|
},
|
|
},
|
|
}
|
|
|
|
ctx := context.Background()
|
|
|
|
// wrong config
|
|
err := m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
|
|
assert.Error(err)
|
|
|
|
sandbox.config.HypervisorConfig = HypervisorConfig{
|
|
KernelPath: fmt.Sprintf("%s/%s", testDir, testKernel),
|
|
ImagePath: fmt.Sprintf("%s/%s", testDir, testImage),
|
|
HypervisorPath: fmt.Sprintf("%s/%s", testDir, testHypervisor),
|
|
}
|
|
|
|
err = m.createSandbox(ctx, sandbox.config.ID, NetworkNamespace{}, &sandbox.config.HypervisorConfig)
|
|
assert.NoError(err)
|
|
}
|
|
|
|
func TestMockHypervisorStartSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
assert.NoError(t, m.startSandbox(context.Background(), vmStartTimeout))
|
|
}
|
|
|
|
func TestMockHypervisorStopSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
assert.NoError(t, m.stopSandbox(context.Background(), false))
|
|
}
|
|
|
|
func TestMockHypervisorAddDevice(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
assert.NoError(t, m.addDevice(context.Background(), nil, imgDev))
|
|
}
|
|
|
|
func TestMockHypervisorGetSandboxConsole(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
expected := ""
|
|
expectedProto := ""
|
|
proto, result, err := m.getSandboxConsole(context.Background(), "testSandboxID")
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, result, expected)
|
|
assert.Equal(t, proto, expectedProto)
|
|
}
|
|
|
|
func TestMockHypervisorSaveSandbox(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
assert.NoError(t, m.saveSandbox())
|
|
}
|
|
|
|
func TestMockHypervisorDisconnect(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
m.disconnect(context.Background())
|
|
}
|
|
|
|
func TestMockHypervisorCheck(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
assert.NoError(t, m.check())
|
|
}
|
|
|
|
func TestMockGenerateSocket(t *testing.T) {
|
|
var m *mockHypervisor
|
|
|
|
i, err := m.generateSocket("a")
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, i)
|
|
}
|