1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fixed a bug preventing containers from running after being restored

This commit is contained in:
Andrea Luzzardi 2013-01-25 16:20:34 -08:00
parent f4e25694c1
commit 6513a1d94e
2 changed files with 28 additions and 8 deletions

View file

@ -70,10 +70,14 @@ func loadContainer(containerPath string) (*Container, error) {
if err != nil {
return nil, err
}
container := &Container{}
container := &Container{
stdout: newWriteBroadcaster(),
stderr: newWriteBroadcaster(),
}
if err := json.Unmarshal(data, container); err != nil {
return nil, err
}
container.State = newState()
return container, nil
}

View file

@ -179,23 +179,32 @@ func TestRestore(t *testing.T) {
if err != nil {
t.Fatal(err)
}
docker, err := NewFromDirectory(root)
// Create a container with one instance of docker
docker1, err := NewFromDirectory(root)
if err != nil {
t.Fatal(err)
}
container, err := docker.Create(
"test",
container1, err := docker1.Create(
"restore_test",
"ls",
[]string{"-al"},
[]string{"/var/lib/docker/images/ubuntu"},
&Config{},
)
if len(docker.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker.List()))
if err != nil {
t.Fatal(err)
}
defer docker1.Destroy(container1)
if len(docker1.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker1.List()))
}
if err := container1.Run(); err != nil {
t.Fatal(err)
}
defer docker.Destroy(container)
// Here are are simulating a docker restart - that is, reloading all containers
// from scratch
docker2, err := NewFromDirectory(root)
if err != nil {
t.Fatal(err)
@ -203,4 +212,11 @@ func TestRestore(t *testing.T) {
if len(docker2.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker2.List()))
}
container2 := docker2.Get("restore_test")
if container2 == nil {
t.Fatal("Unable to Get container")
}
if err := container2.Run(); err != nil {
t.Fatal(err)
}
}