зеркало из https://github.com/microsoft/docker.git
More thorough test case, use container.Stop() instead of lxc-kill,
use setStopped() during the restore step
This commit is contained in:
Родитель
8edf0ca7f3
Коммит
c780ff5ae7
|
@ -136,14 +136,14 @@ func (runtime *Runtime) Register(container *Container) error {
|
|||
}
|
||||
|
||||
// FIXME: if the container is supposed to be running but is not, auto restart it?
|
||||
// If the container is supposed to be running, make sure of if
|
||||
// If the container is supposed to be running, make sure of it
|
||||
if container.State.Running {
|
||||
if output, err := exec.Command("lxc-info", "-n", container.Id).CombinedOutput(); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if !strings.Contains(string(output), "RUNNING") {
|
||||
Debugf("Container %s was supposed to be running be is not.", container.Id)
|
||||
container.State.Running = false
|
||||
container.State.setStopped(-127)
|
||||
if err := container.ToDisk(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -297,10 +297,15 @@ func TestRestore(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
|
||||
if err := exec.Command("lxc-kill", "-n", container1_1.Id, "9").Run(); err == nil {
|
||||
t.Fatalf("container supposed to be killed (return error 255). Success received.")
|
||||
if !container1_1.State.Running {
|
||||
t.Fatalf("Container %v should appear as running but isn't", container1_1.Id)
|
||||
}
|
||||
|
||||
// Simulate a crash/manual quit of dockerd: process dies, states stays 'Running'
|
||||
if err := container1_1.Stop(); err != nil {
|
||||
t.Fatalf("Could not stop container: %v", err)
|
||||
}
|
||||
|
||||
container1_1.State.Running = true
|
||||
|
||||
if len(runtime1.List()) != 2 {
|
||||
|
@ -310,6 +315,10 @@ func TestRestore(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if !container1_1.State.Running {
|
||||
t.Fatalf("Container %v should appear as running but isn't", container1_1.Id)
|
||||
}
|
||||
|
||||
// Here are are simulating a docker restart - that is, reloading all containers
|
||||
// from scratch
|
||||
runtime2, err := NewRuntimeFromDirectory(root)
|
||||
|
@ -323,6 +332,7 @@ func TestRestore(t *testing.T) {
|
|||
runningCount := 0
|
||||
for _, c := range runtime2.List() {
|
||||
if c.State.Running {
|
||||
t.Errorf("Running container found: %v (%v)", c.Id, c.Path)
|
||||
runningCount++
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче