func myLog(c *check.C, args ...interface{}) { if len(args) == 1 { c.Log(fmt.Sprintf("%s: %v\n", c.TestName(), args[0])) return } newArgs := make([]interface{}, len(args)-1) for i, a := range args[1:] { switch a := a.(type) { default: j, err := json.Marshal(a) if err == nil { newArgs[i] = fmt.Sprintf("%T: %s", a, j) } else { newArgs[i] = fmt.Sprintf("%s", a) } case bool: newArgs[i] = a case int: newArgs[i] = a case uint: newArgs[i] = a case uint64: newArgs[i] = a case string: newArgs[i] = a } } fmtStr := fmt.Sprintf("%s: %s\n", c.TestName(), args[0].(string)) c.Logf(fmtStr, newArgs...) }
func (s *DockerSuite) TestRmiContainerImageNotFound(c *check.C) { // Build 2 images for testing. imageNames := []string{"test1", "test2"} imageIds := make([]string, 2) for i, name := range imageNames { dockerfile := fmt.Sprintf("FROM busybox\nMAINTAINER %s\nRUN echo %s\n", name, name) id, err := buildImage(name, dockerfile, false) c.Assert(err, check.IsNil) imageIds[i] = id } // Create a long-running container. dockerCmd(c, "run", "-d", imageNames[0], "top") // Create a stopped container, and then force remove its image. dockerCmd(c, "run", imageNames[1], "true") dockerCmd(c, "rmi", "-f", imageIds[1]) // Try to remove the image of the running container and see if it fails as expected. out, _, err := dockerCmdWithError("rmi", "-f", imageIds[0]) if err == nil || !strings.Contains(out, "is using it") { c.Log(out) c.Fatal("The image of the running container should not be removed.") } }
// See https://github.com/docker/docker/issues/14116 func (s *DockerSuite) TestRmiImageIDForceWithRunningContainersAndMultipleTags(c *check.C) { dockerfile := "FROM busybox\nRUN echo test 14116\n" imgID, err := buildImage("test-14116", dockerfile, false) c.Assert(err, check.IsNil) newTag := "newtag" dockerCmd(c, "tag", imgID, newTag) dockerCmd(c, "run", "-d", imgID, "top") out, _, err := dockerCmdWithError("rmi", "-f", imgID) if err == nil || !strings.Contains(out, "stop it and retry") { c.Log(out) c.Fatalf("rmi -f should not delete image with running containers") } }
func (s *DockerSuite) TestSaveLoadParents(c *check.C) { testRequires(c, DaemonIsLinux) makeImage := func(from string, addfile string) string { var ( out string ) out, _ = dockerCmd(c, "run", "-d", from, "touch", addfile) cleanedContainerID := strings.TrimSpace(out) out, _ = dockerCmd(c, "commit", cleanedContainerID) imageID := strings.TrimSpace(out) dockerCmd(c, "rm", "-f", cleanedContainerID) return imageID } idFoo := makeImage("busybox", "foo") idBar := makeImage(idFoo, "bar") tmpDir, err := ioutil.TempDir("", "save-load-parents") c.Assert(err, checker.IsNil) defer os.RemoveAll(tmpDir) c.Log("tmpdir", tmpDir) outfile := filepath.Join(tmpDir, "out.tar") dockerCmd(c, "save", "-o", outfile, idBar, idFoo) dockerCmd(c, "rmi", idBar) dockerCmd(c, "load", "-i", outfile) inspectOut := inspectField(c, idBar, "Parent") c.Assert(inspectOut, checker.Equals, idFoo) inspectOut = inspectField(c, idFoo, "Parent") c.Assert(inspectOut, checker.Equals, "") }
// #13422 func (s *DockerSuite) TestRmiUntagHistoryLayer(c *check.C) { testRequires(c, DaemonIsLinux) image := "tmp1" // Build a image for testing. dockerfile := `FROM busybox MAINTAINER foo RUN echo 0 #layer0 RUN echo 1 #layer1 RUN echo 2 #layer2 ` _, err := buildImage(image, dockerfile, false) c.Assert(err, check.IsNil) out, _ := dockerCmd(c, "history", "-q", image) ids := strings.Split(out, "\n") idToTag := ids[2] // Tag layer0 to "tmp2". newTag := "tmp2" dockerCmd(c, "tag", idToTag, newTag) // Create a container based on "tmp1". dockerCmd(c, "run", "-d", image, "true") // See if the "tmp2" can be untagged. out, _ = dockerCmd(c, "rmi", newTag) if d := strings.Count(out, "Untagged: "); d != 1 { c.Log(out) c.Fatalf("Expected 1 untagged entry got %d: %q", d, out) } // Now let's add the tag again and create a container based on it. dockerCmd(c, "tag", idToTag, newTag) out, _ = dockerCmd(c, "run", "-d", newTag, "true") cid := strings.TrimSpace(out) // At this point we have 2 containers, one based on layer2 and another based on layer0. // Try to untag "tmp2" without the -f flag. out, _, err = dockerCmdWithError("rmi", newTag) if err == nil || !strings.Contains(out, cid[:12]) || !strings.Contains(out, "(must force)") { c.Log(out) c.Fatalf("%q should not be untagged without the -f flag", newTag) } // Add the -f flag and test again. out, _ = dockerCmd(c, "rmi", "-f", newTag) if !strings.Contains(out, fmt.Sprintf("Untagged: %s:latest", newTag)) { c.Log(out) c.Fatalf("%q should be allowed to untag with the -f flag", newTag) } }
func myLog(c *check.C, args ...interface{}) { fmt.Println(args) c.Log(args) }
func myLog(c *check.C, args ...interface{}) { fmt.Println("IntegrationTest> ", args) c.Log("IntegrationTest> ", args) }
func (s *MySuite) SetUpTest(c *check.C) { dir, _ := os.Getwd() c.Log("Entering setup in directory", dir) common.MockPortsInConfig("../common/testdata/romana.sample.yaml") s.configFile = "/tmp/romana.yaml" var err error s.config, err = common.ReadConfig(s.configFile) if err != nil { panic(err) } c.Log("Root configuration: ", s.config.Services["root"].Common.Api.GetHostPort()) // Starting root service fmt.Println("STARTING ROOT SERVICE") channelRoot, addr, err := root.Run(s.configFile) if err != nil { c.Error(err) } s.rootUrl = "http://" + addr c.Log("Root URL:", s.rootUrl) msg := <-channelRoot c.Log("Root service said:", msg) c.Log("Waiting a bit...") time.Sleep(time.Second) c.Log("Creating topology schema with root URL", s.rootUrl) err = topology.CreateSchema(s.rootUrl, true) if err != nil { c.Fatal(err) } c.Log("OK") c.Log("Creating tenant schema") err = tenant.CreateSchema(s.rootUrl, true) if err != nil { c.Fatal(err) } c.Log("OK") c.Log("Creating IPAM schema") err = ipam.CreateSchema(s.rootUrl, true) if err != nil { c.Fatal(err) } c.Log("OK") myLog(c, "Done with setup") }