Skip to content
This repository has been archived by the owner on Jun 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1237 from devimc/topic/pkgMgr-Stable-1.4
Browse files Browse the repository at this point in the history
stable-1.4: integration/docker: package managers
  • Loading branch information
Julio Montes authored Feb 25, 2019
2 parents ac6d5e9 + d54e02f commit 539670a
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 19 deletions.
40 changes: 27 additions & 13 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tests
import (
"bytes"
"flag"
"fmt"
"os/exec"
"syscall"
"time"
Expand Down Expand Up @@ -52,6 +53,8 @@ func (c *Command) Run() (string, string, int) {
func (c *Command) RunWithPipe(stdin *bytes.Buffer) (string, string, int) {
LogIfFail("Running command '%s %s'\n", c.cmd.Path, c.cmd.Args)

keepAliveTime := 1 * time.Minute

var stdout, stderr bytes.Buffer
c.cmd.Stdout = &stdout
c.cmd.Stderr = &stderr
Expand All @@ -72,22 +75,33 @@ func (c *Command) RunWithPipe(stdin *bytes.Buffer) (string, string, int) {
timeout = time.After(c.Timeout * time.Second)
}

select {
case <-timeout:
LogIfFail("Killing process timeout reached '%d' seconds\n", c.Timeout)
_ = c.cmd.Process.Kill()
return "", "", -1
keepAliveCh := time.NewTimer(keepAliveTime)

case err := <-done:
if err != nil {
LogIfFail("command failed error '%s'\n", err)
}
for {
select {
case <-timeout:
keepAliveCh.Stop()
LogIfFail("Killing process timeout reached '%d' seconds\n", c.Timeout)
_ = c.cmd.Process.Kill()
return "", "", -1

case <-keepAliveCh.C:
// Avoid CI (i.e jenkins) kills the process for inactivity by printing a dot
fmt.Println(".")
keepAliveCh.Reset(keepAliveTime)

exitCode := c.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()
case err := <-done:
keepAliveCh.Stop()
if err != nil {
LogIfFail("command failed error '%s'\n", err)
}

LogIfFail("%+v\nTimeout: %d seconds\nExit Code: %d\nStdout: %s\nStderr: %s\n",
c.cmd.Args, c.Timeout, exitCode, stdout.String(), stderr.String())
exitCode := c.cmd.ProcessState.Sys().(syscall.WaitStatus).ExitStatus()

return stdout.String(), stderr.String(), exitCode
LogIfFail("%+v\nTimeout: %d seconds\nExit Code: %d\nStdout: %s\nStderr: %s\n",
c.cmd.Args, c.Timeout, exitCode, stdout.String(), stderr.String())

return stdout.String(), stderr.String(), exitCode
}
}
}
40 changes: 34 additions & 6 deletions integration/docker/package_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ import (
. "github.com/onsi/gomega"
)

const (
packageManagerTimeout = 900
packageManagerMaxTries = 5
)

func tryPackageManagerCommand(container string, command []string, expectedExitCode int) int {
cmd := []string{container}
exitCode := int(-1)
for i := 0; i < packageManagerMaxTries; i++ {
_, _, exitCode = runDockerCommandWithTimeout(packageManagerTimeout, "exec", append(cmd, command...)...)
if exitCode == expectedExitCode {
break
}
}
return exitCode
}

var _ = Describe("package manager update test", func() {
var (
id string
Expand All @@ -34,17 +51,24 @@ var _ = Describe("package manager update test", func() {
Expect(ExistDockerContainer(id)).NotTo(BeTrue())
})

Context("check apt-get update", func() {
Context("check apt-get update and upgrade", func() {
It("should not fail", func() {
args = append(args, "--rm", "--name", id, DebianImage, "apt-get", "-y", "update")
args = append(args, "-td", "--name", id, DebianImage, "sh")
_, _, exitCode := dockerRun(args...)
Expect(exitCode).To(BeZero())

exitCode = tryPackageManagerCommand(id, []string{"apt-get", "-y", "update"}, 0)
Expect(exitCode).To(BeZero())

exitCode = tryPackageManagerCommand(id, []string{"apt-get", "-y", "upgrade"}, 0)
Expect(exitCode).To(BeZero())

Expect(RemoveDockerContainer(id)).To(BeTrue())
})
})

Context("check dnf update", func() {
It("should not fail", func() {
Skip("Issue: https://github.com/clearcontainers/runtime/issues/868")
args = append(args, "-td", "--name", id, FedoraImage, "sh")
_, _, exitCode := dockerRun(args...)
Expect(exitCode).To(BeZero())
Expand All @@ -54,7 +78,7 @@ var _ = Describe("package manager update test", func() {
Expect(exitCode).To(BeZero())
}

_, _, exitCode = dockerExec(id, "dnf", "-y", "update")
exitCode = tryPackageManagerCommand(id, []string{"dnf", "-y", "update"}, 0)
Expect(exitCode).To(BeZero())

Expect(RemoveDockerContainer(id)).To(BeTrue())
Expand All @@ -63,10 +87,14 @@ var _ = Describe("package manager update test", func() {

Context("check yum update", func() {
It("should not fail", func() {
Skip("Issue: https://github.com/kata-containers/tests/issues/264")
args = append(args, "--rm", "--name", id, CentosImage, "yum", "-y", "update")
args = append(args, "--rm", "-td", "--name", id, CentosImage, "sh")
_, _, exitCode := dockerRun(args...)
Expect(exitCode).To(BeZero())

exitCode = tryPackageManagerCommand(id, []string{"yum", "-y", "update"}, 0)
Expect(exitCode).To(BeZero())

Expect(RemoveDockerContainer(id)).To(BeTrue())
})
})
})

0 comments on commit 539670a

Please sign in to comment.