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 #193 from devimc/virtcontainers/fixUnitTests
Browse files Browse the repository at this point in the history
virtcontainers: fix unit tests
  • Loading branch information
Sebastien Boeuf authored Apr 9, 2018
2 parents bc83bf0 + dacc175 commit 5932803
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
2 changes: 1 addition & 1 deletion virtcontainers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
28 changes: 17 additions & 11 deletions virtcontainers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
12 changes: 10 additions & 2 deletions virtcontainers/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -258,7 +264,6 @@ func TestContainerAddDriveDir(t *testing.T) {
if container.state.Fstype == "" || !container.state.HotpluggedDrive {
t.Fatal()
}

}

func TestCheckPodRunningEmptyCmdFailure(t *testing.T) {
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/pkg/vcmock/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 5932803

Please sign in to comment.