github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/mock_hypervisor.go (about)

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