Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
Merge pull request #2283 from tedyu/rm-pause-resume
Browse files Browse the repository at this point in the history
vc: Drop Sandbox#Pause and Sandbox#Resume
  • Loading branch information
bergwolf authored Dec 2, 2019
2 parents 450a646 + 544730b commit 0a5315b
Show file tree
Hide file tree
Showing 8 changed files with 0 additions and 275 deletions.
18 changes: 0 additions & 18 deletions virtcontainers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,24 +659,6 @@ func KillContainer(ctx context.Context, sandboxID, containerID string, signal sy
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
// processes running inside a container
func ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
Expand Down
58 changes: 0 additions & 58 deletions virtcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,64 +354,6 @@ func TestStopSandboxNoopAgentSuccessful(t *testing.T) {
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) {
assert := assert.New(t)
if tc.NotValid(ktu.NeedRoot()) {
Expand Down
10 changes: 0 additions & 10 deletions virtcontainers/implementation.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,6 @@ func (impl *VCImpl) StatusSandbox(ctx context.Context, sandboxID string) (Sandbo
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.
func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
return CreateContainer(ctx, sandboxID, containerConfig)
Expand Down
4 changes: 0 additions & 4 deletions virtcontainers/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ type VC interface {
DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, 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)
StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error)
StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error)
Expand Down Expand Up @@ -72,8 +70,6 @@ type VCSandbox interface {

Start() error
Stop(force bool) error
Pause() error
Resume() error
Release() error
Monitor() (chan error, error)
Delete() error
Expand Down
18 changes: 0 additions & 18 deletions virtcontainers/pkg/vcmock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

// 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.
func (m *VCMock) CreateContainer(ctx context.Context, sandboxID string, containerConfig vc.ContainerConfig) (vc.VCSandbox, vc.VCContainer, error) {
if m.CreateContainerFunc != nil {
Expand Down
54 changes: 0 additions & 54 deletions virtcontainers/pkg/vcmock/mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,60 +197,6 @@ func TestVCMockListSandbox(t *testing.T) {
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) {
assert := assert.New(t)

Expand Down
2 changes: 0 additions & 2 deletions virtcontainers/pkg/vcmock/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ type VCMock struct {
DeleteSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
ListSandboxFunc func(ctx context.Context) ([]vc.SandboxStatus, 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)
StartSandboxFunc func(ctx context.Context, sandboxID string) (vc.VCSandbox, error)
StatusSandboxFunc func(ctx context.Context, sandboxID string) (vc.SandboxStatus, error)
Expand Down
111 changes: 0 additions & 111 deletions virtcontainers/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -1597,48 +1597,6 @@ func (s *Sandbox) Stop(force bool) error {
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.
func (s *Sandbox) list() ([]Sandbox, error) {
return nil, nil
Expand Down Expand Up @@ -1666,26 +1624,6 @@ func (s *Sandbox) setSandboxState(state types.StateString) error {
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
// subsequent accesses. This index is used to maintain the index at which a
// block device is assigned to a container in the sandbox.
Expand Down Expand Up @@ -1735,55 +1673,6 @@ func (s *Sandbox) decrementSandboxBlockIndex() error {
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
// Sandbox implement DeviceReceiver interface from device/api/interface.go
func (s *Sandbox) HotplugAddDevice(device api.Device, devType config.DeviceType) error {
Expand Down

0 comments on commit 0a5315b

Please sign in to comment.