diff --git a/virtcontainers/persist/api/sandbox.go b/virtcontainers/persist/api/sandbox.go index cd2249c1f7..71403eac06 100644 --- a/virtcontainers/persist/api/sandbox.go +++ b/virtcontainers/persist/api/sandbox.go @@ -57,6 +57,7 @@ type ProxyState struct { } // SandboxState contains state information of sandbox +// nolint: maligned type SandboxState struct { // PersistVersion of persist data format, can be used for keeping compatibility later PersistVersion uint @@ -64,20 +65,20 @@ type SandboxState struct { // State is sandbox running status State string - // SandboxContainer specifies which container is used to start the sandbox/vm - SandboxContainer string + // GuestMemoryBlockSizeMB is the size of memory block of guestos + GuestMemoryBlockSizeMB uint32 // GuestMemoryHotplugProbe determines whether guest kernel supports memory hotplug probe interface GuestMemoryHotplugProbe bool + // SandboxContainer specifies which container is used to start the sandbox/vm + SandboxContainer string + // CgroupPath is the cgroup hierarchy where sandbox's processes // including the hypervisor are placed. // FIXME: sandbox can reuse "SandboxContainer"'s CgroupPath so we can remove this field. CgroupPath string - // GuestMemoryBlockSizeMB is the size of memory block of guestos - GuestMemoryBlockSizeMB uint32 - // Devices plugged to sandbox(hypervisor) Devices []DeviceState diff --git a/virtcontainers/persist_test.go b/virtcontainers/persist_test.go index 96354f5272..425b33d6c6 100644 --- a/virtcontainers/persist_test.go +++ b/virtcontainers/persist_test.go @@ -97,7 +97,6 @@ func TestSandboxRestore(t *testing.T) { assert.Equal(t, sandbox.state.State, types.StateString("")) assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(0)) assert.Equal(t, sandbox.state.BlockIndex, 0) - assert.Equal(t, sandbox.state.Pid, 0) // register callback function sandbox.stateSaveCallback() @@ -105,20 +104,18 @@ func TestSandboxRestore(t *testing.T) { sandbox.state.State = types.StateString("running") sandbox.state.GuestMemoryBlockSizeMB = uint32(1024) sandbox.state.BlockIndex = 2 - sandbox.state.Pid = 10000 // flush data to disk err = sandbox.newStore.ToDisk() assert.Nil(t, err) // empty the sandbox - sandbox.state = types.State{} + sandbox.state = types.SandboxState{} // restore data from disk err = sandbox.Restore() assert.Nil(t, err) assert.Equal(t, sandbox.state.State, types.StateString("running")) assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024)) - assert.Equal(t, sandbox.state.Pid, 10000) // require hvStateSaveCallback to make it savable assert.Equal(t, sandbox.state.BlockIndex, 0) @@ -131,7 +128,6 @@ func TestSandboxRestore(t *testing.T) { assert.Nil(t, err) assert.Equal(t, sandbox.state.State, types.StateString("running")) assert.Equal(t, sandbox.state.GuestMemoryBlockSizeMB, uint32(1024)) - assert.Equal(t, sandbox.state.Pid, 10000) assert.Equal(t, sandbox.state.BlockIndex, 2) } diff --git a/virtcontainers/sandbox_test.go b/virtcontainers/sandbox_test.go index 70ed5906b9..2188972d10 100644 --- a/virtcontainers/sandbox_test.go +++ b/virtcontainers/sandbox_test.go @@ -762,15 +762,11 @@ func TestContainerStateSetFstype(t *testing.T) { hConfig := newHypervisorConfig(nil, nil) sandbox, err := testCreateSandbox(t, testSandboxID, MockHypervisor, hConfig, NoopAgentType, NetworkConfig{}, containers, nil) - if err != nil { - t.Fatal(err) - } + assert.Nil(t, err) defer cleanUp() vcStore, err := store.NewVCSandboxStore(sandbox.ctx, sandbox.id) - if err != nil { - t.Fatal(err) - } + assert.Nil(t, err) sandbox.store = vcStore c := sandbox.GetContainer("100") @@ -827,6 +823,11 @@ func TestContainerStateSetFstype(t *testing.T) { t.Fatal() } + // experimental features doesn't write state.json + if sandbox.supportNewStore() { + return + } + var res types.ContainerState err = json.Unmarshal([]byte(string(fileData)), &res) if err != nil {