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

Renamed Docker{} to Runtime{} for clarity

This commit is contained in:
Solomon Hykes 2013-03-21 00:41:15 -07:00
parent 7c57a4cfc0
commit b8547f31e4
5 changed files with 229 additions and 229 deletions

View file

@ -116,7 +116,7 @@ func (srv *Server) CmdWait(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
fmt.Fprintln(stdout, container.Wait()) fmt.Fprintln(stdout, container.Wait())
} else { } else {
return errors.New("No such container: " + name) return errors.New("No such container: " + name)
@ -133,7 +133,7 @@ func (srv *Server) CmdVersion(stdin io.ReadCloser, stdout io.Writer, args ...str
// 'docker info': display system-wide information. // 'docker info': display system-wide information.
func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string) error { func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string) error {
images, _ := srv.containers.graph.All() images, _ := srv.runtime.graph.All()
var imgcount int var imgcount int
if images == nil { if images == nil {
imgcount = 0 imgcount = 0
@ -149,7 +149,7 @@ func (srv *Server) CmdInfo(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
fmt.Fprintf(stdout, "containers: %d\nversion: %s\nimages: %d\n", fmt.Fprintf(stdout, "containers: %d\nversion: %s\nimages: %d\n",
len(srv.containers.List()), len(srv.runtime.List()),
VERSION, VERSION,
imgcount) imgcount)
return nil return nil
@ -165,7 +165,7 @@ func (srv *Server) CmdStop(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
if err := container.Stop(); err != nil { if err := container.Stop(); err != nil {
return err return err
} }
@ -187,7 +187,7 @@ func (srv *Server) CmdRestart(stdin io.ReadCloser, stdout io.Writer, args ...str
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
if err := container.Restart(); err != nil { if err := container.Restart(); err != nil {
return err return err
} }
@ -209,7 +209,7 @@ func (srv *Server) CmdStart(stdin io.ReadCloser, stdout io.Writer, args ...strin
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
if err := container.Start(); err != nil { if err := container.Start(); err != nil {
return err return err
} }
@ -231,7 +231,7 @@ func (srv *Server) CmdMount(stdin io.ReadCloser, stdout io.Writer, args ...strin
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
if err := container.EnsureMounted(); err != nil { if err := container.EnsureMounted(); err != nil {
return err return err
} }
@ -254,9 +254,9 @@ func (srv *Server) CmdInspect(stdin io.ReadCloser, stdout io.Writer, args ...str
} }
name := cmd.Arg(0) name := cmd.Arg(0)
var obj interface{} var obj interface{}
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
obj = container obj = container
} else if image, err := srv.containers.graph.Get(name); err != nil { } else if image, err := srv.runtime.graph.Get(name); err != nil {
return err return err
} else if image != nil { } else if image != nil {
obj = image obj = image
@ -291,7 +291,7 @@ func (srv *Server) CmdPort(stdin io.ReadCloser, stdout io.Writer, args ...string
} }
name := cmd.Arg(0) name := cmd.Arg(0)
privatePort := cmd.Arg(1) privatePort := cmd.Arg(1)
if container := srv.containers.Get(name); container == nil { if container := srv.runtime.Get(name); container == nil {
return errors.New("No such container: " + name) return errors.New("No such container: " + name)
} else { } else {
if frontend, exists := container.NetworkSettings.PortMapping[privatePort]; !exists { if frontend, exists := container.NetworkSettings.PortMapping[privatePort]; !exists {
@ -311,7 +311,7 @@ func (srv *Server) CmdRmi(stdin io.ReadCloser, stdout io.Writer, args ...string)
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
if err := srv.containers.graph.Delete(name); err != nil { if err := srv.runtime.graph.Delete(name); err != nil {
return err return err
} }
} }
@ -324,11 +324,11 @@ func (srv *Server) CmdRm(stdin io.ReadCloser, stdout io.Writer, args ...string)
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
container := srv.containers.Get(name) container := srv.runtime.Get(name)
if container == nil { if container == nil {
return errors.New("No such container: " + name) return errors.New("No such container: " + name)
} }
if err := srv.containers.Destroy(container); err != nil { if err := srv.runtime.Destroy(container); err != nil {
fmt.Fprintln(stdout, "Error destroying container "+name+": "+err.Error()) fmt.Fprintln(stdout, "Error destroying container "+name+": "+err.Error())
} }
} }
@ -342,7 +342,7 @@ func (srv *Server) CmdKill(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
container := srv.containers.Get(name) container := srv.runtime.Get(name)
if container == nil { if container == nil {
return errors.New("No such container: " + name) return errors.New("No such container: " + name)
} }
@ -390,7 +390,7 @@ func (srv *Server) CmdImport(stdin io.ReadCloser, stdout io.Writer, args ...stri
archive = future.ProgressReader(resp.Body, int(resp.ContentLength), stdout) archive = future.ProgressReader(resp.Body, int(resp.ContentLength), stdout)
} }
fmt.Fprintf(stdout, "Unpacking to %s\n", name) fmt.Fprintf(stdout, "Unpacking to %s\n", name)
img, err := srv.containers.graph.Create(archive, "", "") img, err := srv.runtime.graph.Create(archive, "", "")
if err != nil { if err != nil {
return err return err
} }
@ -420,7 +420,7 @@ func (srv *Server) CmdImages(stdin io.ReadCloser, stdout io.Writer, args ...stri
fmt.Fprintf(w, "NAME\tID\tCREATED\tPARENT\n") fmt.Fprintf(w, "NAME\tID\tCREATED\tPARENT\n")
} }
if *quiet { if *quiet {
images, err := srv.containers.graph.All() images, err := srv.runtime.graph.All()
if err != nil { if err != nil {
return err return err
} }
@ -486,7 +486,7 @@ func (srv *Server) CmdPs(stdin io.ReadCloser, stdout io.Writer, args ...string)
if !*quiet { if !*quiet {
fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT\n") fmt.Fprintf(w, "ID\tIMAGE\tCOMMAND\tCREATED\tSTATUS\tCOMMENT\n")
} }
for _, container := range srv.containers.List() { for _, container := range srv.runtime.List() {
if !container.State.Running && !*fl_all { if !container.State.Running && !*fl_all {
continue continue
} }
@ -532,7 +532,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
cmd.Usage() cmd.Usage()
return nil return nil
} }
if container := srv.containers.Get(containerName); container != nil { if container := srv.runtime.Get(containerName); container != nil {
// FIXME: freeze the container before copying it to avoid data corruption? // FIXME: freeze the container before copying it to avoid data corruption?
// FIXME: this shouldn't be in commands. // FIXME: this shouldn't be in commands.
rwTar, err := container.ExportRw() rwTar, err := container.ExportRw()
@ -540,7 +540,7 @@ func (srv *Server) CmdCommit(stdin io.ReadCloser, stdout io.Writer, args ...stri
return err return err
} }
// Create a new image from the container's base layers + a new layer from container changes // Create a new image from the container's base layers + a new layer from container changes
img, err := srv.containers.graph.Create(rwTar, container.Image, "") img, err := srv.runtime.graph.Create(rwTar, container.Image, "")
if err != nil { if err != nil {
return err return err
} }
@ -563,7 +563,7 @@ func (srv *Server) CmdTar(stdin io.ReadCloser, stdout io.Writer, args ...string)
return errors.New("Sparse mode not yet implemented") // FIXME return errors.New("Sparse mode not yet implemented") // FIXME
} }
name := cmd.Arg(0) name := cmd.Arg(0)
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
if err := container.EnsureMounted(); err != nil { if err := container.EnsureMounted(); err != nil {
return err return err
} }
@ -590,7 +590,7 @@ func (srv *Server) CmdDiff(stdin io.ReadCloser, stdout io.Writer, args ...string
if cmd.NArg() < 1 { if cmd.NArg() < 1 {
return errors.New("Not enough arguments") return errors.New("Not enough arguments")
} }
if container := srv.containers.Get(cmd.Arg(0)); container == nil { if container := srv.runtime.Get(cmd.Arg(0)); container == nil {
return errors.New("No such container") return errors.New("No such container")
} else { } else {
changes, err := container.Changes() changes, err := container.Changes()
@ -614,7 +614,7 @@ func (srv *Server) CmdLogs(stdin io.ReadCloser, stdout io.Writer, args ...string
return nil return nil
} }
name := cmd.Arg(0) name := cmd.Arg(0)
if container := srv.containers.Get(name); container != nil { if container := srv.runtime.Get(name); container != nil {
log_stdout, err := container.ReadLog("stdout") log_stdout, err := container.ReadLog("stdout")
if err != nil { if err != nil {
return err return err
@ -649,7 +649,7 @@ func (srv *Server) CmdAttach(stdin io.ReadCloser, stdout io.Writer, args ...stri
return nil return nil
} }
name := cmd.Arg(0) name := cmd.Arg(0)
container := srv.containers.Get(name) container := srv.runtime.Get(name)
if container == nil { if container == nil {
return errors.New("No such container: " + name) return errors.New("No such container: " + name)
} }
@ -731,7 +731,7 @@ func (srv *Server) CmdRun(stdin io.ReadCloser, stdout io.Writer, args ...string)
} }
// Create new container // Create new container
container, err := srv.containers.Create(cmdline[0], cmdline[1:], name, container, err := srv.runtime.Create(cmdline[0], cmdline[1:], name,
&Config{ &Config{
Ports: fl_ports, Ports: fl_ports,
User: *fl_user, User: *fl_user,
@ -799,16 +799,16 @@ func NewServer() (*Server, error) {
// if err != nil { // if err != nil {
// return nil, err // return nil, err
// } // }
containers, err := New() runtime, err := New()
if err != nil { if err != nil {
return nil, err return nil, err
} }
srv := &Server{ srv := &Server{
containers: containers, runtime: runtime,
} }
return srv, nil return srv, nil
} }
type Server struct { type Server struct {
containers *Docker runtime *Runtime
} }

View file

@ -45,7 +45,7 @@ type Container struct {
stdoutLog *os.File stdoutLog *os.File
stderrLog *os.File stderrLog *os.File
runtime *Docker // FIXME: rename Docker to Runtime for clarity runtime *Runtime
} }
type Config struct { type Config struct {

View file

@ -14,15 +14,15 @@ import (
) )
func TestCommitRun(t *testing.T) { func TestCommitRun(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container1, err := docker.Create( container1, err := runtime.Create(
"/bin/sh", "/bin/sh",
[]string{"-c", "echo hello > /world"}, []string{"-c", "echo hello > /world"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
Memory: 33554432, Memory: 33554432,
}, },
@ -30,7 +30,7 @@ func TestCommitRun(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container1) defer runtime.Destroy(container1)
if container1.State.Running { if container1.State.Running {
t.Errorf("Container shouldn't be running") t.Errorf("Container shouldn't be running")
@ -46,14 +46,14 @@ func TestCommitRun(t *testing.T) {
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
img, err := docker.graph.Create(rwTar, container1.Image, "unit test commited image") img, err := runtime.graph.Create(rwTar, container1.Image, "unit test commited image")
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }
// FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world // FIXME: Make a TestCommit that stops here and check docker.root/layers/img.id/world
container2, err := docker.Create( container2, err := runtime.Create(
"cat", "cat",
[]string{"/world"}, []string{"/world"},
img.Id, img.Id,
@ -64,7 +64,7 @@ func TestCommitRun(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container2) defer runtime.Destroy(container2)
stdout, err := container2.StdoutPipe() stdout, err := container2.StdoutPipe()
stderr, err := container2.StderrPipe() stderr, err := container2.StderrPipe()
@ -82,15 +82,15 @@ func TestCommitRun(t *testing.T) {
} }
func TestRun(t *testing.T) { func TestRun(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
Memory: 33554432, Memory: 33554432,
}, },
@ -98,7 +98,7 @@ func TestRun(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
if container.State.Running { if container.State.Running {
t.Errorf("Container shouldn't be running") t.Errorf("Container shouldn't be running")
@ -112,21 +112,21 @@ func TestRun(t *testing.T) {
} }
func TestOutput(t *testing.T) { func TestOutput(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"echo", "echo",
[]string{"-n", "foobar"}, []string{"-n", "foobar"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err := container.Output() output, err := container.Output()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -137,21 +137,21 @@ func TestOutput(t *testing.T) {
} }
func TestKill(t *testing.T) { func TestKill(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"cat", "cat",
[]string{"/dev/zero"}, []string{"/dev/zero"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
if container.State.Running { if container.State.Running {
t.Errorf("Container shouldn't be running") t.Errorf("Container shouldn't be running")
@ -179,36 +179,36 @@ func TestKill(t *testing.T) {
} }
func TestExitCode(t *testing.T) { func TestExitCode(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
trueContainer, err := docker.Create( trueContainer, err := runtime.Create(
"/bin/true", "/bin/true",
[]string{""}, []string{""},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(trueContainer) defer runtime.Destroy(trueContainer)
if err := trueContainer.Run(); err != nil { if err := trueContainer.Run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
falseContainer, err := docker.Create( falseContainer, err := runtime.Create(
"/bin/false", "/bin/false",
[]string{""}, []string{""},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(falseContainer) defer runtime.Destroy(falseContainer)
if err := falseContainer.Run(); err != nil { if err := falseContainer.Run(); err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -223,21 +223,21 @@ func TestExitCode(t *testing.T) {
} }
func TestRestart(t *testing.T) { func TestRestart(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"echo", "echo",
[]string{"-n", "foobar"}, []string{"-n", "foobar"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err := container.Output() output, err := container.Output()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -257,15 +257,15 @@ func TestRestart(t *testing.T) {
} }
func TestRestartStdin(t *testing.T) { func TestRestartStdin(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"cat", "cat",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
OpenStdin: true, OpenStdin: true,
}, },
@ -273,7 +273,7 @@ func TestRestartStdin(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
stdin, err := container.StdinPipe() stdin, err := container.StdinPipe()
stdout, err := container.StdoutPipe() stdout, err := container.StdoutPipe()
@ -306,23 +306,23 @@ func TestRestartStdin(t *testing.T) {
} }
func TestUser(t *testing.T) { func TestUser(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
// Default user must be root // Default user must be root
container, err := docker.Create( container, err := runtime.Create(
"id", "id",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err := container.Output() output, err := container.Output()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -332,10 +332,10 @@ func TestUser(t *testing.T) {
} }
// Set a username // Set a username
container, err = docker.Create( container, err = runtime.Create(
"id", "id",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
User: "root", User: "root",
}, },
@ -343,7 +343,7 @@ func TestUser(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err = container.Output() output, err = container.Output()
if err != nil || container.State.ExitCode != 0 { if err != nil || container.State.ExitCode != 0 {
t.Fatal(err) t.Fatal(err)
@ -353,10 +353,10 @@ func TestUser(t *testing.T) {
} }
// Set a UID // Set a UID
container, err = docker.Create( container, err = runtime.Create(
"id", "id",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
User: "0", User: "0",
}, },
@ -364,7 +364,7 @@ func TestUser(t *testing.T) {
if err != nil || container.State.ExitCode != 0 { if err != nil || container.State.ExitCode != 0 {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err = container.Output() output, err = container.Output()
if err != nil || container.State.ExitCode != 0 { if err != nil || container.State.ExitCode != 0 {
t.Fatal(err) t.Fatal(err)
@ -374,10 +374,10 @@ func TestUser(t *testing.T) {
} }
// Set a different user by uid // Set a different user by uid
container, err = docker.Create( container, err = runtime.Create(
"id", "id",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
User: "1", User: "1",
}, },
@ -385,7 +385,7 @@ func TestUser(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err = container.Output() output, err = container.Output()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -397,10 +397,10 @@ func TestUser(t *testing.T) {
} }
// Set a different user by username // Set a different user by username
container, err = docker.Create( container, err = runtime.Create(
"id", "id",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
User: "daemon", User: "daemon",
}, },
@ -408,7 +408,7 @@ func TestUser(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err = container.Output() output, err = container.Output()
if err != nil || container.State.ExitCode != 0 { if err != nil || container.State.ExitCode != 0 {
t.Fatal(err) t.Fatal(err)
@ -419,33 +419,33 @@ func TestUser(t *testing.T) {
} }
func TestMultipleContainers(t *testing.T) { func TestMultipleContainers(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container1, err := docker.Create( container1, err := runtime.Create(
"cat", "cat",
[]string{"/dev/zero"}, []string{"/dev/zero"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container1) defer runtime.Destroy(container1)
container2, err := docker.Create( container2, err := runtime.Create(
"cat", "cat",
[]string{"/dev/zero"}, []string{"/dev/zero"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container2) defer runtime.Destroy(container2)
// Start both containers // Start both containers
if err := container1.Start(); err != nil { if err := container1.Start(); err != nil {
@ -474,15 +474,15 @@ func TestMultipleContainers(t *testing.T) {
} }
func TestStdin(t *testing.T) { func TestStdin(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"cat", "cat",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
OpenStdin: true, OpenStdin: true,
}, },
@ -490,7 +490,7 @@ func TestStdin(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
stdin, err := container.StdinPipe() stdin, err := container.StdinPipe()
stdout, err := container.StdoutPipe() stdout, err := container.StdoutPipe()
@ -509,15 +509,15 @@ func TestStdin(t *testing.T) {
} }
func TestTty(t *testing.T) { func TestTty(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"cat", "cat",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
OpenStdin: true, OpenStdin: true,
}, },
@ -525,7 +525,7 @@ func TestTty(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
stdin, err := container.StdinPipe() stdin, err := container.StdinPipe()
stdout, err := container.StdoutPipe() stdout, err := container.StdoutPipe()
@ -544,21 +544,21 @@ func TestTty(t *testing.T) {
} }
func TestEnv(t *testing.T) { func TestEnv(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"/usr/bin/env", "/usr/bin/env",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
stdout, err := container.StdoutPipe() stdout, err := container.StdoutPipe()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
@ -613,20 +613,20 @@ func grepFile(t *testing.T, path string, pattern string) {
} }
func TestLXCConfig(t *testing.T) { func TestLXCConfig(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
// Memory is allocated randomly for testing // Memory is allocated randomly for testing
rand.Seed(time.Now().UTC().UnixNano()) rand.Seed(time.Now().UTC().UnixNano())
memMin := 33554432 memMin := 33554432
memMax := 536870912 memMax := 536870912
mem := memMin + rand.Intn(memMax-memMin) mem := memMin + rand.Intn(memMax-memMin)
container, err := docker.Create( container, err := runtime.Create(
"/bin/true", "/bin/true",
[]string{}, []string{},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{ &Config{
Hostname: "foobar", Hostname: "foobar",
Memory: int64(mem), Memory: int64(mem),
@ -635,7 +635,7 @@ func TestLXCConfig(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
container.generateLXCConfig() container.generateLXCConfig()
grepFile(t, container.lxcConfigPath(), "lxc.utsname = foobar") grepFile(t, container.lxcConfigPath(), "lxc.utsname = foobar")
grepFile(t, container.lxcConfigPath(), grepFile(t, container.lxcConfigPath(),
@ -645,22 +645,22 @@ func TestLXCConfig(t *testing.T) {
} }
func BenchmarkRunSequencial(b *testing.B) { func BenchmarkRunSequencial(b *testing.B) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
container, err := docker.Create( container, err := runtime.Create(
"echo", "echo",
[]string{"-n", "foo"}, []string{"-n", "foo"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
output, err := container.Output() output, err := container.Output()
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
@ -668,18 +668,18 @@ func BenchmarkRunSequencial(b *testing.B) {
if string(output) != "foo" { if string(output) != "foo" {
b.Fatalf("Unexecpted output: %v", string(output)) b.Fatalf("Unexecpted output: %v", string(output))
} }
if err := docker.Destroy(container); err != nil { if err := runtime.Destroy(container); err != nil {
b.Fatal(err) b.Fatal(err)
} }
} }
} }
func BenchmarkRunParallel(b *testing.B) { func BenchmarkRunParallel(b *testing.B) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
var tasks []chan error var tasks []chan error
@ -687,17 +687,17 @@ func BenchmarkRunParallel(b *testing.B) {
complete := make(chan error) complete := make(chan error)
tasks = append(tasks, complete) tasks = append(tasks, complete)
go func(i int, complete chan error) { go func(i int, complete chan error) {
container, err := docker.Create( container, err := runtime.Create(
"echo", "echo",
[]string{"-n", "foo"}, []string{"-n", "foo"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
complete <- err complete <- err
return return
} }
defer docker.Destroy(container) defer runtime.Destroy(container)
if err := container.Start(); err != nil { if err := container.Start(); err != nil {
complete <- err complete <- err
return return
@ -709,7 +709,7 @@ func BenchmarkRunParallel(b *testing.B) {
// if string(output) != "foo" { // if string(output) != "foo" {
// complete <- fmt.Errorf("Unexecpted output: %v", string(output)) // complete <- fmt.Errorf("Unexecpted output: %v", string(output))
// } // }
if err := docker.Destroy(container); err != nil { if err := runtime.Destroy(container); err != nil {
complete <- err complete <- err
return return
} }

View file

@ -14,7 +14,7 @@ import (
"time" "time"
) )
type Docker struct { type Runtime struct {
root string root string
repository string repository string
containers *list.List containers *list.List
@ -28,16 +28,16 @@ func init() {
sysInitPath = SelfPath() sysInitPath = SelfPath()
} }
func (docker *Docker) List() []*Container { func (runtime *Runtime) List() []*Container {
containers := new(History) containers := new(History)
for e := docker.containers.Front(); e != nil; e = e.Next() { for e := runtime.containers.Front(); e != nil; e = e.Next() {
containers.Add(e.Value.(*Container)) containers.Add(e.Value.(*Container))
} }
return *containers return *containers
} }
func (docker *Docker) getContainerElement(id string) *list.Element { func (runtime *Runtime) getContainerElement(id string) *list.Element {
for e := docker.containers.Front(); e != nil; e = e.Next() { for e := runtime.containers.Front(); e != nil; e = e.Next() {
container := e.Value.(*Container) container := e.Value.(*Container)
if container.Id == id { if container.Id == id {
return e return e
@ -46,23 +46,23 @@ func (docker *Docker) getContainerElement(id string) *list.Element {
return nil return nil
} }
func (docker *Docker) Get(id string) *Container { func (runtime *Runtime) Get(id string) *Container {
e := docker.getContainerElement(id) e := runtime.getContainerElement(id)
if e == nil { if e == nil {
return nil return nil
} }
return e.Value.(*Container) return e.Value.(*Container)
} }
func (docker *Docker) Exists(id string) bool { func (runtime *Runtime) Exists(id string) bool {
return docker.Get(id) != nil return runtime.Get(id) != nil
} }
func (docker *Docker) containerRoot(id string) string { func (runtime *Runtime) containerRoot(id string) string {
return path.Join(docker.repository, id) return path.Join(runtime.repository, id)
} }
func (docker *Docker) Create(command string, args []string, image string, config *Config) (*Container, error) { func (runtime *Runtime) Create(command string, args []string, image string, config *Config) (*Container, error) {
container := &Container{ container := &Container{
// FIXME: we should generate the ID here instead of receiving it as an argument // FIXME: we should generate the ID here instead of receiving it as an argument
Id: GenerateId(), Id: GenerateId(),
@ -75,7 +75,7 @@ func (docker *Docker) Create(command string, args []string, image string, config
// FIXME: do we need to store this in the container? // FIXME: do we need to store this in the container?
SysInitPath: sysInitPath, SysInitPath: sysInitPath,
} }
container.root = docker.containerRoot(container.Id) container.root = runtime.containerRoot(container.Id)
// Step 1: create the container directory. // Step 1: create the container directory.
// This doubles as a barrier to avoid race conditions. // This doubles as a barrier to avoid race conditions.
if err := os.Mkdir(container.root, 0700); err != nil { if err := os.Mkdir(container.root, 0700); err != nil {
@ -86,36 +86,36 @@ func (docker *Docker) Create(command string, args []string, image string, config
return nil, err return nil, err
} }
// Step 3: register the container // Step 3: register the container
if err := docker.Register(container); err != nil { if err := runtime.Register(container); err != nil {
return nil, err return nil, err
} }
return container, nil return container, nil
} }
func (docker *Docker) Load(id string) (*Container, error) { func (runtime *Runtime) Load(id string) (*Container, error) {
container := &Container{root: docker.containerRoot(id)} container := &Container{root: runtime.containerRoot(id)}
if err := container.FromDisk(); err != nil { if err := container.FromDisk(); err != nil {
return nil, err return nil, err
} }
if container.Id != id { if container.Id != id {
return container, fmt.Errorf("Container %s is stored at %s", container.Id, id) return container, fmt.Errorf("Container %s is stored at %s", container.Id, id)
} }
if err := docker.Register(container); err != nil { if err := runtime.Register(container); err != nil {
return nil, err return nil, err
} }
return container, nil return container, nil
} }
// Register makes a container object usable by the runtime as <container.Id> // Register makes a container object usable by the runtime as <container.Id>
func (docker *Docker) Register(container *Container) error { func (runtime *Runtime) Register(container *Container) error {
if container.runtime != nil || docker.Exists(container.Id) { if container.runtime != nil || runtime.Exists(container.Id) {
return fmt.Errorf("Container is already loaded") return fmt.Errorf("Container is already loaded")
} }
if err := validateId(container.Id); err != nil { if err := validateId(container.Id); err != nil {
return err return err
} }
container.runtime = docker container.runtime = runtime
container.networkManager = docker.networkManager // FIXME: infer from docker.runtime container.networkManager = runtime.networkManager // FIXME: infer from docker.runtime
// Setup state lock (formerly in newState() // Setup state lock (formerly in newState()
lock := new(sync.Mutex) lock := new(sync.Mutex)
container.State.stateChangeLock = lock container.State.stateChangeLock = lock
@ -130,18 +130,18 @@ func (docker *Docker) Register(container *Container) error {
container.stdinPipe = NopWriteCloser(ioutil.Discard) // Silently drop stdin container.stdinPipe = NopWriteCloser(ioutil.Discard) // Silently drop stdin
} }
// Setup logging of stdout and stderr to disk // Setup logging of stdout and stderr to disk
if err := docker.LogToDisk(container.stdout, container.logPath("stdout")); err != nil { if err := runtime.LogToDisk(container.stdout, container.logPath("stdout")); err != nil {
return err return err
} }
if err := docker.LogToDisk(container.stderr, container.logPath("stderr")); err != nil { if err := runtime.LogToDisk(container.stderr, container.logPath("stderr")); err != nil {
return err return err
} }
// done // done
docker.containers.PushBack(container) runtime.containers.PushBack(container)
return nil return nil
} }
func (docker *Docker) LogToDisk(src *writeBroadcaster, dst string) error { func (runtime *Runtime) LogToDisk(src *writeBroadcaster, dst string) error {
log, err := os.OpenFile(dst, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600) log, err := os.OpenFile(dst, os.O_RDWR|os.O_APPEND|os.O_CREATE, 0600)
if err != nil { if err != nil {
return err return err
@ -150,8 +150,8 @@ func (docker *Docker) LogToDisk(src *writeBroadcaster, dst string) error {
return nil return nil
} }
func (docker *Docker) Destroy(container *Container) error { func (runtime *Runtime) Destroy(container *Container) error {
element := docker.getContainerElement(container.Id) element := runtime.getContainerElement(container.Id)
if element == nil { if element == nil {
return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id) return fmt.Errorf("Container %v not found - maybe it was already destroyed?", container.Id)
} }
@ -167,21 +167,21 @@ func (docker *Docker) Destroy(container *Container) error {
} }
} }
// Deregister the container before removing its directory, to avoid race conditions // Deregister the container before removing its directory, to avoid race conditions
docker.containers.Remove(element) runtime.containers.Remove(element)
if err := os.RemoveAll(container.root); err != nil { if err := os.RemoveAll(container.root); err != nil {
return fmt.Errorf("Unable to remove filesystem for %v: %v", container.Id, err) return fmt.Errorf("Unable to remove filesystem for %v: %v", container.Id, err)
} }
return nil return nil
} }
func (docker *Docker) restore() error { func (runtime *Runtime) restore() error {
dir, err := ioutil.ReadDir(docker.repository) dir, err := ioutil.ReadDir(runtime.repository)
if err != nil { if err != nil {
return err return err
} }
for _, v := range dir { for _, v := range dir {
id := v.Name() id := v.Name()
container, err := docker.Load(id) container, err := runtime.Load(id)
if err != nil { if err != nil {
log.Printf("Failed to load container %v: %v", id, err) log.Printf("Failed to load container %v: %v", id, err)
continue continue
@ -191,14 +191,14 @@ func (docker *Docker) restore() error {
return nil return nil
} }
func New() (*Docker, error) { func New() (*Runtime, error) {
return NewFromDirectory("/var/lib/docker") return NewFromDirectory("/var/lib/docker")
} }
func NewFromDirectory(root string) (*Docker, error) { func NewFromDirectory(root string) (*Runtime, error) {
docker_repo := path.Join(root, "containers") runtime_repo := path.Join(root, "containers")
if err := os.MkdirAll(docker_repo, 0700); err != nil && !os.IsExist(err) { if err := os.MkdirAll(runtime_repo, 0700); err != nil && !os.IsExist(err) {
return nil, err return nil, err
} }
@ -211,18 +211,18 @@ func NewFromDirectory(root string) (*Docker, error) {
return nil, err return nil, err
} }
docker := &Docker{ runtime := &Runtime{
root: root, root: root,
repository: docker_repo, repository: runtime_repo,
containers: list.New(), containers: list.New(),
networkManager: netManager, networkManager: netManager,
graph: graph, graph: graph,
} }
if err := docker.restore(); err != nil { if err := runtime.restore(); err != nil {
return nil, err return nil, err
} }
return docker, nil return runtime, nil
} }
type History []*Container type History []*Container

View file

@ -16,8 +16,8 @@ const unitTestImageName string = "busybox"
var unitTestStoreBase string var unitTestStoreBase string
var srv *Server var srv *Server
func nuke(docker *Docker) error { func nuke(runtime *Runtime) error {
return os.RemoveAll(docker.root) return os.RemoveAll(runtime.root)
} }
func CopyDirectory(source, dest string) error { func CopyDirectory(source, dest string) error {
@ -57,13 +57,13 @@ func init() {
unitTestStoreBase = root unitTestStoreBase = root
// Make it our Store root // Make it our Store root
docker, err := NewFromDirectory(root) runtime, err := NewFromDirectory(root)
if err != nil { if err != nil {
panic(err) panic(err)
} }
// Create the "Server" // Create the "Server"
srv := &Server{ srv := &Server{
containers: docker, runtime: runtime,
} }
// Retrieve the Image // Retrieve the Image
if err := srv.CmdImport(os.Stdin, os.Stdout, unitTestImageName); err != nil { if err := srv.CmdImport(os.Stdin, os.Stdout, unitTestImageName); err != nil {
@ -71,7 +71,7 @@ func init() {
} }
} }
func newTestDocker() (*Docker, error) { func newTestRuntime() (*Runtime, error) {
root, err := ioutil.TempDir("", "docker-test") root, err := ioutil.TempDir("", "docker-test")
if err != nil { if err != nil {
return nil, err return nil, err
@ -84,16 +84,16 @@ func newTestDocker() (*Docker, error) {
return nil, err return nil, err
} }
docker, err := NewFromDirectory(root) runtime, err := NewFromDirectory(root)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return docker, nil return runtime, nil
} }
func GetTestImage(docker *Docker) *graph.Image { func GetTestImage(runtime *Runtime) *graph.Image {
imgs, err := docker.graph.All() imgs, err := runtime.graph.All()
if err != nil { if err != nil {
panic(err) panic(err)
} else if len(imgs) < 1 { } else if len(imgs) < 1 {
@ -103,20 +103,20 @@ func GetTestImage(docker *Docker) *graph.Image {
} }
func TestCreate(t *testing.T) { func TestCreate(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
// Make sure we start we 0 containers // Make sure we start we 0 containers
if len(docker.List()) != 0 { if len(runtime.List()) != 0 {
t.Errorf("Expected 0 containers, %v found", len(docker.List())) t.Errorf("Expected 0 containers, %v found", len(runtime.List()))
} }
container, err := docker.Create( container, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
@ -124,69 +124,69 @@ func TestCreate(t *testing.T) {
} }
defer func() { defer func() {
if err := docker.Destroy(container); err != nil { if err := runtime.Destroy(container); err != nil {
t.Error(err) t.Error(err)
} }
}() }()
// Make sure we can find the newly created container with List() // Make sure we can find the newly created container with List()
if len(docker.List()) != 1 { if len(runtime.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker.List())) t.Errorf("Expected 1 container, %v found", len(runtime.List()))
} }
// Make sure the container List() returns is the right one // Make sure the container List() returns is the right one
if docker.List()[0].Id != container.Id { if runtime.List()[0].Id != container.Id {
t.Errorf("Unexpected container %v returned by List", docker.List()[0]) t.Errorf("Unexpected container %v returned by List", runtime.List()[0])
} }
// Make sure we can get the container with Get() // Make sure we can get the container with Get()
if docker.Get(container.Id) == nil { if runtime.Get(container.Id) == nil {
t.Errorf("Unable to get newly created container") t.Errorf("Unable to get newly created container")
} }
// Make sure it is the right container // Make sure it is the right container
if docker.Get(container.Id) != container { if runtime.Get(container.Id) != container {
t.Errorf("Get() returned the wrong container") t.Errorf("Get() returned the wrong container")
} }
// Make sure Exists returns it as existing // Make sure Exists returns it as existing
if !docker.Exists(container.Id) { if !runtime.Exists(container.Id) {
t.Errorf("Exists() returned false for a newly created container") t.Errorf("Exists() returned false for a newly created container")
} }
} }
func TestDestroy(t *testing.T) { func TestDestroy(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container, err := docker.Create( container, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Destroy // Destroy
if err := docker.Destroy(container); err != nil { if err := runtime.Destroy(container); err != nil {
t.Error(err) t.Error(err)
} }
// Make sure docker.Exists() behaves correctly // Make sure runtime.Exists() behaves correctly
if docker.Exists("test_destroy") { if runtime.Exists("test_destroy") {
t.Errorf("Exists() returned true") t.Errorf("Exists() returned true")
} }
// Make sure docker.List() doesn't list the destroyed container // Make sure runtime.List() doesn't list the destroyed container
if len(docker.List()) != 0 { if len(runtime.List()) != 0 {
t.Errorf("Expected 0 container, %v found", len(docker.List())) t.Errorf("Expected 0 container, %v found", len(runtime.List()))
} }
// Make sure docker.Get() refuses to return the unexisting container // Make sure runtime.Get() refuses to return the unexisting container
if docker.Get(container.Id) != nil { if runtime.Get(container.Id) != nil {
t.Errorf("Unable to get newly created container") t.Errorf("Unable to get newly created container")
} }
@ -197,61 +197,61 @@ func TestDestroy(t *testing.T) {
} }
// Test double destroy // Test double destroy
if err := docker.Destroy(container); err == nil { if err := runtime.Destroy(container); err == nil {
// It should have failed // It should have failed
t.Errorf("Double destroy did not fail") t.Errorf("Double destroy did not fail")
} }
} }
func TestGet(t *testing.T) { func TestGet(t *testing.T) {
docker, err := newTestDocker() runtime, err := newTestRuntime()
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker) defer nuke(runtime)
container1, err := docker.Create( container1, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container1) defer runtime.Destroy(container1)
container2, err := docker.Create( container2, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container2) defer runtime.Destroy(container2)
container3, err := docker.Create( container3, err := runtime.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker).Id, GetTestImage(runtime).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker.Destroy(container3) defer runtime.Destroy(container3)
if docker.Get(container1.Id) != container1 { if runtime.Get(container1.Id) != container1 {
t.Errorf("Get(test1) returned %v while expecting %v", docker.Get(container1.Id), container1) t.Errorf("Get(test1) returned %v while expecting %v", runtime.Get(container1.Id), container1)
} }
if docker.Get(container2.Id) != container2 { if runtime.Get(container2.Id) != container2 {
t.Errorf("Get(test2) returned %v while expecting %v", docker.Get(container2.Id), container2) t.Errorf("Get(test2) returned %v while expecting %v", runtime.Get(container2.Id), container2)
} }
if docker.Get(container3.Id) != container3 { if runtime.Get(container3.Id) != container3 {
t.Errorf("Get(test3) returned %v while expecting %v", docker.Get(container3.Id), container3) t.Errorf("Get(test3) returned %v while expecting %v", runtime.Get(container3.Id), container3)
} }
} }
@ -269,24 +269,24 @@ func TestRestore(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
docker1, err := NewFromDirectory(root) runtime1, err := NewFromDirectory(root)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
// Create a container with one instance of docker // Create a container with one instance of docker
container1, err := docker1.Create( container1, err := runtime1.Create(
"ls", "ls",
[]string{"-al"}, []string{"-al"},
GetTestImage(docker1).Id, GetTestImage(runtime1).Id,
&Config{}, &Config{},
) )
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer docker1.Destroy(container1) defer runtime1.Destroy(container1)
if len(docker1.List()) != 1 { if len(runtime1.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker1.List())) t.Errorf("Expected 1 container, %v found", len(runtime1.List()))
} }
if err := container1.Run(); err != nil { if err := container1.Run(); err != nil {
t.Fatal(err) t.Fatal(err)
@ -294,15 +294,15 @@ func TestRestore(t *testing.T) {
// Here are are simulating a docker restart - that is, reloading all containers // Here are are simulating a docker restart - that is, reloading all containers
// from scratch // from scratch
docker2, err := NewFromDirectory(root) runtime2, err := NewFromDirectory(root)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer nuke(docker2) defer nuke(runtime2)
if len(docker2.List()) != 1 { if len(runtime2.List()) != 1 {
t.Errorf("Expected 1 container, %v found", len(docker2.List())) t.Errorf("Expected 1 container, %v found", len(runtime2.List()))
} }
container2 := docker2.Get(container1.Id) container2 := runtime2.Get(container1.Id)
if container2 == nil { if container2 == nil {
t.Fatal("Unable to Get container") t.Fatal("Unable to Get container")
} }