mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-23 09:14:27 +01:00
virtcontainers/utils: Implement function to check vsocks support
Implement function to check if the system has support for vsocks. This function looks for vsock and vhost-vsock devices returning true if those exist, otherwise false. Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com> Signed-off-by: Julio Montes <julio.montes@intel.com>
This commit is contained in:
@@ -294,3 +294,34 @@ func TestBuildSocketPath(t *testing.T) {
|
||||
assert.Equal(d.expected, result)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSupportsVsocks(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
orgVSockDevicePath := VSockDevicePath
|
||||
orgVHostVSockDevicePath := VHostVSockDevicePath
|
||||
defer func() {
|
||||
VSockDevicePath = orgVSockDevicePath
|
||||
VHostVSockDevicePath = orgVHostVSockDevicePath
|
||||
}()
|
||||
|
||||
VSockDevicePath = "/abc/xyz/123"
|
||||
VHostVSockDevicePath = "/abc/xyz/123"
|
||||
assert.False(SupportsVsocks())
|
||||
|
||||
vSockDeviceFile, err := ioutil.TempFile("", "vsock")
|
||||
assert.NoError(err)
|
||||
defer os.Remove(vSockDeviceFile.Name())
|
||||
defer vSockDeviceFile.Close()
|
||||
VSockDevicePath = vSockDeviceFile.Name()
|
||||
|
||||
assert.False(SupportsVsocks())
|
||||
|
||||
vHostVSockFile, err := ioutil.TempFile("", "vhost-vsock")
|
||||
assert.NoError(err)
|
||||
defer os.Remove(vHostVSockFile.Name())
|
||||
defer vHostVSockFile.Close()
|
||||
VHostVSockDevicePath = vHostVSockFile.Name()
|
||||
|
||||
assert.True(SupportsVsocks())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user