示例#1
0
func TestManager(t *testing.T) {
	testManager := NewManager("unix:///var/run/docker.sock", utils.LocalDir("images"), "/tmp")

	if err := testManager.Stop(); err != ErrManagerNotRunning {
		t.Logf("expected an error got %s", err)
		t.Fail()
	}

	if err := testManager.Start(); err != nil {
		t.Logf("expected no error got %s", err)
		t.Fail()
	}

	cd1 := ContainerDescription{
		Name:    "test1",
		Repo:    "ubuntu",
		Tag:     "latest",
		Command: func() string { return `/bin/sh -c "while true; do echo hello world; sleep 1; done"` },
	}
	container, err := NewContainer(cd1)
	if err != nil {
		t.Logf("could not create container: %s", err)
		t.Fail()
	}

	cd2 := ContainerDescription{
		Name:    "test2",
		Repo:    "ubuntu",
		Tag:     "latest",
		Command: func() string { return `/bin/sh -c "while true; do echo hello world; sleep 1; done"` },
	}
	container2, err := NewContainer(cd2)
	if err != nil {
		t.Logf("could not create container: %s", err)
		t.Fail()
	}

	if err := testManager.Stop(); err != nil {
		t.Logf("expected no error got %s", err)
		t.Fail()
	}

	if err := testManager.Register(container); err != nil {
		t.Logf("expected nil got %s", err)
		t.Fatal()
	}

	if err := testManager.Register(container2); err != nil {
		t.Logf("expected nil got %s", err)
		t.Fatal()
	}

	if err := testManager.Start(); err != nil {
		t.Logf("expected no error got %s", err)
		t.Fail()
	}
	time.Sleep(time.Second * 10)

	testManager.Stop()
}
示例#2
0
func (d *daemon) addTemplates() {
	root := utils.LocalDir("templates")
	glog.V(1).Infof("Adding templates from %s", root)
	// Don't block startup for this. It's merely a convenience.
	go func() {
		err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
			if err != nil {
				return err
			}
			if info == nil || !strings.HasSuffix(info.Name(), ".json") {
				return nil
			}
			if info.IsDir() {
				return filepath.SkipDir
			}
			var reader io.ReadCloser
			if reader, err = os.Open(path); err != nil {
				glog.Warningf("Unable to open template %s", path)
				return nil
			}
			defer reader.Close()
			st := servicetemplate.ServiceTemplate{}
			if err := json.NewDecoder(reader).Decode(&st); err != nil {
				glog.Warningf("Unable to parse template file %s", path)
				return nil
			}
			glog.V(1).Infof("Adding service template %s", path)
			d.facade.AddServiceTemplate(d.dsContext, st)
			return nil
		})
		if err != nil {
			glog.Warningf("Not loading templates from %s: %s", root, err)
		}
	}()
}
示例#3
0
func (t *ManagerTestSuite) SetUpSuite(c *C) {
	t.manager = NewManager(utils.LocalDir("images"), "/tmp/serviced-test")
	for _, testservice := range t.testservices {
		svc := testservice.GetService(c)
		if err := t.manager.Register(svc); err != nil {
			c.Fatalf("Could not register %s: %s", svc.Name, err)
		}
	}
	t.manager.Wipe()
	if err := t.manager.Start(); err != nil {
		c.Fatalf("Could not start isvcs: %s", err)
	}

	for _, testservice := range t.testservices {
		testservice.Create(c)
	}
}