mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #29224 from vdemeester/check-no-errors
Use check in params so we don't ignore errors
This commit is contained in:
commit
7ea31b4034
12 changed files with 77 additions and 116 deletions
|
@ -44,12 +44,14 @@ func (s *DockerSuite) OnTimeout(c *check.C) {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) TearDownTest(c *check.C) {
|
||||
unpauseAllContainers()
|
||||
deleteAllContainers()
|
||||
deleteAllImages()
|
||||
deleteAllVolumes()
|
||||
deleteAllNetworks()
|
||||
deleteAllPlugins()
|
||||
unpauseAllContainers(c)
|
||||
deleteAllContainers(c)
|
||||
deleteAllImages(c)
|
||||
deleteAllVolumes(c)
|
||||
deleteAllNetworks(c)
|
||||
if daemonPlatform == "linux" {
|
||||
deleteAllPlugins(c)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -346,7 +346,7 @@ func (s *DockerSuite) TestGetStoppedContainerStats(c *check.C) {
|
|||
func (s *DockerSuite) TestContainerAPIPause(c *check.C) {
|
||||
// Problematic on Windows as Windows does not support pause
|
||||
testRequires(c, DaemonIsLinux)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
out, _ := dockerCmd(c, "run", "-d", "busybox", "sleep", "30")
|
||||
ContainerID := strings.TrimSpace(out)
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ func (s *DockerSuite) TestAttachDisconnect(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestAttachPausedContainer(c *check.C) {
|
||||
testRequires(c, IsPausable)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
runSleepingContainer(c, "-d", "--name=test")
|
||||
dockerCmd(c, "pause", "test")
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ func (s *DockerSuite) TestCommitWithoutPause(c *check.C) {
|
|||
//test commit a paused container should not unpause it after commit
|
||||
func (s *DockerSuite) TestCommitPausedContainer(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
out, _ := dockerCmd(c, "run", "-i", "-d", "busybox")
|
||||
|
||||
cleanedContainerID := strings.TrimSpace(out)
|
||||
|
|
|
@ -139,7 +139,7 @@ func (s *DockerSuite) TestExecExitStatus(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestExecPausedContainer(c *check.C) {
|
||||
testRequires(c, IsPausable)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
|
||||
out, _ := runSleepingContainer(c, "-d", "--name", "testing")
|
||||
ContainerID := strings.TrimSpace(out)
|
||||
|
@ -388,7 +388,7 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) {
|
|||
// Not applicable on Windows to Windows CI.
|
||||
testRequires(c, SameHostDaemon, DaemonIsLinux)
|
||||
for _, fn := range []string{"resolv.conf", "hosts"} {
|
||||
deleteAllContainers()
|
||||
deleteAllContainers(c)
|
||||
|
||||
content, err := runCommandAndReadContainerFile(fn, exec.Command(dockerBinary, "run", "-d", "--name", "c1", "busybox", "sh", "-c", fmt.Sprintf("echo success >/etc/%s && top", fn)))
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
|
|
@ -54,7 +54,7 @@ func (s *DockerSuite) TestInspectDefault(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestInspectStatus(c *check.C) {
|
||||
if daemonPlatform != "windows" {
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
}
|
||||
out, _ := runSleepingContainer(c, "-d")
|
||||
out = strings.TrimSpace(out)
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
func (s *DockerSuite) TestPause(c *check.C) {
|
||||
testRequires(c, IsPausable)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
|
||||
name := "testeventpause"
|
||||
runSleepingContainer(c, "-d", "--name", name)
|
||||
|
@ -31,7 +31,7 @@ func (s *DockerSuite) TestPause(c *check.C) {
|
|||
|
||||
func (s *DockerSuite) TestPauseMultipleContainers(c *check.C) {
|
||||
testRequires(c, IsPausable)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
|
||||
containers := []string{
|
||||
"testpausewithmorecontainers1",
|
||||
|
|
|
@ -275,4 +275,7 @@ func (s *DockerSuite) TestRestartAutoRemoveContainer(c *check.C) {
|
|||
|
||||
out, _ = dockerCmd(c, "ps")
|
||||
c.Assert(out, checker.Contains, id[:12], check.Commentf("container should be restarted instead of removed: %v", out))
|
||||
|
||||
// Kill the container to make sure it will be removed
|
||||
dockerCmd(c, "kill", id)
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ func (s *DockerSuite) TestRunLookupGoogleDNS(c *check.C) {
|
|||
// nslookup isn't present in nanoserver. Hence just use PowerShell...
|
||||
dockerCmd(c, "run", WindowsBaseImage, "powershell", "Resolve-DNSName", "google.com")
|
||||
} else {
|
||||
dockerCmd(c, "run", DefaultImage, "nslookup", "google.com")
|
||||
dockerCmd(c, "run", "busybox", "nslookup", "google.com")
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ func (s *DockerSuite) TestStartRecordError(c *check.C) {
|
|||
func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
|
||||
// Windows does not support pausing containers
|
||||
testRequires(c, IsPausable)
|
||||
defer unpauseAllContainers()
|
||||
defer unpauseAllContainers(c)
|
||||
|
||||
runSleepingContainer(c, "-d", "--name", "testing")
|
||||
|
||||
|
|
|
@ -22,16 +22,9 @@ var (
|
|||
// path to containerd's ctr binary
|
||||
ctrBinary = "docker-containerd-ctr"
|
||||
|
||||
// the private registry image to use for tests involving the registry
|
||||
registryImageName = "registry"
|
||||
|
||||
// the private registry to use for tests
|
||||
privateRegistryURL = "127.0.0.1:5000"
|
||||
|
||||
// TODO Windows CI. These are incorrect and need fixing into
|
||||
// platform specific pieces.
|
||||
runtimePath = "/var/run/docker"
|
||||
|
||||
workingDirectory string
|
||||
|
||||
// isLocalDaemon is true if the daemon under test is on the same
|
||||
|
@ -50,10 +43,6 @@ var (
|
|||
// not support volumes, but TP4 did.
|
||||
windowsDaemonKV int
|
||||
|
||||
// daemonDefaultImage is the name of the default image to use when running
|
||||
// tests. This is platform dependent.
|
||||
daemonDefaultImage string
|
||||
|
||||
// For a local daemon on Linux, these values will be used for testing
|
||||
// user namespace support as the standard graph path(s) will be
|
||||
// appended with the root remapped uid.gid prefix
|
||||
|
@ -81,12 +70,6 @@ var (
|
|||
daemonPid int
|
||||
)
|
||||
|
||||
const (
|
||||
// DefaultImage is the name of the base image for the majority of tests that
|
||||
// are run across suites
|
||||
DefaultImage = "busybox"
|
||||
)
|
||||
|
||||
func init() {
|
||||
reexec.Init()
|
||||
if dockerBin := os.Getenv("DOCKER_BINARY"); dockerBin != "" {
|
||||
|
@ -98,9 +81,6 @@ func init() {
|
|||
fmt.Printf("ERROR: couldn't resolve full path to the Docker binary (%v)\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if registryImage := os.Getenv("REGISTRY_IMAGE"); registryImage != "" {
|
||||
registryImageName = registryImage
|
||||
}
|
||||
if registry := os.Getenv("REGISTRY_URL"); registry != "" {
|
||||
privateRegistryURL = registry
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
volumetypes "github.com/docker/docker/api/types/volume"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/httputils"
|
||||
"github.com/docker/docker/pkg/integration/checker"
|
||||
icmd "github.com/docker/docker/pkg/integration/cmd"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/stringutils"
|
||||
|
@ -245,29 +246,20 @@ func getAllContainers() (string, error) {
|
|||
return out, err
|
||||
}
|
||||
|
||||
func deleteAllContainers() error {
|
||||
func deleteAllContainers(c *check.C) {
|
||||
containers, err := getAllContainers()
|
||||
if err != nil {
|
||||
fmt.Println(containers)
|
||||
return err
|
||||
}
|
||||
if containers == "" {
|
||||
return nil
|
||||
}
|
||||
c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers))
|
||||
|
||||
if containers != "" {
|
||||
err = deleteContainer(strings.Split(strings.TrimSpace(containers), "\n")...)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
c.Assert(err, checker.IsNil)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func deleteAllNetworks() error {
|
||||
func deleteAllNetworks(c *check.C) {
|
||||
networks, err := getAllNetworks()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var errors []string
|
||||
c.Assert(err, check.IsNil)
|
||||
var errs []string
|
||||
for _, n := range networks {
|
||||
if n.Name == "bridge" || n.Name == "none" || n.Name == "host" {
|
||||
continue
|
||||
|
@ -278,17 +270,14 @@ func deleteAllNetworks() error {
|
|||
}
|
||||
status, b, err := sockRequest("DELETE", "/networks/"+n.Name, nil)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
if status != http.StatusNoContent {
|
||||
errors = append(errors, fmt.Sprintf("error deleting network %s: %s", n.Name, string(b)))
|
||||
errs = append(errs, fmt.Sprintf("error deleting network %s: %s", n.Name, string(b)))
|
||||
}
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf(strings.Join(errors, "\n"))
|
||||
}
|
||||
return nil
|
||||
c.Assert(errs, checker.HasLen, 0, check.Commentf(strings.Join(errs, "\n")))
|
||||
}
|
||||
|
||||
func getAllNetworks() ([]types.NetworkResource, error) {
|
||||
|
@ -303,26 +292,26 @@ func getAllNetworks() ([]types.NetworkResource, error) {
|
|||
return networks, nil
|
||||
}
|
||||
|
||||
func deleteAllPlugins() error {
|
||||
func deleteAllPlugins(c *check.C) {
|
||||
plugins, err := getAllPlugins()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var errors []string
|
||||
c.Assert(err, checker.IsNil)
|
||||
var errs []string
|
||||
for _, p := range plugins {
|
||||
status, b, err := sockRequest("DELETE", "/plugins/"+p.Name+":"+p.Tag+"?force=1", nil)
|
||||
pluginName := p.Name
|
||||
tag := p.Tag
|
||||
if tag == "" {
|
||||
tag = "latest"
|
||||
}
|
||||
status, b, err := sockRequest("DELETE", "/plugins/"+pluginName+":"+tag+"?force=1", nil)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
if status != http.StatusNoContent {
|
||||
errors = append(errors, fmt.Sprintf("error deleting plugin %s: %s", p.Name, string(b)))
|
||||
if status != http.StatusOK {
|
||||
errs = append(errs, fmt.Sprintf("error deleting plugin %s: %s", p.Name, string(b)))
|
||||
}
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf(strings.Join(errors, "\n"))
|
||||
}
|
||||
return nil
|
||||
c.Assert(errs, checker.HasLen, 0, check.Commentf(strings.Join(errs, "\n")))
|
||||
}
|
||||
|
||||
func getAllPlugins() (types.PluginsListResponse, error) {
|
||||
|
@ -337,26 +326,21 @@ func getAllPlugins() (types.PluginsListResponse, error) {
|
|||
return plugins, nil
|
||||
}
|
||||
|
||||
func deleteAllVolumes() error {
|
||||
func deleteAllVolumes(c *check.C) {
|
||||
volumes, err := getAllVolumes()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var errors []string
|
||||
c.Assert(err, checker.IsNil)
|
||||
var errs []string
|
||||
for _, v := range volumes {
|
||||
status, b, err := sockRequest("DELETE", "/volumes/"+v.Name, nil)
|
||||
if err != nil {
|
||||
errors = append(errors, err.Error())
|
||||
errs = append(errs, err.Error())
|
||||
continue
|
||||
}
|
||||
if status != http.StatusNoContent {
|
||||
errors = append(errors, fmt.Sprintf("error deleting volume %s: %s", v.Name, string(b)))
|
||||
errs = append(errs, fmt.Sprintf("error deleting volume %s: %s", v.Name, string(b)))
|
||||
}
|
||||
}
|
||||
if len(errors) > 0 {
|
||||
return fmt.Errorf(strings.Join(errors, "\n"))
|
||||
}
|
||||
return nil
|
||||
c.Assert(errs, checker.HasLen, 0, check.Commentf(strings.Join(errs, "\n")))
|
||||
}
|
||||
|
||||
func getAllVolumes() ([]*types.Volume, error) {
|
||||
|
@ -373,15 +357,13 @@ func getAllVolumes() ([]*types.Volume, error) {
|
|||
|
||||
var protectedImages = map[string]struct{}{}
|
||||
|
||||
func deleteAllImages() error {
|
||||
cmd := exec.Command(dockerBinary, "images")
|
||||
func deleteAllImages(c *check.C) {
|
||||
cmd := exec.Command(dockerBinary, "images", "--digests")
|
||||
cmd.Env = appendBaseEnv(true)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.Assert(err, checker.IsNil)
|
||||
lines := strings.Split(string(out), "\n")[1:]
|
||||
var imgs []string
|
||||
imgMap := map[string]struct{}{}
|
||||
for _, l := range lines {
|
||||
if l == "" {
|
||||
continue
|
||||
|
@ -389,21 +371,25 @@ func deleteAllImages() error {
|
|||
fields := strings.Fields(l)
|
||||
imgTag := fields[0] + ":" + fields[1]
|
||||
if _, ok := protectedImages[imgTag]; !ok {
|
||||
if fields[0] == "<none>" {
|
||||
imgs = append(imgs, fields[2])
|
||||
continue
|
||||
if fields[0] == "<none>" || fields[1] == "<none>" {
|
||||
if fields[2] != "<none>" {
|
||||
imgMap[fields[0]+"@"+fields[2]] = struct{}{}
|
||||
} else {
|
||||
imgMap[fields[3]] = struct{}{}
|
||||
}
|
||||
imgs = append(imgs, imgTag)
|
||||
// continue
|
||||
} else {
|
||||
imgMap[imgTag] = struct{}{}
|
||||
}
|
||||
}
|
||||
if len(imgs) == 0 {
|
||||
return nil
|
||||
}
|
||||
args := append([]string{"rmi", "-f"}, imgs...)
|
||||
if err := exec.Command(dockerBinary, args...).Run(); err != nil {
|
||||
return err
|
||||
if len(imgMap) != 0 {
|
||||
imgs := make([]string, 0, len(imgMap))
|
||||
for k := range imgMap {
|
||||
imgs = append(imgs, k)
|
||||
}
|
||||
dockerCmd(c, append([]string{"rmi", "-f"}, imgs...)...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getPausedContainers() (string, error) {
|
||||
|
@ -428,30 +414,23 @@ func getSliceOfPausedContainers() ([]string, error) {
|
|||
return []string{out}, err
|
||||
}
|
||||
|
||||
func unpauseContainer(container string) error {
|
||||
return icmd.RunCommand(dockerBinary, "unpause", container).Error
|
||||
func unpauseContainer(c *check.C, container string) {
|
||||
dockerCmd(c, "unpause", container)
|
||||
}
|
||||
|
||||
func unpauseAllContainers() error {
|
||||
func unpauseAllContainers(c *check.C) {
|
||||
containers, err := getPausedContainers()
|
||||
if err != nil {
|
||||
fmt.Println(containers)
|
||||
return err
|
||||
}
|
||||
c.Assert(err, checker.IsNil, check.Commentf("containers: %v", containers))
|
||||
|
||||
containers = strings.Replace(containers, "\n", " ", -1)
|
||||
containers = strings.Trim(containers, " ")
|
||||
containerList := strings.Split(containers, " ")
|
||||
|
||||
for _, value := range containerList {
|
||||
if err = unpauseContainer(value); err != nil {
|
||||
return err
|
||||
unpauseContainer(c, value)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func deleteImages(images ...string) error {
|
||||
args := []string{dockerBinary, "rmi", "-f"}
|
||||
return icmd.RunCmd(icmd.Cmd{Command: append(args, images...)}).Error
|
||||
|
@ -490,10 +469,7 @@ func dockerCmdWithStdoutStderr(c *check.C, args ...string) (string, string, int)
|
|||
}
|
||||
|
||||
result := icmd.RunCommand(dockerBinary, args...)
|
||||
// TODO: why is c ever nil?
|
||||
if c != nil {
|
||||
c.Assert(result, icmd.Matches, icmd.Success)
|
||||
}
|
||||
return result.Stdout(), result.Stderr(), result.ExitCode
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue