From cde11c36dbe711f64e5b934a7f8cada7510b8cc8 Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Thu, 5 Apr 2018 13:06:32 -0500 Subject: [PATCH 1/3] virtcontainers: fix unit tests Use noopAgent in unit tests to add online fake resources. Fix unit tests according with new changes introduced recently. fixes #192 Signed-off-by: Julio Montes --- virtcontainers/api_test.go | 2 +- virtcontainers/container_test.go | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/virtcontainers/api_test.go b/virtcontainers/api_test.go index ce4d01fff2..8db38a8e41 100644 --- a/virtcontainers/api_test.go +++ b/virtcontainers/api_test.go @@ -1726,7 +1726,7 @@ func TestEnterContainerFailingContNotStarted(t *testing.T) { cmd := newBasicTestCmd() _, c, _, err = EnterContainer(p.ID(), contID, cmd) - if c != nil || err == nil { + if c == nil || err != nil { t.Fatal() } } diff --git a/virtcontainers/container_test.go b/virtcontainers/container_test.go index 6ad6d9961a..4897e34a38 100644 --- a/virtcontainers/container_test.go +++ b/virtcontainers/container_test.go @@ -210,6 +210,12 @@ func TestContainerAddDriveDir(t *testing.T) { id: testPodID, storage: fs, hypervisor: &mockHypervisor{}, + agent: &noopAgent{}, + config: &PodConfig{ + HypervisorConfig: HypervisorConfig{ + DisableBlockDeviceUse: false, + }, + }, } contID := "100" @@ -258,7 +264,6 @@ func TestContainerAddDriveDir(t *testing.T) { if container.state.Fstype == "" || !container.state.HotpluggedDrive { t.Fatal() } - } func TestCheckPodRunningEmptyCmdFailure(t *testing.T) { @@ -307,7 +312,10 @@ func TestContainerAddResources(t *testing.T) { CPUQuota: 5000, CPUPeriod: 1000, } - c.pod = &Pod{hypervisor: &mockHypervisor{}} + c.pod = &Pod{ + hypervisor: &mockHypervisor{}, + agent: &noopAgent{}, + } err = c.addResources() assert.Nil(err) } From 50fd76eb9a6739058826fbe7ca3bf29062824906 Mon Sep 17 00:00:00 2001 From: Archana Shinde Date: Thu, 5 Apr 2018 12:03:14 -0700 Subject: [PATCH 2/3] virtcontainers: block: Factorize checks for evaluating block support Factorize configuration and hardware support for hotplugging block devices into a single function and use that. Signed-off-by: Archana Shinde --- virtcontainers/container.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/virtcontainers/container.go b/virtcontainers/container.go index 16a95d2e05..bc2eda71f7 100644 --- a/virtcontainers/container.go +++ b/virtcontainers/container.go @@ -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 // 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) { @@ -456,8 +469,10 @@ func createContainer(pod *Pod, contConfig ContainerConfig) (c *Container, err er } }() - if err = c.hotplugDrive(); err != nil { - return + if c.checkBlockDeviceSupport() { + if err = c.hotplugDrive(); err != nil { + return + } } // Attach devices @@ -683,15 +698,6 @@ func (c *Container) processList(options ProcessListOptions) (ProcessList, 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) if err == errMountPointNotFound { From dacc1755365530eaf565b5336a824dac0c4552fe Mon Sep 17 00:00:00 2001 From: Julio Montes Date: Mon, 9 Apr 2018 12:12:42 -0500 Subject: [PATCH 3/3] virtcontainers: mockcontainer: return a valid process in order to make log-parser happy, mockcontainer must return always a valid process with a fake PID, since log-parser checks that PID value in the logs and it must be different to zero Depends-on: github.com/kata-containers/tests#226 Signed-off-by: Julio Montes --- virtcontainers/pkg/vcmock/container.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/virtcontainers/pkg/vcmock/container.go b/virtcontainers/pkg/vcmock/container.go index 7bee5567a8..07432c8c1b 100644 --- a/virtcontainers/pkg/vcmock/container.go +++ b/virtcontainers/pkg/vcmock/container.go @@ -30,6 +30,10 @@ func (c *Container) Pod() vc.VCPod { // Process implements the VCContainer function of the same name. 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 }