mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-28 12:31:04 +00:00
Merge pull request #193 from devimc/virtcontainers/fixUnitTests
virtcontainers: fix unit tests
This commit is contained in:
commit
5932803088
@ -1726,7 +1726,7 @@ func TestEnterContainerFailingContNotStarted(t *testing.T) {
|
|||||||
cmd := newBasicTestCmd()
|
cmd := newBasicTestCmd()
|
||||||
|
|
||||||
_, c, _, err = EnterContainer(p.ID(), contID, cmd)
|
_, c, _, err = EnterContainer(p.ID(), contID, cmd)
|
||||||
if c != nil || err == nil {
|
if c == nil || err != nil {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -432,6 +432,19 @@ func (c *Container) rollbackFailingContainerCreation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Container) checkBlockDeviceSupport() bool {
|
||||||
|
if !c.pod.config.HypervisorConfig.DisableBlockDeviceUse {
|
||||||
|
agentCaps := c.pod.agent.capabilities()
|
||||||
|
hypervisorCaps := c.pod.hypervisor.capabilities()
|
||||||
|
|
||||||
|
if agentCaps.isBlockDeviceSupported() && hypervisorCaps.isBlockDeviceHotplugSupported() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// createContainer creates and start a container inside a Pod. It has to be
|
// createContainer creates and start a container inside a Pod. It has to be
|
||||||
// called only when a new container, not known by the pod, has to be created.
|
// called only when a new container, not known by the pod, has to be created.
|
||||||
func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err error) {
|
func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err error) {
|
||||||
@ -456,8 +469,10 @@ func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err er
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if err = c.hotplugDrive(); err != nil {
|
if c.checkBlockDeviceSupport() {
|
||||||
return
|
if err = c.hotplugDrive(); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attach devices
|
// Attach devices
|
||||||
@ -683,15 +698,6 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Container) hotplugDrive() error {
|
func (c *Container) hotplugDrive() error {
|
||||||
agentCaps := c.pod.agent.capabilities()
|
|
||||||
hypervisorCaps := c.pod.hypervisor.capabilities()
|
|
||||||
|
|
||||||
if c.pod.config.HypervisorConfig.DisableBlockDeviceUse ||
|
|
||||||
!agentCaps.isBlockDeviceSupported() ||
|
|
||||||
!hypervisorCaps.isBlockDeviceHotplugSupported() {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
dev, err := getDeviceForPath(c.rootFs)
|
dev, err := getDeviceForPath(c.rootFs)
|
||||||
|
|
||||||
if err == errMountPointNotFound {
|
if err == errMountPointNotFound {
|
||||||
|
@ -210,6 +210,12 @@ func TestContainerAddDriveDir(t *testing.T) {
|
|||||||
id: testPodID,
|
id: testPodID,
|
||||||
storage: fs,
|
storage: fs,
|
||||||
hypervisor: &mockHypervisor{},
|
hypervisor: &mockHypervisor{},
|
||||||
|
agent: &noopAgent{},
|
||||||
|
config: &PodConfig{
|
||||||
|
HypervisorConfig: HypervisorConfig{
|
||||||
|
DisableBlockDeviceUse: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
contID := "100"
|
contID := "100"
|
||||||
@ -258,7 +264,6 @@ func TestContainerAddDriveDir(t *testing.T) {
|
|||||||
if container.state.Fstype == "" || !container.state.HotpluggedDrive {
|
if container.state.Fstype == "" || !container.state.HotpluggedDrive {
|
||||||
t.Fatal()
|
t.Fatal()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCheckPodRunningEmptyCmdFailure(t *testing.T) {
|
func TestCheckPodRunningEmptyCmdFailure(t *testing.T) {
|
||||||
@ -307,7 +312,10 @@ func TestContainerAddResources(t *testing.T) {
|
|||||||
CPUQuota: 5000,
|
CPUQuota: 5000,
|
||||||
CPUPeriod: 1000,
|
CPUPeriod: 1000,
|
||||||
}
|
}
|
||||||
c.pod = &Pod{hypervisor: &mockHypervisor{}}
|
c.pod = &Pod{
|
||||||
|
hypervisor: &mockHypervisor{},
|
||||||
|
agent: &noopAgent{},
|
||||||
|
}
|
||||||
err = c.addResources()
|
err = c.addResources()
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,10 @@ func (c *Container) Pod() vc.VCPod {
|
|||||||
|
|
||||||
// Process implements the VCContainer function of the same name.
|
// Process implements the VCContainer function of the same name.
|
||||||
func (c *Container) Process() vc.Process {
|
func (c *Container) Process() vc.Process {
|
||||||
|
// always return a mockprocess with a non-zero Pid
|
||||||
|
if c.MockProcess.Pid == 0 {
|
||||||
|
c.MockProcess.Pid = 1000
|
||||||
|
}
|
||||||
return c.MockProcess
|
return c.MockProcess
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user