diff --git a/cli/delete_test.go b/cli/delete_test.go index 97768e1b4..77ded07f5 100644 --- a/cli/delete_test.go +++ b/cli/delete_test.go @@ -200,7 +200,7 @@ func TestDeleteSandbox(t *testing.T) { assert.Error(err) assert.True(vcmock.IsMockError(err)) - testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { + testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { return sandbox, nil } @@ -310,7 +310,7 @@ func TestDeleteSandboxRunning(t *testing.T) { }, nil } - testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { + testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { return sandbox, nil } @@ -564,7 +564,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) { }, nil } - testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { + testingImpl.StopSandboxFunc = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { return sandbox, nil } diff --git a/cli/kill_test.go b/cli/kill_test.go index cd8910cf9..a80bc2673 100644 --- a/cli/kill_test.go +++ b/cli/kill_test.go @@ -29,7 +29,7 @@ var ( return &vcmock.Container{}, nil } - testStopSandboxFuncReturnNil = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { + testStopSandboxFuncReturnNil = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { return &vcmock.Sandbox{}, nil } ) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index e41db846d..a8e7dc91c 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -971,10 +971,6 @@ func (c *Container) stop() error { return nil } - if c.sandbox.state.State != types.StateReady && c.sandbox.state.State != types.StateRunning { - return fmt.Errorf("Sandbox not ready or running, impossible to stop the container") - } - if err := c.state.ValidTransition(c.state.State, types.StateStopped); err != nil { return err } diff --git a/virtcontainers/pkg/vcmock/mock.go b/virtcontainers/pkg/vcmock/mock.go index b2455850f..4b60575b9 100644 --- a/virtcontainers/pkg/vcmock/mock.go +++ b/virtcontainers/pkg/vcmock/mock.go @@ -84,9 +84,9 @@ func (m *VCMock) StartSandbox(ctx context.Context, sandboxID string) (vc.VCSandb } // StopSandbox implements the VC function of the same name. -func (m *VCMock) StopSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { +func (m *VCMock) StopSandbox(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { if m.StopSandboxFunc != nil { - return m.StopSandboxFunc(ctx, sandboxID) + return m.StopSandboxFunc(ctx, sandboxID, force) } return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID) diff --git a/virtcontainers/pkg/vcmock/mock_test.go b/virtcontainers/pkg/vcmock/mock_test.go index d369e6574..dc94d740a 100644 --- a/virtcontainers/pkg/vcmock/mock_test.go +++ b/virtcontainers/pkg/vcmock/mock_test.go @@ -339,22 +339,22 @@ func TestVCMockStopSandbox(t *testing.T) { assert.Nil(m.StopSandboxFunc) ctx := context.Background() - _, err := m.StopSandbox(ctx, testSandboxID) + _, err := m.StopSandbox(ctx, testSandboxID, false) assert.Error(err) assert.True(IsMockError(err)) - m.StopSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) { + m.StopSandboxFunc = func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) { return &Sandbox{}, nil } - sandbox, err := m.StopSandbox(ctx, testSandboxID) + sandbox, err := m.StopSandbox(ctx, testSandboxID, false) assert.NoError(err) assert.Equal(sandbox, &Sandbox{}) // reset m.StopSandboxFunc = nil - _, err = m.StopSandbox(ctx, testSandboxID) + _, err = m.StopSandbox(ctx, testSandboxID, false) assert.Error(err) assert.True(IsMockError(err)) } diff --git a/virtcontainers/pkg/vcmock/types.go b/virtcontainers/pkg/vcmock/types.go index 6f7df5a3d..9a65389cd 100644 --- a/virtcontainers/pkg/vcmock/types.go +++ b/virtcontainers/pkg/vcmock/types.go @@ -54,7 +54,7 @@ type VCMock struct { StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error) StatsContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, error) - StopSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) + StopSandboxFunc func(ctx context.Context, sandboxID string, force bool) (vc.VCSandbox, error) CreateContainerFunc func(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) DeleteContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)