mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-26 15:32:30 +00:00
vc: Drop Sandbox#Pause and Sandbox#Resume
Fixes #2276 Signed-off-by: Ted Yu <yuzhihong@gmail.com>
This commit is contained in:
parent
d054556f60
commit
544730b4b1
@ -659,24 +659,6 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
|
|||||||
return s.KillContainer(containerID, signal, all)
|
return s.KillContainer(containerID, signal, all)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PauseSandbox is the virtcontainers pausing entry point which pauses an
|
|
||||||
// already running sandbox.
|
|
||||||
func PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
|
||||||
span, ctx := trace(ctx, "PauseSandbox")
|
|
||||||
defer span.Finish()
|
|
||||||
|
|
||||||
return togglePauseSandbox(ctx, sandboxID, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResumeSandbox is the virtcontainers resuming entry point which resumes
|
|
||||||
// (or unpauses) and already paused sandbox.
|
|
||||||
func ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
|
||||||
span, ctx := trace(ctx, "ResumeSandbox")
|
|
||||||
defer span.Finish()
|
|
||||||
|
|
||||||
return togglePauseSandbox(ctx, sandboxID, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProcessListContainer is the virtcontainers entry point to list
|
// ProcessListContainer is the virtcontainers entry point to list
|
||||||
// processes running inside a container
|
// processes running inside a container
|
||||||
func ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
func ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
|
||||||
|
@ -354,64 +354,6 @@ func TestStopSandboxNoopAgentSuccessful(t *testing.T) {
|
|||||||
assert.NotNil(vp)
|
assert.NotNil(vp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPauseThenResumeSandboxNoopAgentSuccessful(t *testing.T) {
|
|
||||||
defer cleanUp()
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
config := newTestSandboxConfigNoop()
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
|
|
||||||
p, _, err := createAndStartSandbox(ctx, config)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NotNil(p)
|
|
||||||
|
|
||||||
contID := "100"
|
|
||||||
contConfig := newTestContainerConfigNoop(contID)
|
|
||||||
|
|
||||||
_, c, err := CreateContainer(ctx, p.ID(), contConfig)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NotNil(c)
|
|
||||||
|
|
||||||
p, err = PauseSandbox(ctx, p.ID())
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NotNil(p)
|
|
||||||
|
|
||||||
pImpl, ok := p.(*Sandbox)
|
|
||||||
assert.True(ok)
|
|
||||||
|
|
||||||
expectedState := types.StatePaused
|
|
||||||
|
|
||||||
assert.Equal(pImpl.state.State, expectedState, "unexpected paused sandbox state")
|
|
||||||
|
|
||||||
for i, c := range p.GetAllContainers() {
|
|
||||||
cImpl, ok := c.(*Container)
|
|
||||||
assert.True(ok)
|
|
||||||
|
|
||||||
assert.Equal(expectedState, cImpl.state.State,
|
|
||||||
fmt.Sprintf("paused container %d has unexpected state", i))
|
|
||||||
}
|
|
||||||
|
|
||||||
p, err = ResumeSandbox(ctx, p.ID())
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.NotNil(p)
|
|
||||||
|
|
||||||
pImpl, ok = p.(*Sandbox)
|
|
||||||
assert.True(ok)
|
|
||||||
|
|
||||||
expectedState = types.StateRunning
|
|
||||||
|
|
||||||
assert.Equal(pImpl.state.State, expectedState, "unexpected resumed sandbox state")
|
|
||||||
|
|
||||||
for i, c := range p.GetAllContainers() {
|
|
||||||
cImpl, ok := c.(*Container)
|
|
||||||
assert.True(ok)
|
|
||||||
|
|
||||||
assert.Equal(cImpl.state.State, expectedState,
|
|
||||||
fmt.Sprintf("resumed container %d has unexpected state", i))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestStopSandboxKataAgentSuccessful(t *testing.T) {
|
func TestStopSandboxKataAgentSuccessful(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
if tc.NotValid(ktu.NeedRoot()) {
|
if tc.NotValid(ktu.NeedRoot()) {
|
||||||
|
@ -77,16 +77,6 @@ func (impl *VCImpl) StatusSandbox(ctx context.Context, sandboxID string) (Sandbo
|
|||||||
return StatusSandbox(ctx, sandboxID)
|
return StatusSandbox(ctx, sandboxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PauseSandbox implements the VC function of the same name.
|
|
||||||
func (impl *VCImpl) PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
|
||||||
return PauseSandbox(ctx, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResumeSandbox implements the VC function of the same name.
|
|
||||||
func (impl *VCImpl) ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
|
|
||||||
return ResumeSandbox(ctx, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateContainer implements the VC function of the same name.
|
// CreateContainer implements the VC function of the same name.
|
||||||
func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
|
||||||
return CreateContainer(ctx, sandboxID, containerConfig)
|
return CreateContainer(ctx, sandboxID, containerConfig)
|
||||||
|
@ -27,8 +27,6 @@ type VC interface {
|
|||||||
DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||||
FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||||
ListSandbox(ctx context.Context) ([]SandboxStatus, error)
|
ListSandbox(ctx context.Context) ([]SandboxStatus, error)
|
||||||
PauseSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
|
||||||
ResumeSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
|
||||||
RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
|
RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error)
|
||||||
StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
|
||||||
StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
|
StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
|
||||||
@ -72,8 +70,6 @@ type VCSandbox interface {
|
|||||||
|
|
||||||
Start() error
|
Start() error
|
||||||
Stop(force bool) error
|
Stop(force bool) error
|
||||||
Pause() error
|
|
||||||
Resume() error
|
|
||||||
Release() error
|
Release() error
|
||||||
Monitor() (chan error, error)
|
Monitor() (chan error, error)
|
||||||
Delete() error
|
Delete() error
|
||||||
|
@ -119,24 +119,6 @@ func (m *VCMock) StatusSandbox(ctx context.Context, sandboxID string) (vc.Sandbo
|
|||||||
return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
return vc.SandboxStatus{}, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PauseSandbox implements the VC function of the same name.
|
|
||||||
func (m *VCMock) PauseSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
|
||||||
if m.PauseSandboxFunc != nil {
|
|
||||||
return m.PauseSandboxFunc(ctx, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ResumeSandbox implements the VC function of the same name.
|
|
||||||
func (m *VCMock) ResumeSandbox(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
|
||||||
if m.ResumeSandboxFunc != nil {
|
|
||||||
return m.ResumeSandboxFunc(ctx, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, fmt.Errorf("%s: %s (%+v): sandboxID: %v", mockErrorPrefix, getSelf(), m, sandboxID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// CreateContainer implements the VC function of the same name.
|
// CreateContainer implements the VC function of the same name.
|
||||||
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
|
||||||
if m.CreateContainerFunc != nil {
|
if m.CreateContainerFunc != nil {
|
||||||
|
@ -197,60 +197,6 @@ func TestVCMockListSandbox(t *testing.T) {
|
|||||||
assert.True(IsMockError(err))
|
assert.True(IsMockError(err))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVCMockPauseSandbox(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
m := &VCMock{}
|
|
||||||
assert.Nil(m.PauseSandboxFunc)
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
_, err := m.PauseSandbox(ctx, testSandboxID)
|
|
||||||
assert.Error(err)
|
|
||||||
assert.True(IsMockError(err))
|
|
||||||
|
|
||||||
m.PauseSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
|
||||||
return &Sandbox{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sandbox, err := m.PauseSandbox(ctx, testSandboxID)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(sandbox, &Sandbox{})
|
|
||||||
|
|
||||||
// reset
|
|
||||||
m.PauseSandboxFunc = nil
|
|
||||||
|
|
||||||
_, err = m.PauseSandbox(ctx, testSandboxID)
|
|
||||||
assert.Error(err)
|
|
||||||
assert.True(IsMockError(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestVCMockResumeSandbox(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
m := &VCMock{}
|
|
||||||
assert.Nil(m.ResumeSandboxFunc)
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
_, err := m.ResumeSandbox(ctx, testSandboxID)
|
|
||||||
assert.Error(err)
|
|
||||||
assert.True(IsMockError(err))
|
|
||||||
|
|
||||||
m.ResumeSandboxFunc = func(ctx context.Context, sandboxID string) (vc.VCSandbox, error) {
|
|
||||||
return &Sandbox{}, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sandbox, err := m.ResumeSandbox(ctx, testSandboxID)
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(sandbox, &Sandbox{})
|
|
||||||
|
|
||||||
// reset
|
|
||||||
m.ResumeSandboxFunc = nil
|
|
||||||
|
|
||||||
_, err = m.ResumeSandbox(ctx, testSandboxID)
|
|
||||||
assert.Error(err)
|
|
||||||
assert.True(IsMockError(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestVCMockRunSandbox(t *testing.T) {
|
func TestVCMockRunSandbox(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
|
@ -48,8 +48,6 @@ type VCMock struct {
|
|||||||
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||||
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, error)
|
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, error)
|
||||||
FetchSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
FetchSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
||||||
PauseSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
|
||||||
ResumeSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
|
|
||||||
RunSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
RunSandboxFunc func(ctx context.Context, sandboxConfig vc.SandboxConfig) (vc.VCSandbox, error)
|
||||||
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)
|
||||||
|
@ -1599,48 +1599,6 @@ func (s *Sandbox) Stop(force bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pause pauses the sandbox
|
|
||||||
func (s *Sandbox) Pause() error {
|
|
||||||
if err := s.hypervisor.pauseSandbox(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
//After the sandbox is paused, it's needed to stop its monitor,
|
|
||||||
//Otherwise, its monitors will receive timeout errors if it is
|
|
||||||
//paused for a long time, thus its monitor will not tell it's a
|
|
||||||
//crash caused timeout or just a paused timeout.
|
|
||||||
if s.monitor != nil {
|
|
||||||
s.monitor.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.pauseSetStates(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.storeSandbox(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resume resumes the sandbox
|
|
||||||
func (s *Sandbox) Resume() error {
|
|
||||||
if err := s.hypervisor.resumeSandbox(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.resumeSetStates(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := s.storeSandbox(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// list lists all sandbox running on the host.
|
// list lists all sandbox running on the host.
|
||||||
func (s *Sandbox) list() ([]Sandbox, error) {
|
func (s *Sandbox) list() ([]Sandbox, error) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
@ -1668,26 +1626,6 @@ func (s *Sandbox) setSandboxState(state types.StateString) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sandbox) pauseSetStates() error {
|
|
||||||
// XXX: When a sandbox is paused, all its containers are forcibly
|
|
||||||
// paused too.
|
|
||||||
if err := s.setContainersState(types.StatePaused); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.setSandboxState(types.StatePaused)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Sandbox) resumeSetStates() error {
|
|
||||||
// XXX: Resuming a paused sandbox puts all containers back into the
|
|
||||||
// running state.
|
|
||||||
if err := s.setContainersState(types.StateRunning); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return s.setSandboxState(types.StateRunning)
|
|
||||||
}
|
|
||||||
|
|
||||||
// getAndSetSandboxBlockIndex retrieves sandbox block index and increments it for
|
// getAndSetSandboxBlockIndex retrieves sandbox block index and increments it for
|
||||||
// subsequent accesses. This index is used to maintain the index at which a
|
// subsequent accesses. This index is used to maintain the index at which a
|
||||||
// block device is assigned to a container in the sandbox.
|
// block device is assigned to a container in the sandbox.
|
||||||
@ -1737,55 +1675,6 @@ func (s *Sandbox) decrementSandboxBlockIndex() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Sandbox) setContainersState(state types.StateString) error {
|
|
||||||
if state == "" {
|
|
||||||
return vcTypes.ErrNeedState
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, c := range s.containers {
|
|
||||||
if err := c.setContainerState(state); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// togglePauseSandbox pauses a sandbox if pause is set to true, else it resumes it.
|
|
||||||
func togglePauseSandbox(ctx context.Context, sandboxID string, pause bool) (*Sandbox, error) {
|
|
||||||
span, ctx := trace(ctx, "togglePauseSandbox")
|
|
||||||
defer span.Finish()
|
|
||||||
|
|
||||||
if sandboxID == "" {
|
|
||||||
return nil, vcTypes.ErrNeedSandbox
|
|
||||||
}
|
|
||||||
|
|
||||||
lockFile, err := rwLockSandbox(ctx, sandboxID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer unlockSandbox(ctx, sandboxID, lockFile)
|
|
||||||
|
|
||||||
// Fetch the sandbox from storage and create it.
|
|
||||||
s, err := fetchSandbox(ctx, sandboxID)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
defer s.releaseStatelessSandbox()
|
|
||||||
|
|
||||||
if pause {
|
|
||||||
err = s.Pause()
|
|
||||||
} else {
|
|
||||||
err = s.Resume()
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return s, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// HotplugAddDevice is used for add a device to sandbox
|
// HotplugAddDevice is used for add a device to sandbox
|
||||||
// Sandbox implement DeviceReceiver interface from device/api/interface.go
|
// Sandbox implement DeviceReceiver interface from device/api/interface.go
|
||||||
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
|
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user