test integration: Adds a test that restarts a failed container
If a container failed to start due to a bad command, the container could not be recreated with a proper command in its stead. Adds a test that verifies this scenario. Signed-off-by: Claudiu Belu <cbelu@cloudbasesolutions.com>
This commit is contained in:
parent
e1f28659bc
commit
04ab4418fd
@ -55,3 +55,44 @@ func TestContainerRestart(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NoError(t, runtimeService.StartContainer(cn))
|
require.NoError(t, runtimeService.StartContainer(cn))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test to verify that, after a container fails to start due to a bad command, it can be removed
|
||||||
|
// and a proper container can be created and started in its stead.
|
||||||
|
func TestFailedContainerRestart(t *testing.T) {
|
||||||
|
t.Logf("Create a pod config and run sandbox container")
|
||||||
|
sb, sbConfig := PodSandboxConfigWithCleanup(t, "sandbox1", "restart")
|
||||||
|
|
||||||
|
EnsureImageExists(t, pauseImage)
|
||||||
|
|
||||||
|
t.Logf("Create a container config in a pod with a command that fails")
|
||||||
|
containerConfig := ContainerConfig(
|
||||||
|
"container1",
|
||||||
|
pauseImage,
|
||||||
|
WithCommand("something-that-doesnt-exist"),
|
||||||
|
WithTestLabels(),
|
||||||
|
WithTestAnnotations(),
|
||||||
|
)
|
||||||
|
cn, err := runtimeService.CreateContainer(sb, containerConfig, sbConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
defer func() {
|
||||||
|
assert.NoError(t, runtimeService.RemoveContainer(cn))
|
||||||
|
}()
|
||||||
|
require.Error(t, runtimeService.StartContainer(cn))
|
||||||
|
defer func() {
|
||||||
|
assert.NoError(t, runtimeService.StopContainer(cn, 10))
|
||||||
|
}()
|
||||||
|
|
||||||
|
t.Logf("Create the container with a proper command")
|
||||||
|
require.NoError(t, runtimeService.StopContainer(cn, 10))
|
||||||
|
require.NoError(t, runtimeService.RemoveContainer(cn))
|
||||||
|
|
||||||
|
containerConfig = ContainerConfig(
|
||||||
|
"container1",
|
||||||
|
pauseImage,
|
||||||
|
WithTestLabels(),
|
||||||
|
WithTestAnnotations(),
|
||||||
|
)
|
||||||
|
cn, err = runtimeService.CreateContainer(sb, containerConfig, sbConfig)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, runtimeService.StartContainer(cn))
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user