mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-16 16:32:03 +00:00
sandbox/virtcontainers: modify tests relate to memory hotplug.
Signed-off-by: Clare Chen <clare.chenhui@huawei.com> Signed-off-by: Zichang Lin <linzichang@huawei.com>
This commit is contained in:
parent
14f480af8f
commit
36306e283c
@ -75,7 +75,7 @@ default_bridges = @DEFBRIDGES@
|
||||
|
||||
# Default memory size in MiB for SB/VM.
|
||||
# If unspecified then it will be set @DEFMEMSZ@ MiB.
|
||||
#default_memory = @DEFMEMSZ@
|
||||
default_memory = @DEFMEMSZ@
|
||||
#
|
||||
# Default memory slots per SB/VM.
|
||||
# If unspecified then it will be set @DEFMEMSLOTS@.
|
||||
|
@ -896,7 +896,6 @@ func TestCreateSandboxConfigFail(t *testing.T) {
|
||||
|
||||
_, err = createSandbox(context.Background(), spec, runtimeConfig, testContainerID, bundlePath, testConsole, true, true)
|
||||
assert.Error(err)
|
||||
assert.False(vcmock.IsMockError(err))
|
||||
}
|
||||
|
||||
func TestCreateCreateSandboxFail(t *testing.T) {
|
||||
|
@ -993,6 +993,10 @@ func (c *Container) update(resources specs.LinuxResources) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.storeContainer(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return c.sandbox.agent.updateContainer(c.sandbox, *c, resources)
|
||||
}
|
||||
|
||||
@ -1353,11 +1357,8 @@ func (c *Container) updateResources(oldResources, newResources ContainerResource
|
||||
if err := c.updateVCPUResources(oldResources, &newResources); err != nil {
|
||||
return err
|
||||
}
|
||||
// Set and save container's config VCPUs field only
|
||||
// Set container's config VCPUs field only
|
||||
c.config.Resources.VCPUs = newResources.VCPUs
|
||||
if err := c.storeContainer(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Memory is not updated if memory limit not set
|
||||
@ -1366,9 +1367,8 @@ func (c *Container) updateResources(oldResources, newResources ContainerResource
|
||||
return err
|
||||
}
|
||||
|
||||
// Set and save container's config Mem field only
|
||||
// Set container's config MemByte field only
|
||||
c.config.Resources.MemByte = newResources.MemByte
|
||||
return c.storeContainer()
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -326,11 +326,9 @@ func TestContainerAddResources(t *testing.T) {
|
||||
MemByte: memByte,
|
||||
}
|
||||
c.sandbox = &Sandbox{
|
||||
hypervisor: &mockHypervisor{
|
||||
vCPUs: vCPUs,
|
||||
},
|
||||
agent: &noopAgent{},
|
||||
storage: &filesystem{},
|
||||
hypervisor: &mockHypervisor{},
|
||||
agent: &noopAgent{},
|
||||
storage: &filesystem{},
|
||||
}
|
||||
err = c.addResources()
|
||||
assert.Nil(err)
|
||||
@ -363,16 +361,94 @@ func TestContainerRemoveResources(t *testing.T) {
|
||||
}
|
||||
|
||||
c.sandbox = &Sandbox{
|
||||
hypervisor: &mockHypervisor{
|
||||
vCPUs: vCPUs,
|
||||
},
|
||||
storage: &filesystem{},
|
||||
hypervisor: &mockHypervisor{},
|
||||
storage: &filesystem{},
|
||||
}
|
||||
|
||||
err = c.removeResources()
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
func TestContainerUpdateResources(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
sandbox := &Sandbox{
|
||||
hypervisor: &mockHypervisor{},
|
||||
agent: &noopAgent{},
|
||||
storage: &filesystem{},
|
||||
}
|
||||
|
||||
c := &Container{
|
||||
sandbox: sandbox,
|
||||
}
|
||||
c.config = &ContainerConfig{Annotations: make(map[string]string)}
|
||||
|
||||
// VCPUs is equal to zero
|
||||
oldResource := ContainerResources{
|
||||
VCPUs: 0,
|
||||
MemByte: 0,
|
||||
}
|
||||
|
||||
newResource := ContainerResources{
|
||||
VCPUs: 0,
|
||||
MemByte: 104857600,
|
||||
}
|
||||
|
||||
err := c.updateResources(oldResource, newResource)
|
||||
assert.Nil(err)
|
||||
|
||||
// MemByte is equal to zero
|
||||
newResource = ContainerResources{
|
||||
VCPUs: 5,
|
||||
MemByte: 0,
|
||||
}
|
||||
|
||||
err = c.updateResources(oldResource, newResource)
|
||||
assert.Nil(err)
|
||||
|
||||
// oldResource is equal to newResource
|
||||
oldResource = ContainerResources{
|
||||
VCPUs: 5,
|
||||
MemByte: 104857600,
|
||||
}
|
||||
|
||||
newResource = ContainerResources{
|
||||
VCPUs: 5,
|
||||
MemByte: 104857600,
|
||||
}
|
||||
|
||||
err = c.updateResources(oldResource, newResource)
|
||||
assert.Nil(err)
|
||||
|
||||
// memory hotplug and cpu hotplug
|
||||
oldResource = ContainerResources{
|
||||
VCPUs: 5,
|
||||
MemByte: 104857600,
|
||||
}
|
||||
|
||||
newResource = ContainerResources{
|
||||
VCPUs: 10,
|
||||
MemByte: 209715200,
|
||||
}
|
||||
|
||||
err = c.updateResources(oldResource, newResource)
|
||||
assert.Nil(err)
|
||||
|
||||
// memory hot remove and cpu hot remove
|
||||
oldResource = ContainerResources{
|
||||
VCPUs: 10,
|
||||
MemByte: 209715200,
|
||||
}
|
||||
|
||||
newResource = ContainerResources{
|
||||
VCPUs: 5,
|
||||
MemByte: 104857600,
|
||||
}
|
||||
|
||||
err = c.updateResources(oldResource, newResource)
|
||||
assert.Nil(err)
|
||||
}
|
||||
|
||||
func TestContainerEnterErrorsOnContainerStates(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
c := &Container{
|
||||
|
@ -8,7 +8,6 @@ package virtcontainers
|
||||
import "context"
|
||||
|
||||
type mockHypervisor struct {
|
||||
vCPUs uint32
|
||||
}
|
||||
|
||||
func (m *mockHypervisor) init(ctx context.Context, id string, hypervisorConfig *HypervisorConfig, storage resourceStorage) error {
|
||||
@ -63,7 +62,7 @@ func (m *mockHypervisor) addDevice(devInfo interface{}, devType deviceType) erro
|
||||
func (m *mockHypervisor) hotplugAddDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
|
||||
switch devType {
|
||||
case cpuDev:
|
||||
return m.vCPUs, nil
|
||||
return devInfo.(uint32), nil
|
||||
case memoryDev:
|
||||
memdev := devInfo.(*memoryDevice)
|
||||
return memdev.sizeMB, nil
|
||||
@ -74,7 +73,9 @@ func (m *mockHypervisor) hotplugAddDevice(devInfo interface{}, devType deviceTyp
|
||||
func (m *mockHypervisor) hotplugRemoveDevice(devInfo interface{}, devType deviceType) (interface{}, error) {
|
||||
switch devType {
|
||||
case cpuDev:
|
||||
return m.vCPUs, nil
|
||||
return devInfo.(uint32), nil
|
||||
case memoryDev:
|
||||
return 0, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user