mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-29 08:47:56 +00:00
container: allow to stop a paused container
When a container is paused and something goes terribly wrong, we still need to be able to clean thing up. A paused container should be able to transit to stopped state as well so that we can delete it properly. Signed-off-by: Peng Tao <bergwolf@hyper.sh>
This commit is contained in:
parent
f886c0bf35
commit
c472a01006
@ -200,7 +200,7 @@ func TestDeleteSandbox(t *testing.T) {
|
|||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(vcmock.IsMockError(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
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,7 +310,7 @@ func TestDeleteSandboxRunning(t *testing.T) {
|
|||||||
}, nil
|
}, 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
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -564,7 +564,7 @@ func TestDeleteCLIFunctionSuccess(t *testing.T) {
|
|||||||
}, nil
|
}, 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
|
return sandbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ var (
|
|||||||
return &vcmock.Container{}, nil
|
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
|
return &vcmock.Sandbox{}, nil
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -971,10 +971,6 @@ func (c *Container) stop() error {
|
|||||||
return nil
|
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 {
|
if err := c.state.ValidTransition(c.state.State, types.StateStopped); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -84,9 +84,9 @@ func (m *VCMock) StartSandbox(ctx context.Context, sandboxID string) (vc.VCSandb
|
|||||||
}
|
}
|
||||||
|
|
||||||
// StopSandbox implements the VC function of the same name.
|
// 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 {
|
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)
|
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||||
|
@ -339,22 +339,22 @@ func TestVCMockStopSandbox(t *testing.T) {
|
|||||||
assert.Nil(m.StopSandboxFunc)
|
assert.Nil(m.StopSandboxFunc)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
_, err := m.StopSandbox(ctx, testSandboxID)
|
_, err := m.StopSandbox(ctx, testSandboxID, false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(IsMockError(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
|
return &Sandbox{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox, err := m.StopSandbox(ctx, testSandboxID)
|
sandbox, err := m.StopSandbox(ctx, testSandboxID, false)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.Equal(sandbox, &Sandbox{})
|
assert.Equal(sandbox, &Sandbox{})
|
||||||
|
|
||||||
// reset
|
// reset
|
||||||
m.StopSandboxFunc = nil
|
m.StopSandboxFunc = nil
|
||||||
|
|
||||||
_, err = m.StopSandbox(ctx, testSandboxID)
|
_, err = m.StopSandbox(ctx, testSandboxID, false)
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
assert.True(IsMockError(err))
|
assert.True(IsMockError(err))
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ type VCMock struct {
|
|||||||
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||||
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)
|
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)
|
||||||
StatsContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.ContainerStats, 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)
|
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)
|
DeleteContainerFunc func(ctx context.Context, sandboxID, containerID string) (vc.VCContainer, error)
|
||||||
|
Loading…
Reference in New Issue
Block a user