forked from kata-containers/runtime
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mock_hypervisor.go
130 lines (102 loc) · 2.93 KB
/
mock_hypervisor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) 2016 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//
package virtcontainers
import (
"context"
"errors"
"os"
persistapi "github.com/kata-containers/runtime/virtcontainers/persist/api"
"github.com/kata-containers/runtime/virtcontainers/types"
)
type mockHypervisor struct {
mockPid int
}
func (m *mockHypervisor) capabilities() types.Capabilities {
return types.Capabilities{}
}
func (m *mockHypervisor) hypervisorConfig() HypervisorConfig {
return HypervisorConfig{}
}
func (m *mockHypervisor) createSandbox(ctx context.Context, id string, networkNS NetworkNamespace, hypervisorConfig *HypervisorConfig, stateful bool) error {
err := hypervisorConfig.valid()
if err != nil {
return err
}
return nil
}
func (m *mockHypervisor) startSandbox(timeout int) error {
return nil
}
func (m *mockHypervisor) stopSandbox() error {
return nil
}
func (m *mockHypervisor) pauseSandbox() error {
return nil
}
func (m *mockHypervisor) resumeSandbox() error {
return nil
}
func (m *mockHypervisor) saveSandbox() error {
return nil
}
func (m *mockHypervisor) addDevice(devInfo interface{}, devType deviceType) error {
return nil
}
func (m *mockHypervisor) hotplugAddDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
switch devType {
case cpuDev:
return devInfo.(uint32), nil
case memoryDev:
memdev := devInfo.(*memoryDevice)
return memdev.sizeMB, nil
}
return nil, nil
}
func (m *mockHypervisor) hotplugRemoveDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
switch devType {
case cpuDev:
return devInfo.(uint32), nil
case memoryDev:
return 0, nil
}
return nil, nil
}
func (m *mockHypervisor) getSandboxConsole(sandboxID string) (string, error) {
return "", nil
}
func (m *mockHypervisor) resizeMemory(memMB uint32, memorySectionSizeMB uint32, probe bool) (uint32, memoryDevice, error) {
return 0, memoryDevice{}, nil
}
func (m *mockHypervisor) resizeVCPUs(cpus uint32) (uint32, uint32, error) {
return 0, 0, nil
}
func (m *mockHypervisor) disconnect() {
}
func (m *mockHypervisor) getThreadIDs() (vcpuThreadIDs, error) {
vcpus := map[int]int{0: os.Getpid()}
return vcpuThreadIDs{vcpus}, nil
}
func (m *mockHypervisor) cleanup() error {
return nil
}
func (m *mockHypervisor) getPids() []int {
return []int{m.mockPid}
}
func (m *mockHypervisor) fromGrpc(ctx context.Context, hypervisorConfig *HypervisorConfig, j []byte) error {
return errors.New("mockHypervisor is not supported by VM cache")
}
func (m *mockHypervisor) toGrpc() ([]byte, error) {
return nil, errors.New("mockHypervisor is not supported by VM cache")
}
func (m *mockHypervisor) save() (s persistapi.HypervisorState) {
return
}
func (m *mockHypervisor) load(s persistapi.HypervisorState) {}
func (m *mockHypervisor) check() error {
return nil
}
func (m *mockHypervisor) generateSocket(id string, useVsock bool) (interface{}, error) {
return types.Socket{HostPath: "/tmp/socket", Name: "socket"}, nil
}