2013-01-19 04:13:39 +04:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2013-04-20 07:46:07 +04:00
|
|
|
"fmt"
|
2013-05-15 05:52:09 +04:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2013-03-11 16:42:36 +04:00
|
|
|
"io"
|
2013-01-19 04:13:39 +04:00
|
|
|
"io/ioutil"
|
2013-04-20 07:46:07 +04:00
|
|
|
"net"
|
2013-01-19 04:13:39 +04:00
|
|
|
"os"
|
2013-03-15 13:03:41 +04:00
|
|
|
"os/user"
|
2013-04-02 22:00:14 +04:00
|
|
|
"sync"
|
2013-01-19 04:13:39 +04:00
|
|
|
"testing"
|
2013-04-02 21:06:49 +04:00
|
|
|
"time"
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
|
2013-03-26 04:18:56 +04:00
|
|
|
const unitTestImageName string = "docker-ut"
|
2013-03-14 13:30:50 +04:00
|
|
|
|
2013-04-17 22:32:13 +04:00
|
|
|
const unitTestStoreBase string = "/var/lib/docker/unit-tests"
|
2013-02-27 05:45:46 +04:00
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
func nuke(runtime *Runtime) error {
|
2013-04-02 22:00:14 +04:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, container := range runtime.List() {
|
|
|
|
wg.Add(1)
|
2013-04-03 13:10:50 +04:00
|
|
|
go func(c *Container) {
|
|
|
|
c.Kill()
|
2013-04-03 13:11:34 +04:00
|
|
|
wg.Done()
|
2013-04-03 13:10:50 +04:00
|
|
|
}(container)
|
2013-04-02 22:00:14 +04:00
|
|
|
}
|
|
|
|
wg.Wait()
|
2013-03-21 11:41:15 +04:00
|
|
|
return os.RemoveAll(runtime.root)
|
2013-03-12 11:08:41 +04:00
|
|
|
}
|
|
|
|
|
2013-03-11 16:42:36 +04:00
|
|
|
func layerArchive(tarfile string) (io.Reader, error) {
|
2013-02-27 05:45:46 +04:00
|
|
|
// FIXME: need to close f somewhere
|
|
|
|
f, err := os.Open(tarfile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return f, nil
|
|
|
|
}
|
2013-02-15 03:37:45 +04:00
|
|
|
|
2013-02-14 02:01:44 +04:00
|
|
|
func init() {
|
2013-02-15 03:37:45 +04:00
|
|
|
// Hack to run sys init during unit testing
|
2013-05-15 05:52:09 +04:00
|
|
|
if utils.SelfPath() == "/sbin/init" {
|
2013-02-14 02:01:44 +04:00
|
|
|
SysInit()
|
2013-03-14 13:30:50 +04:00
|
|
|
return
|
2013-02-14 02:01:44 +04:00
|
|
|
}
|
2013-02-15 03:37:45 +04:00
|
|
|
|
2013-03-15 13:03:41 +04:00
|
|
|
if usr, err := user.Current(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
} else if usr.Uid != "0" {
|
|
|
|
panic("docker tests needs to be run as root")
|
|
|
|
}
|
|
|
|
|
2013-04-25 04:43:41 +04:00
|
|
|
NetworkBridgeIface = "testdockbr0"
|
|
|
|
|
2013-03-14 13:30:50 +04:00
|
|
|
// Make it our Store root
|
2013-04-25 06:01:23 +04:00
|
|
|
runtime, err := NewRuntimeFromDirectory(unitTestStoreBase, false)
|
2013-03-14 13:30:50 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2013-05-06 13:31:22 +04:00
|
|
|
|
2013-03-14 13:30:50 +04:00
|
|
|
// Create the "Server"
|
|
|
|
srv := &Server{
|
2013-05-29 04:35:10 +04:00
|
|
|
runtime: runtime,
|
2013-03-14 13:30:50 +04:00
|
|
|
}
|
|
|
|
// Retrieve the Image
|
2013-05-25 05:32:21 +04:00
|
|
|
if err := srv.ImagePull(unitTestImageName, "", "", os.Stdout, false); err != nil {
|
2013-03-14 13:30:50 +04:00
|
|
|
panic(err)
|
2013-02-15 03:37:45 +04:00
|
|
|
}
|
2013-02-14 02:01:44 +04:00
|
|
|
}
|
|
|
|
|
2013-05-25 05:32:21 +04:00
|
|
|
// FIXME: test that ImagePull(json=true) send correct json output
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
func newTestRuntime() (*Runtime, error) {
|
2013-01-19 04:13:39 +04:00
|
|
|
root, err := ioutil.TempDir("", "docker-test")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-03-14 13:30:50 +04:00
|
|
|
if err := os.Remove(root); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-05-29 00:38:26 +04:00
|
|
|
if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
|
2013-03-14 13:30:50 +04:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2013-04-25 06:01:23 +04:00
|
|
|
runtime, err := NewRuntimeFromDirectory(root, false)
|
2013-01-19 04:13:39 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2013-04-27 01:32:55 +04:00
|
|
|
runtime.UpdateCapabilities(true)
|
2013-03-21 11:41:15 +04:00
|
|
|
return runtime, nil
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-22 04:47:23 +04:00
|
|
|
func GetTestImage(runtime *Runtime) *Image {
|
2013-03-21 11:41:15 +04:00
|
|
|
imgs, err := runtime.graph.All()
|
2013-02-27 05:45:46 +04:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
} else if len(imgs) < 1 {
|
|
|
|
panic("GASP")
|
|
|
|
}
|
|
|
|
return imgs[0]
|
|
|
|
}
|
|
|
|
|
2013-03-22 04:47:23 +04:00
|
|
|
func TestRuntimeCreate(t *testing.T) {
|
2013-03-21 11:41:15 +04:00
|
|
|
runtime, err := newTestRuntime()
|
2013-01-19 04:13:39 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer nuke(runtime)
|
2013-01-19 04:13:39 +04:00
|
|
|
|
|
|
|
// Make sure we start we 0 containers
|
2013-03-21 11:41:15 +04:00
|
|
|
if len(runtime.List()) != 0 {
|
|
|
|
t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
2013-05-07 22:18:13 +04:00
|
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
|
|
|
|
|
|
container, err := builder.Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2013-03-21 11:41:15 +04:00
|
|
|
if err := runtime.Destroy(container); err != nil {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// Make sure we can find the newly created container with List()
|
2013-03-21 11:41:15 +04:00
|
|
|
if len(runtime.List()) != 1 {
|
|
|
|
t.Errorf("Expected 1 container, %v found", len(runtime.List()))
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the container List() returns is the right one
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.List()[0].Id != container.Id {
|
|
|
|
t.Errorf("Unexpected container %v returned by List", runtime.List()[0])
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we can get the container with Get()
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.Get(container.Id) == nil {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Errorf("Unable to get newly created container")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure it is the right container
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.Get(container.Id) != container {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Errorf("Get() returned the wrong container")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure Exists returns it as existing
|
2013-03-21 11:41:15 +04:00
|
|
|
if !runtime.Exists(container.Id) {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Errorf("Exists() returned false for a newly created container")
|
|
|
|
}
|
2013-05-07 22:18:13 +04:00
|
|
|
|
|
|
|
// Make sure crete with bad parameters returns an error
|
|
|
|
_, err = builder.Create(
|
|
|
|
&Config{
|
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Builder.Create should throw an error when Cmd is missing")
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = builder.Create(
|
|
|
|
&Config{
|
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err == nil {
|
|
|
|
t.Fatal("Builder.Create should throw an error when Cmd is empty")
|
|
|
|
}
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDestroy(t *testing.T) {
|
2013-03-21 11:41:15 +04:00
|
|
|
runtime, err := newTestRuntime()
|
2013-01-19 04:13:39 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer nuke(runtime)
|
2013-04-25 02:35:28 +04:00
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
// Destroy
|
2013-03-21 11:41:15 +04:00
|
|
|
if err := runtime.Destroy(container); err != nil {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Error(err)
|
|
|
|
}
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
// Make sure runtime.Exists() behaves correctly
|
|
|
|
if runtime.Exists("test_destroy") {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Errorf("Exists() returned true")
|
|
|
|
}
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
// Make sure runtime.List() doesn't list the destroyed container
|
|
|
|
if len(runtime.List()) != 0 {
|
|
|
|
t.Errorf("Expected 0 container, %v found", len(runtime.List()))
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
// Make sure runtime.Get() refuses to return the unexisting container
|
|
|
|
if runtime.Get(container.Id) != nil {
|
2013-01-19 04:13:39 +04:00
|
|
|
t.Errorf("Unable to get newly created container")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the container root directory does not exist anymore
|
2013-03-21 11:25:00 +04:00
|
|
|
_, err = os.Stat(container.root)
|
2013-01-19 04:13:39 +04:00
|
|
|
if err == nil || !os.IsNotExist(err) {
|
|
|
|
t.Errorf("Container root directory still exists after destroy")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test double destroy
|
2013-03-21 11:41:15 +04:00
|
|
|
if err := runtime.Destroy(container); err == nil {
|
2013-01-19 04:13:39 +04:00
|
|
|
// It should have failed
|
|
|
|
t.Errorf("Double destroy did not fail")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGet(t *testing.T) {
|
2013-03-21 11:41:15 +04:00
|
|
|
runtime, err := newTestRuntime()
|
2013-01-19 04:13:39 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer nuke(runtime)
|
2013-04-25 02:35:28 +04:00
|
|
|
|
|
|
|
builder := NewBuilder(runtime)
|
|
|
|
|
|
|
|
container1, err := builder.Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer runtime.Destroy(container1)
|
2013-01-19 04:13:39 +04:00
|
|
|
|
2013-04-25 02:35:28 +04:00
|
|
|
container2, err := builder.Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer runtime.Destroy(container2)
|
2013-01-19 04:13:39 +04:00
|
|
|
|
2013-04-25 02:35:28 +04:00
|
|
|
container3, err := builder.Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-19 04:13:39 +04:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer runtime.Destroy(container3)
|
2013-01-19 04:13:39 +04:00
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.Get(container1.Id) != container1 {
|
|
|
|
t.Errorf("Get(test1) returned %v while expecting %v", runtime.Get(container1.Id), container1)
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.Get(container2.Id) != container2 {
|
|
|
|
t.Errorf("Get(test2) returned %v while expecting %v", runtime.Get(container2.Id), container2)
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 11:41:15 +04:00
|
|
|
if runtime.Get(container3.Id) != container3 {
|
|
|
|
t.Errorf("Get(test3) returned %v while expecting %v", runtime.Get(container3.Id), container3)
|
2013-01-19 04:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-01-26 02:09:21 +04:00
|
|
|
|
2013-04-20 07:46:07 +04:00
|
|
|
// Run a container with a TCP port allocated, and test that it can receive connections on localhost
|
|
|
|
func TestAllocatePortLocalhost(t *testing.T) {
|
|
|
|
runtime, err := newTestRuntime()
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-04-25 02:35:28 +04:00
|
|
|
container, err := NewBuilder(runtime).Create(&Config{
|
2013-04-20 07:46:07 +04:00
|
|
|
Image: GetTestImage(runtime).Id,
|
|
|
|
Cmd: []string{"sh", "-c", "echo well hello there | nc -l -p 5555"},
|
|
|
|
PortSpecs: []string{"5555"},
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if err := container.Start(); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer container.Kill()
|
2013-04-23 21:28:40 +04:00
|
|
|
|
|
|
|
setTimeout(t, "Waiting for the container to be started timed out", 2*time.Second, func() {
|
|
|
|
for {
|
|
|
|
if container.State.Running {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(10 * time.Millisecond)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2013-04-20 07:46:07 +04:00
|
|
|
conn, err := net.Dial("tcp",
|
|
|
|
fmt.Sprintf(
|
|
|
|
"localhost:%s", container.NetworkSettings.PortMapping["5555"],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
defer conn.Close()
|
|
|
|
output, err := ioutil.ReadAll(conn)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
if string(output) != "well hello there\n" {
|
|
|
|
t.Fatalf("Received wrong output from network connection: should be '%s', not '%s'",
|
|
|
|
"well hello there\n",
|
|
|
|
string(output),
|
|
|
|
)
|
|
|
|
}
|
2013-04-23 21:28:40 +04:00
|
|
|
container.Wait()
|
2013-04-20 07:46:07 +04:00
|
|
|
}
|
|
|
|
|
2013-01-26 02:09:21 +04:00
|
|
|
func TestRestore(t *testing.T) {
|
2013-03-14 13:30:50 +04:00
|
|
|
|
2013-01-26 02:09:21 +04:00
|
|
|
root, err := ioutil.TempDir("", "docker-test")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-14 13:30:50 +04:00
|
|
|
if err := os.Remove(root); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-05-29 00:38:26 +04:00
|
|
|
if err := utils.CopyDirectory(unitTestStoreBase, root); err != nil {
|
2013-03-14 13:30:50 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-01-26 04:20:34 +04:00
|
|
|
|
2013-04-25 06:01:23 +04:00
|
|
|
runtime1, err := NewRuntimeFromDirectory(root, false)
|
2013-01-26 02:09:21 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-02-27 05:45:46 +04:00
|
|
|
|
2013-04-25 02:35:28 +04:00
|
|
|
builder := NewBuilder(runtime1)
|
|
|
|
|
2013-02-27 05:45:46 +04:00
|
|
|
// Create a container with one instance of docker
|
2013-04-25 02:35:28 +04:00
|
|
|
container1, err := builder.Create(&Config{
|
2013-03-23 23:39:09 +04:00
|
|
|
Image: GetTestImage(runtime1).Id,
|
|
|
|
Cmd: []string{"ls", "-al"},
|
2013-03-23 23:16:58 +04:00
|
|
|
},
|
2013-01-26 02:09:21 +04:00
|
|
|
)
|
2013-01-26 04:20:34 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer runtime1.Destroy(container1)
|
2013-04-01 07:14:54 +04:00
|
|
|
|
|
|
|
// Create a second container meant to be killed
|
2013-04-25 02:35:28 +04:00
|
|
|
container2, err := builder.Create(&Config{
|
2013-04-01 07:14:54 +04:00
|
|
|
Image: GetTestImage(runtime1).Id,
|
|
|
|
Cmd: []string{"/bin/cat"},
|
|
|
|
OpenStdin: true,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-04-02 18:13:42 +04:00
|
|
|
defer runtime1.Destroy(container2)
|
2013-04-01 07:14:54 +04:00
|
|
|
|
|
|
|
// Start the container non blocking
|
2013-04-02 18:13:42 +04:00
|
|
|
if err := container2.Start(); err != nil {
|
2013-04-01 07:14:54 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2013-04-02 18:13:42 +04:00
|
|
|
if !container2.State.Running {
|
|
|
|
t.Fatalf("Container %v should appear as running but isn't", container2.Id)
|
2013-04-02 18:01:43 +04:00
|
|
|
}
|
|
|
|
|
2013-04-01 07:14:54 +04:00
|
|
|
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
|
2013-04-02 21:06:49 +04:00
|
|
|
cStdin, _ := container2.StdinPipe()
|
|
|
|
cStdin.Close()
|
2013-04-05 07:32:44 +04:00
|
|
|
if err := container2.WaitTimeout(2 * time.Second); err != nil {
|
2013-04-03 21:48:02 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-04-02 18:13:42 +04:00
|
|
|
container2.State.Running = true
|
2013-04-02 21:06:49 +04:00
|
|
|
container2.ToDisk()
|
2013-04-01 07:14:54 +04:00
|
|
|
|
|
|
|
if len(runtime1.List()) != 2 {
|
|
|
|
t.Errorf("Expected 2 container, %v found", len(runtime1.List()))
|
2013-01-26 04:20:34 +04:00
|
|
|
}
|
|
|
|
if err := container1.Run(); err != nil {
|
|
|
|
t.Fatal(err)
|
2013-01-26 02:09:21 +04:00
|
|
|
}
|
|
|
|
|
2013-04-02 18:13:42 +04:00
|
|
|
if !container2.State.Running {
|
|
|
|
t.Fatalf("Container %v should appear as running but isn't", container2.Id)
|
2013-04-02 18:01:43 +04:00
|
|
|
}
|
|
|
|
|
2013-01-26 04:20:34 +04:00
|
|
|
// Here are are simulating a docker restart - that is, reloading all containers
|
|
|
|
// from scratch
|
2013-04-25 06:01:23 +04:00
|
|
|
runtime2, err := NewRuntimeFromDirectory(root, false)
|
2013-01-26 02:09:21 +04:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-03-21 11:41:15 +04:00
|
|
|
defer nuke(runtime2)
|
2013-04-01 07:14:54 +04:00
|
|
|
if len(runtime2.List()) != 2 {
|
|
|
|
t.Errorf("Expected 2 container, %v found", len(runtime2.List()))
|
|
|
|
}
|
|
|
|
runningCount := 0
|
|
|
|
for _, c := range runtime2.List() {
|
|
|
|
if c.State.Running {
|
2013-04-02 18:01:43 +04:00
|
|
|
t.Errorf("Running container found: %v (%v)", c.Id, c.Path)
|
2013-04-01 07:14:54 +04:00
|
|
|
runningCount++
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if runningCount != 0 {
|
|
|
|
t.Fatalf("Expected 0 container alive, %d found", runningCount)
|
2013-01-26 02:09:21 +04:00
|
|
|
}
|
2013-04-02 18:13:42 +04:00
|
|
|
container3 := runtime2.Get(container1.Id)
|
|
|
|
if container3 == nil {
|
2013-01-26 04:20:34 +04:00
|
|
|
t.Fatal("Unable to Get container")
|
|
|
|
}
|
2013-04-02 18:13:42 +04:00
|
|
|
if err := container3.Run(); err != nil {
|
2013-01-26 04:20:34 +04:00
|
|
|
t.Fatal(err)
|
|
|
|
}
|
2013-04-05 07:40:42 +04:00
|
|
|
container2.State.Running = false
|
2013-01-26 02:09:21 +04:00
|
|
|
}
|