Exemplo n.º 1
0
// Remove everything Eris.
func RemoveAllContainers() error {
	return util.Clean(false, false, false, false)
}
Exemplo n.º 2
0
func TestClean(t *testing.T) {
	// since we'll be cleaning all eris containers, check if any exist & flame out
	contns, err := util.DockerClient.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		fatal(t, err)
	}
	for _, container := range contns {
		if container.Labels["eris:ERIS"] == "true" {
			fatal(t, fmt.Errorf("Eris container detected. Please remove all eris containers prior to initiating tests\n"))
		}
	}

	// each boot 2 contns
	testStartService(t, "ipfs", false)
	testStartService(t, "keys", false)

	opts := docker.CreateContainerOptions{
		Name: "not_eris",
		Config: &docker.Config{
			Image:           "busybox",
			AttachStdin:     false,
			AttachStdout:    false,
			AttachStderr:    false,
			Tty:             false,
			OpenStdin:       false,
			NetworkDisabled: true,
			Entrypoint:      []string{},
			Cmd:             []string{},
		},
		HostConfig: &docker.HostConfig{},
	}

	newCont, err := util.DockerClient.CreateContainer(opts)
	if err != nil {
		fatal(t, err)
	}

	//only runs default clean -> need test for others
	if err := util.Clean(false, false, false, false); err != nil {
		fatal(t, err)
	}

	contns, err = util.DockerClient.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		fatal(t, err)
	}

	//if any Eris, fail
	for _, container := range contns {
		if container.Labels["eris:ERIS"] == "true" {
			fatal(t, fmt.Errorf("Eris container detected. Clean did not do its job\n"))
		}
	}

	var notEris bool
	//make sure "not_eris" still exists
	for _, container := range contns {
		if container.ID == newCont.ID {
			notEris = true
			break
		} else {
			notEris = false
		}
	}

	if !notEris {
		fatal(t, fmt.Errorf("Expected running container, did not find %s\n", newCont.ID))
	}

	//teardown non-eris
	rmOpts := docker.RemoveContainerOptions{
		ID:            newCont.ID,
		RemoveVolumes: true,
		Force:         true,
	}

	if err := util.DockerClient.RemoveContainer(rmOpts); err != nil {
		fatal(t, err)
	}

	contns, err = util.DockerClient.ListContainers(docker.ListContainersOptions{All: true})
	if err != nil {
		fatal(t, err)
	}

	//check only that not_eris and no eris contns are running
	for _, container := range contns {
		if container.Labels["eris:ERIS"] == "true" || container.ID == newCont.ID {
			fatal(t, fmt.Errorf("found remaining eris containers or test container, something went wrong\n"))
		}
	}
}
Exemplo n.º 3
0
func Clean(do *definitions.Do) error {
	if err := util.Clean(do.Yes, do.All, do.RmD, do.Images); err != nil {
		return err
	}
	return nil
}