@@ -1909,7 +1909,6 @@ func requireNonEmptyFifo(t testing.TB, path string) {
1909
1909
1910
1910
func TestCreateVM_Isolated (t * testing.T ) {
1911
1911
prepareIntegTest (t )
1912
-
1913
1912
client , err := containerd .New (containerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
1914
1913
require .NoError (t , err , "unable to create client to containerd service at %s, is containerd running?" , containerdSockPath )
1915
1914
defer client .Close ()
@@ -1921,17 +1920,38 @@ func TestCreateVM_Isolated(t *testing.T) {
1921
1920
1922
1921
fcClient := fccontrol .NewFirecrackerClient (pluginClient .Client ())
1923
1922
1924
- subtests := [] struct {
1923
+ type subtest struct {
1925
1924
name string
1926
1925
request proto.CreateVMRequest
1927
1926
validate func (* testing.T , error )
1928
- }{
1927
+ stopVM bool
1928
+ }
1929
+
1930
+ subtests := []subtest {
1929
1931
{
1930
1932
name : "Happy Case" ,
1931
1933
request : proto.CreateVMRequest {},
1932
1934
validate : func (t * testing.T , err error ) {
1933
1935
require .NoError (t , err )
1934
1936
},
1937
+ stopVM : true ,
1938
+ },
1939
+ {
1940
+ name : "Error Case" ,
1941
+ request : proto.CreateVMRequest {
1942
+ TimeoutSeconds : 5 ,
1943
+ RootDrive : & proto.FirecrackerRootDrive {
1944
+ HostPath : "/var/lib/firecracker-containerd/runtime/rootfs-no-agent.img" ,
1945
+ },
1946
+ },
1947
+ validate : func (t * testing.T , err error ) {
1948
+ require .NotNil (t , err , "expected an error but did not receive any" )
1949
+ time .Sleep (5 * time .Second )
1950
+ firecrackerProcesses , err := findProcess (ctx , findFirecracker )
1951
+ require .NoError (t , err , "failed waiting for expected firecracker process %q to come up" , firecrackerProcessName )
1952
+ require .Len (t , firecrackerProcesses , 0 , "expected only no firecracker processes to exist" )
1953
+ },
1954
+ stopVM : false ,
1935
1955
},
1936
1956
{
1937
1957
name : "Slow Root FS" ,
@@ -1945,6 +1965,7 @@ func TestCreateVM_Isolated(t *testing.T) {
1945
1965
assert .Equal (t , codes .DeadlineExceeded , status .Code (err ))
1946
1966
assert .Contains (t , err .Error (), "didn't start within 20s" )
1947
1967
},
1968
+ stopVM : true ,
1948
1969
},
1949
1970
{
1950
1971
name : "Slow Root FS and Longer Timeout" ,
@@ -1957,10 +1978,11 @@ func TestCreateVM_Isolated(t *testing.T) {
1957
1978
validate : func (t * testing.T , err error ) {
1958
1979
require .NoError (t , err )
1959
1980
},
1981
+ stopVM : true ,
1960
1982
},
1961
1983
}
1962
1984
1963
- runTest := func (t * testing.T , request proto.CreateVMRequest , validate func ( t * testing. T , err error ) ) {
1985
+ runTest := func (t * testing.T , request proto.CreateVMRequest , s subtest ) {
1964
1986
vmID := testNameToVMID (t .Name ())
1965
1987
1966
1988
tempDir , err := ioutil .TempDir ("" , vmID )
@@ -1981,34 +2003,31 @@ func TestCreateVM_Isolated(t *testing.T) {
1981
2003
requireNonEmptyFifo (t , metricsFile )
1982
2004
1983
2005
// Some test cases are expected to have an error, some are not.
1984
- validate (t , createVMErr )
1985
-
1986
- // No VM to stop.
1987
- if createVMErr != nil {
1988
- return
1989
- }
2006
+ s .validate (t , createVMErr )
1990
2007
1991
- // Ensure the response fields are populated correctly
1992
- assert .Equal (t , request .VMID , resp .VMID )
2008
+ if createVMErr == nil && s .stopVM {
2009
+ // Ensure the response fields are populated correctly
2010
+ assert .Equal (t , request .VMID , resp .VMID )
1993
2011
1994
- _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : request .VMID })
1995
- require .Equal (t , status .Code (err ), codes .OK )
2012
+ _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : request .VMID })
2013
+ require .Equal (t , status .Code (err ), codes .OK )
2014
+ }
1996
2015
}
1997
2016
1998
- for _ , subtest := range subtests {
1999
- request := subtest . request
2000
- validate := subtest . validate
2001
- t .Run (subtest .name , func (t * testing.T ) {
2002
- runTest (t , request , validate )
2017
+ for _ , _s := range subtests {
2018
+ s := _s
2019
+ request := s . request
2020
+ t .Run (s .name , func (t * testing.T ) {
2021
+ runTest (t , request , s )
2003
2022
})
2004
2023
2005
- requestWithJailer := subtest .request
2024
+ requestWithJailer := s .request
2006
2025
requestWithJailer .JailerConfig = & proto.JailerConfig {
2007
2026
UID : 30000 ,
2008
2027
GID : 30000 ,
2009
2028
}
2010
- t .Run (subtest .name + "/Jailer" , func (t * testing.T ) {
2011
- runTest (t , requestWithJailer , validate )
2029
+ t .Run (s .name + "/Jailer" , func (t * testing.T ) {
2030
+ runTest (t , requestWithJailer , s )
2012
2031
})
2013
2032
}
2014
2033
}
0 commit comments