2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/integration/container"
|
2018-01-02 23:55:33 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types"
|
2018-02-10 18:01:37 -05:00
|
|
|
"github.com/docker/docker/integration/internal/container"
|
2018-02-09 13:13:26 -05:00
|
|
|
"github.com/docker/docker/integration/internal/request"
|
2018-03-13 15:28:34 -04:00
|
|
|
"github.com/gotestyourself/gotestyourself/assert"
|
2018-01-02 23:55:33 -05:00
|
|
|
"github.com/gotestyourself/gotestyourself/icmd"
|
|
|
|
"github.com/gotestyourself/gotestyourself/poll"
|
|
|
|
"github.com/gotestyourself/gotestyourself/skip"
|
|
|
|
)
|
|
|
|
|
2018-01-29 18:36:45 -05:00
|
|
|
func TestStopContainerWithRestartPolicyAlways(t *testing.T) {
|
|
|
|
defer setupTest(t)()
|
|
|
|
client := request.NewAPIClient(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
names := []string{"verifyRestart1", "verifyRestart2"}
|
|
|
|
for _, name := range names {
|
2018-02-10 18:01:37 -05:00
|
|
|
container.Run(t, ctx, client, container.WithName(name), container.WithCmd("false"), func(c *container.TestContainerConfig) {
|
|
|
|
c.HostConfig.RestartPolicy.Name = "always"
|
|
|
|
})
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsInState(ctx, client, name, "running", "restarting"), poll.WithDelay(100*time.Millisecond))
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
|
|
|
err := client.ContainerStop(ctx, name, nil)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, name := range names {
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsStopped(ctx, client, name), poll.WithDelay(100*time.Millisecond))
|
2018-01-29 18:36:45 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-02 23:55:33 -05:00
|
|
|
func TestDeleteDevicemapper(t *testing.T) {
|
|
|
|
skip.IfCondition(t, testEnv.DaemonInfo.Driver != "devicemapper")
|
|
|
|
|
|
|
|
defer setupTest(t)()
|
|
|
|
client := request.NewAPIClient(t)
|
|
|
|
ctx := context.Background()
|
|
|
|
|
2018-02-10 18:01:37 -05:00
|
|
|
id := container.Run(t, ctx, client, container.WithName("foo"), container.WithCmd("echo"))
|
2018-01-02 23:55:33 -05:00
|
|
|
|
2018-02-22 05:30:51 -05:00
|
|
|
poll.WaitOn(t, container.IsStopped(ctx, client, id), poll.WithDelay(100*time.Millisecond))
|
2018-01-02 23:55:33 -05:00
|
|
|
|
2018-02-10 18:01:37 -05:00
|
|
|
inspect, err := client.ContainerInspect(ctx, id)
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-02 23:55:33 -05:00
|
|
|
|
|
|
|
deviceID := inspect.GraphDriver.Data["DeviceId"]
|
|
|
|
|
|
|
|
// Find pool name from device name
|
|
|
|
deviceName := inspect.GraphDriver.Data["DeviceName"]
|
|
|
|
devicePrefix := deviceName[:strings.LastIndex(deviceName, "-")]
|
|
|
|
devicePool := fmt.Sprintf("/dev/mapper/%s-pool", devicePrefix)
|
|
|
|
|
|
|
|
result := icmd.RunCommand("dmsetup", "message", devicePool, "0", fmt.Sprintf("delete %s", deviceID))
|
|
|
|
result.Assert(t, icmd.Success)
|
|
|
|
|
2018-02-10 18:01:37 -05:00
|
|
|
err = client.ContainerRemove(ctx, id, types.ContainerRemoveOptions{})
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
2018-01-02 23:55:33 -05:00
|
|
|
}
|