mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-05 15:34:21 +01:00
As virtio v1.1 spec states: The guest_cid configuration field MUST be fetched to determine the current CID when a VIRTIO_VSOCK_EVENT_TRANSPORT_RESET event is received. Existing connections MUST be shut down when a VIRTIO_VSOCK_EVENT_TRANSPORT_RESET event is received. Listen connections MUST remain operational with the current CID when a VIRTIO_VSOCK_EVENT_TRANSPORT_RESET event is received. We should be able to use vm templating together with vsock easily, as qemu already sends VIRTIO_VSOCK_EVENT_TRANSPORT_RESET event to guest. Fixes: #1773 Signed-off-by: Peng Tao <bergwolf@hyper.sh>
117 lines
2.0 KiB
Go
117 lines
2.0 KiB
Go
// Copyright (c) 2018 HyperHQ Inc.
|
|
//
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
//
|
|
|
|
package template
|
|
|
|
import (
|
|
"context"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
vc "github.com/kata-containers/runtime/virtcontainers"
|
|
)
|
|
|
|
const testDisabledAsNonRoot = "Test disabled as requires root privileges"
|
|
|
|
func TestTemplateFactory(t *testing.T) {
|
|
if os.Geteuid() != 0 {
|
|
t.Skip(testDisabledAsNonRoot)
|
|
}
|
|
|
|
assert := assert.New(t)
|
|
|
|
templateWaitForAgent = 1 * time.Microsecond
|
|
|
|
testDir, _ := ioutil.TempDir("", "vmfactory-tmp-")
|
|
hyperConfig := vc.HypervisorConfig{
|
|
KernelPath: testDir,
|
|
ImagePath: testDir,
|
|
}
|
|
vmConfig := vc.VMConfig{
|
|
HypervisorType: vc.MockHypervisor,
|
|
HypervisorConfig: hyperConfig,
|
|
AgentType: vc.NoopAgentType,
|
|
ProxyType: vc.NoopProxyType,
|
|
}
|
|
|
|
err := vmConfig.Valid()
|
|
assert.Nil(err)
|
|
|
|
ctx := context.Background()
|
|
|
|
// New
|
|
f, err := New(ctx, vmConfig, testDir)
|
|
assert.Nil(err)
|
|
|
|
// Config
|
|
assert.Equal(f.Config(), vmConfig)
|
|
|
|
// GetBaseVM
|
|
vm, err := f.GetBaseVM(ctx, vmConfig)
|
|
assert.Nil(err)
|
|
|
|
err = vm.Stop()
|
|
assert.Nil(err)
|
|
|
|
// Fetch
|
|
tt := template{
|
|
statePath: testDir,
|
|
config: vmConfig,
|
|
}
|
|
|
|
assert.Equal(tt.Config(), vmConfig)
|
|
|
|
err = tt.checkTemplateVM()
|
|
assert.Error(err)
|
|
|
|
_, err = os.Create(tt.statePath + "/memory")
|
|
assert.Nil(err)
|
|
err = tt.checkTemplateVM()
|
|
assert.Error(err)
|
|
|
|
_, err = os.Create(tt.statePath + "/state")
|
|
assert.Nil(err)
|
|
err = tt.checkTemplateVM()
|
|
assert.Nil(err)
|
|
|
|
err = tt.createTemplateVM(ctx)
|
|
assert.Nil(err)
|
|
|
|
vm, err = tt.GetBaseVM(ctx, vmConfig)
|
|
assert.Nil(err)
|
|
|
|
err = vm.Stop()
|
|
assert.Nil(err)
|
|
|
|
vm, err = f.GetBaseVM(ctx, vmConfig)
|
|
assert.Nil(err)
|
|
|
|
err = vm.Stop()
|
|
assert.Nil(err)
|
|
|
|
err = tt.createTemplateVM(ctx)
|
|
assert.Nil(err)
|
|
|
|
vm, err = tt.GetBaseVM(ctx, vmConfig)
|
|
assert.Nil(err)
|
|
|
|
err = vm.Stop()
|
|
assert.Nil(err)
|
|
|
|
vm, err = f.GetBaseVM(ctx, vmConfig)
|
|
assert.Nil(err)
|
|
|
|
err = vm.Stop()
|
|
assert.Nil(err)
|
|
|
|
// CloseFactory
|
|
f.CloseFactory(ctx)
|
|
tt.CloseFactory(ctx)
|
|
}
|