本文整理匯總了Golang中github.com/fsouza/go-dockerclient/testing.NewServer函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewServer函數的具體用法?Golang NewServer怎麽用?Golang NewServer使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewServer函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestProject_ListContainers
func (s *CoreSuite) TestProject_ListContainers(c *C) {
mA, _ := testing.NewServer("127.0.0.1:0", nil, nil)
mB, _ := testing.NewServer("127.0.0.1:0", nil, nil)
envs := map[string]*Environment{
"a": &Environment{Name: "a", DockerEndPoints: []string{mA.URL()}},
"b": &Environment{Name: "b", DockerEndPoints: []string{mB.URL()}},
}
p := &Project{
Name: "foo",
Repository: "[email protected]:foo/bar.git",
Environments: envs,
}
input := bytes.NewBuffer(nil)
da, _ := NewDocker(envs["a"].DockerEndPoints[0], nil)
da.Deploy(p, Revision{}, &Dockerfile{}, input, false)
db, _ := NewDocker(envs["b"].DockerEndPoints[0], nil)
db.Deploy(p, Revision{}, &Dockerfile{}, input, false)
time.Sleep(1 * time.Second)
l, err := p.ListContainers()
c.Assert(err, HasLen, 0)
c.Assert(l, HasLen, 2)
c.Assert(l[0].APIContainers.Names[0], Equals, "/foo")
c.Assert(l[1].APIContainers.Names[0], Equals, "/foo")
}
示例2: TestListImagesErrors
func TestListImagesErrors(t *testing.T) {
server1, err := dtesting.NewServer("127.0.0.1:0", nil, nil)
if err != nil {
t.Fatal(err)
}
defer server1.Stop()
server2, err := dtesting.NewServer("127.0.0.1:0", nil, nil)
if err != nil {
t.Fatal(err)
}
defer server2.Stop()
cluster, err := New(nil, &MapStorage{},
Node{Address: server1.URL()},
Node{Address: server2.URL()},
)
if err != nil {
t.Fatal(err)
}
opts := docker.PullImageOptions{Repository: "tsuru/python1"}
err = cluster.PullImage(opts, docker.AuthConfiguration{}, server1.URL())
if err != nil {
t.Error(err)
}
opts = docker.PullImageOptions{Repository: "tsuru/python2"}
err = cluster.PullImage(opts, docker.AuthConfiguration{}, server2.URL())
if err != nil {
t.Error(err)
}
server2.PrepareFailure("list-images-error", "/images/json")
defer server2.ResetFailure("list-images-error")
_, err = cluster.ListImages(docker.ListImagesOptions{All: true})
if err == nil {
t.Fatal("Expected error to exist, got <nil>")
}
}
示例3: TestProject_Status
func (s *CoreSuite) TestProject_Status(c *C) {
if !*githubFlag {
c.Skip("--github not provided")
}
mA, _ := testing.NewServer("127.0.0.1:0", nil, nil)
mB, _ := testing.NewServer("127.0.0.1:0", nil, nil)
envs := map[string]*Environment{
"a": &Environment{Name: "a", DockerEndPoints: []string{mA.URL()}},
"b": &Environment{Name: "b", DockerEndPoints: []string{mB.URL()}},
}
p := &Project{
Name: "foo",
Repository: "[email protected]:mcuadros/cli-array-editor.git",
GithubToken: githubToken,
Environments: envs,
Dockerfile: ".gitignore",
}
input := bytes.NewBuffer(nil)
da, _ := NewDocker(envs["a"].DockerEndPoints[0], nil)
da.Deploy(p, Revision{}, &Dockerfile{}, input, false)
db, _ := NewDocker(envs["b"].DockerEndPoints[0], nil)
db.Deploy(p, Revision{}, &Dockerfile{}, input, false)
r, err := p.Status()
c.Assert(err, HasLen, 0)
c.Assert(r, HasLen, 2)
c.Assert(r[0].Environment, Equals, envs["a"])
c.Assert(r[0].LastRevision.GetShort(), Equals, "a44ffbb10515")
c.Assert(r[0].Containers, HasLen, 1)
c.Assert(r[0].RunningContainers, HasLen, 1)
c.Assert(r[0].Containers[0], Equals, r[0].RunningContainers[0])
}
示例4: TestSchedulerSchedule
func (s *SchedulerSuite) TestSchedulerSchedule(c *gocheck.C) {
server0, err := testing.NewServer(nil)
c.Assert(err, gocheck.IsNil)
defer server0.Stop()
server1, err := testing.NewServer(nil)
c.Assert(err, gocheck.IsNil)
defer server1.Stop()
server2, err := testing.NewServer(nil)
c.Assert(err, gocheck.IsNil)
defer server2.Stop()
var buf bytes.Buffer
client, _ := docker.NewClient(server0.URL())
client.PullImage(docker.PullImageOptions{Repository: "tsuru/python", OutputStream: &buf})
client, _ = docker.NewClient(server1.URL())
client.PullImage(docker.PullImageOptions{Repository: "tsuru/python", OutputStream: &buf})
client, _ = docker.NewClient(server2.URL())
client.PullImage(docker.PullImageOptions{Repository: "tsuru/python", OutputStream: &buf})
a1 := app.App{Name: "impius", Teams: []string{"tsuruteam", "nodockerforme"}}
a2 := app.App{Name: "mirror", Teams: []string{"tsuruteam"}}
a3 := app.App{Name: "dedication", Teams: []string{"nodockerforme"}}
cont1 := container{ID: "1", Name: "impius1", AppName: a1.Name}
cont2 := container{ID: "2", Name: "mirror1", AppName: a2.Name}
cont3 := container{ID: "3", Name: "dedication1", AppName: a3.Name}
err = s.storage.Apps().Insert(a1, a2, a3)
c.Assert(err, gocheck.IsNil)
defer s.storage.Apps().RemoveAll(bson.M{"name": bson.M{"$in": []string{a1.Name, a2.Name, a3.Name}}})
coll := s.storage.Collection(schedulerCollection)
err = coll.Insert(
node{ID: "server0", Address: server0.URL(), Teams: []string{"tsuruteam"}},
node{ID: "server1", Address: server1.URL(), Teams: []string{"tsuruteam"}},
node{ID: "server2", Address: server2.URL()},
)
c.Assert(err, gocheck.IsNil)
defer coll.RemoveAll(bson.M{"_id": bson.M{"$in": []string{"server0", "server1", "server2"}}})
contColl := collection()
err = contColl.Insert(
cont1, cont2, cont3,
)
c.Assert(err, gocheck.IsNil)
defer contColl.RemoveAll(bson.M{"name": bson.M{"$in": []string{cont1.Name, cont2.Name, cont3.Name}}})
var scheduler segregatedScheduler
config := docker.Config{Cmd: []string{"/usr/sbin/sshd", "-D"}, Image: "tsuru/python"}
opts := docker.CreateContainerOptions{Name: cont1.Name, Config: &config}
node, _, err := scheduler.Schedule(opts)
c.Assert(err, gocheck.IsNil)
c.Check(node, gocheck.Equals, "server1")
config = docker.Config{Cmd: []string{"/usr/sbin/sshd", "-D"}, Image: "tsuru/python"}
opts = docker.CreateContainerOptions{Name: cont2.Name, Config: &config}
node, _, err = scheduler.Schedule(opts)
c.Assert(err, gocheck.IsNil)
c.Check(node == "server0" || node == "server1", gocheck.Equals, true)
config = docker.Config{Cmd: []string{"/usr/sbin/sshd", "-D"}, Image: "tsuru/python"}
opts = docker.CreateContainerOptions{Name: cont3.Name, Config: &config}
node, _, err = scheduler.Schedule(opts)
c.Assert(err, gocheck.IsNil)
c.Check(node, gocheck.Equals, "server2")
}
示例5: TestSchedulerSchedule
func (s *S) TestSchedulerSchedule(c *check.C) {
a1 := app.App{Name: "impius", Teams: []string{"tsuruteam", "nodockerforme"}, Pool: "pool1"}
a2 := app.App{Name: "mirror", Teams: []string{"tsuruteam"}, Pool: "pool1"}
a3 := app.App{Name: "dedication", Teams: []string{"nodockerforme"}, Pool: "pool1"}
cont1 := container.Container{ID: "1", Name: "impius1", AppName: a1.Name}
cont2 := container.Container{ID: "2", Name: "mirror1", AppName: a2.Name}
cont3 := container.Container{ID: "3", Name: "dedication1", AppName: a3.Name}
err := s.storage.Apps().Insert(a1, a2, a3)
c.Assert(err, check.IsNil)
defer s.storage.Apps().RemoveAll(bson.M{"name": bson.M{"$in": []string{a1.Name, a2.Name, a3.Name}}})
p := provision.Pool{Name: "pool1", Teams: []string{
"tsuruteam",
"nodockerforme",
}}
o := provision.AddPoolOptions{Name: p.Name}
err = provision.AddPool(o)
c.Assert(err, check.IsNil)
err = provision.AddTeamsToPool(p.Name, p.Teams)
c.Assert(err, check.IsNil)
defer provision.RemovePool(p.Name)
contColl := s.p.Collection()
defer contColl.Close()
err = contColl.Insert(
cont1, cont2, cont3,
)
c.Assert(err, check.IsNil)
defer contColl.RemoveAll(bson.M{"name": bson.M{"$in": []string{cont1.Name, cont2.Name, cont3.Name}}})
scheduler := segregatedScheduler{provisioner: s.p}
clusterInstance, err := cluster.New(&scheduler, &cluster.MapStorage{})
s.p.cluster = clusterInstance
c.Assert(err, check.IsNil)
server1, err := testing.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
defer server1.Stop()
server2, err := testing.NewServer("localhost:0", nil, nil)
c.Assert(err, check.IsNil)
defer server2.Stop()
err = clusterInstance.Register(cluster.Node{
Address: server1.URL(),
Metadata: map[string]string{"pool": "pool1"},
})
c.Assert(err, check.IsNil)
localURL := strings.Replace(server2.URL(), "127.0.0.1", "localhost", -1)
err = clusterInstance.Register(cluster.Node{
Address: localURL,
Metadata: map[string]string{"pool": "pool1"},
})
c.Assert(err, check.IsNil)
opts := docker.CreateContainerOptions{Name: cont1.Name}
node, err := scheduler.Schedule(clusterInstance, opts, &container.SchedulerOpts{AppName: a1.Name, ProcessName: "web"})
c.Assert(err, check.IsNil)
c.Check(node.Address, check.Equals, server1.URL())
opts = docker.CreateContainerOptions{Name: cont2.Name}
node, err = scheduler.Schedule(clusterInstance, opts, &container.SchedulerOpts{AppName: a2.Name, ProcessName: "web"})
c.Assert(err, check.IsNil)
c.Check(node.Address, check.Equals, localURL)
}
示例6: TestHealerHealNodeWaitAndRegisterError
func (s *S) TestHealerHealNodeWaitAndRegisterError(c *check.C) {
defer func() {
machines, _ := iaas.ListMachines()
for _, m := range machines {
m.Destroy()
}
}()
iaas.RegisterIaasProvider("my-healer-iaas", newHealerIaaSConstructor("127.0.0.1", nil))
_, err := iaas.CreateMachineForIaaS("my-healer-iaas", map[string]string{})
c.Assert(err, check.IsNil)
iaas.RegisterIaasProvider("my-healer-iaas", newHealerIaaSConstructor("localhost", nil))
node1, err := testing.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
node2, err := testing.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
node2.PrepareFailure("ping-failure", "/_ping")
config.Set("iaas:node-protocol", "http")
config.Set("iaas:node-port", urlPort(node2.URL()))
defer config.Unset("iaas:node-protocol")
defer config.Unset("iaas:node-port")
cluster, err := cluster.New(nil, &cluster.MapStorage{},
cluster.Node{Address: node1.URL()},
)
c.Assert(err, check.IsNil)
node1.PrepareFailure("pingErr", "/_ping")
cluster.StartActiveMonitoring(100 * time.Millisecond)
time.Sleep(300 * time.Millisecond)
cluster.StopActiveMonitoring()
var p dockerProvisioner
err = p.Initialize()
c.Assert(err, check.IsNil)
p.cluster = cluster
healer := nodeHealer{
locks: make(map[string]*sync.Mutex),
provisioner: &p,
disabledTime: 0,
failuresBeforeHealing: 1,
waitTimeNewMachine: 1 * time.Second,
}
nodes, err := p.getCluster().UnfilteredNodes()
c.Assert(err, check.IsNil)
c.Assert(nodes, check.HasLen, 1)
c.Assert(urlPort(nodes[0].Address), check.Equals, urlPort(node1.URL()))
c.Assert(urlToHost(nodes[0].Address), check.Equals, "127.0.0.1")
c.Assert(nodes[0].FailureCount() > 0, check.Equals, true)
nodes[0].Metadata["iaas"] = "my-healer-iaas"
created, err := healer.healNode(&nodes[0])
c.Assert(err, check.ErrorMatches, ".*error registering new node.*")
c.Assert(created.Address, check.Equals, "")
c.Assert(nodes[0].FailureCount(), check.Equals, 0)
nodes, err = p.getCluster().UnfilteredNodes()
c.Assert(err, check.IsNil)
c.Assert(nodes, check.HasLen, 1)
c.Assert(urlPort(nodes[0].Address), check.Equals, urlPort(node1.URL()))
c.Assert(urlToHost(nodes[0].Address), check.Equals, "127.0.0.1")
}
示例7: SetUpTest
func (s *S) SetUpTest(c *check.C) {
config.Set("docker:api-timeout", 2)
iaas.ResetAll()
repositorytest.Reset()
queue.ResetQueue()
repository.Manager().CreateUser(s.user.Email)
s.p = &dockerProvisioner{storage: &cluster.MapStorage{}}
err := s.p.Initialize()
c.Assert(err, check.IsNil)
queue.ResetQueue()
s.server, err = dtesting.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
s.p.cluster, err = cluster.New(nil, s.p.storage,
cluster.Node{Address: s.server.URL(), Metadata: map[string]string{"pool": "test-default"}},
)
c.Assert(err, check.IsNil)
mainDockerProvisioner = s.p
err = dbtest.ClearAllCollectionsExcept(s.storage.Apps().Database, []string{"users", "tokens", "teams"})
c.Assert(err, check.IsNil)
err = clearClusterStorage(s.clusterSess)
c.Assert(err, check.IsNil)
routertest.FakeRouter.Reset()
opts := provision.AddPoolOptions{Name: "test-default", Default: true}
err = provision.AddPool(opts)
c.Assert(err, check.IsNil)
s.storage.Tokens().Remove(bson.M{"appname": bson.M{"$ne": ""}})
s.logBuf = safe.NewBuffer(nil)
log.SetLogger(log.NewWriterLogger(s.logBuf, true))
s.token = createTokenForUser(s.user, "*", string(permission.CtxGlobal), "", c)
}
示例8: SetUpTest
func (s *S) SetUpTest(c *check.C) {
iaas.ResetAll()
repositorytest.Reset()
queue.ResetQueue()
s.p = &dockerProvisioner{storage: &cluster.MapStorage{}}
err := s.p.Initialize()
c.Assert(err, check.IsNil)
queue.ResetQueue()
app.Provisioner = s.p
s.server, err = dtesting.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
s.p.cluster, err = cluster.New(nil, s.p.storage,
cluster.Node{Address: s.server.URL(), Metadata: map[string]string{"pool": "test-fallback"}},
)
c.Assert(err, check.IsNil)
mainDockerProvisioner = s.p
coll := s.p.collection()
defer coll.Close()
err = dbtest.ClearAllCollectionsExcept(coll.Database, []string{"users", "tokens", "teams"})
c.Assert(err, check.IsNil)
err = clearClusterStorage(s.clusterSess)
c.Assert(err, check.IsNil)
routertest.FakeRouter.Reset()
opts := provision.AddPoolOptions{Name: "test-fallback"}
err = provision.AddPool(opts)
c.Assert(err, check.IsNil)
}
示例9: TestReplicateImage
func (s *S) TestReplicateImage(c *gocheck.C) {
var request *http.Request
var requests int32
server, err := dtesting.NewServer(func(r *http.Request) {
v := atomic.AddInt32(&requests, 1)
if v == 2 {
request = r
}
})
c.Assert(err, gocheck.IsNil)
defer server.Stop()
config.Set("docker:registry", "localhost:3030")
defer config.Unset("docker:registry")
cmutex.Lock()
oldDockerCluster := dCluster
dCluster, _ = cluster.New(nil, storage.Redis("localhost:6379", "tests"), cluster.Node{ID: "server0", Address: server.URL()})
cmutex.Unlock()
defer func() {
cmutex.Lock()
defer cmutex.Unlock()
dCluster = oldDockerCluster
}()
err = newImage("localhost:3030/base", "http://index.docker.io")
c.Assert(err, gocheck.IsNil)
cleanup := insertImage("localhost:3030/base", "server0", c)
defer cleanup()
err = replicateImage("localhost:3030/base")
c.Assert(err, gocheck.IsNil)
c.Assert(atomic.LoadInt32(&requests), gocheck.Equals, int32(3))
c.Assert(request.URL.Path, gocheck.Matches, ".*/images/localhost:3030/base/push$")
}
示例10: TestProvisionerPlatformRemoveReturnsStorageError
func (s *S) TestProvisionerPlatformRemoveReturnsStorageError(c *gocheck.C) {
registryServer := httptest.NewServer(nil)
u, _ := url.Parse(registryServer.URL)
config.Set("docker:registry", u.Host)
defer config.Unset("docker:registry")
var requests []*http.Request
server, err := dtesting.NewServer("127.0.0.1:0", nil, func(r *http.Request) {
requests = append(requests, r)
})
c.Assert(err, gocheck.IsNil)
defer server.Stop()
var storage cluster.MapStorage
cmutex.Lock()
oldDockerCluster := dCluster
dCluster, _ = cluster.New(nil, &storage,
cluster.Node{Address: server.URL()})
cmutex.Unlock()
defer func() {
cmutex.Lock()
dCluster = oldDockerCluster
cmutex.Unlock()
}()
p := dockerProvisioner{}
err = p.PlatformRemove("test")
c.Assert(err, gocheck.NotNil)
c.Assert(err, gocheck.DeepEquals, dstorage.ErrNoSuchImage)
}
示例11: TestProvisionerPlatformRemove
func (s *S) TestProvisionerPlatformRemove(c *gocheck.C) {
registryServer := httptest.NewServer(nil)
u, _ := url.Parse(registryServer.URL)
config.Set("docker:registry", u.Host)
defer config.Unset("docker:registry")
var requests []*http.Request
server, err := dtesting.NewServer("127.0.0.1:0", nil, func(r *http.Request) {
requests = append(requests, r)
})
c.Assert(err, gocheck.IsNil)
defer server.Stop()
var storage cluster.MapStorage
imageName := assembleImageName("test")
storage.StoreImage(imageName, server.URL())
cmutex.Lock()
oldDockerCluster := dCluster
dCluster, _ = cluster.New(nil, &storage,
cluster.Node{Address: server.URL()})
cmutex.Unlock()
defer func() {
cmutex.Lock()
dCluster = oldDockerCluster
cmutex.Unlock()
}()
p := dockerProvisioner{}
err = p.PlatformRemove("test")
c.Assert(err, gocheck.IsNil)
c.Assert(strings.Contains(requests[0].URL.RequestURI(), "tsuru/test"), gocheck.Equals, true)
}
示例12: TestEnsureContainersStartedForceStopOnlyOnFailure
func (s *S) TestEnsureContainersStartedForceStopOnlyOnFailure(c *check.C) {
config.Set("docker:bs:image", "myregistry/tsuru/bs")
_, err := nodecontainer.InitializeBS()
c.Assert(err, check.IsNil)
var reqs []*http.Request
server, err := testing.NewServer("127.0.0.1:0", nil, func(r *http.Request) {
reqs = append(reqs, r)
})
c.Assert(err, check.IsNil)
defer server.Stop()
errCount := 0
server.CustomHandler("/containers/big-sibling", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
reqs = append(reqs, r)
if r.Method != "DELETE" {
server.DefaultHandler().ServeHTTP(w, r)
return
}
errCount++
if errCount > 2 {
server.DefaultHandler().ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusInternalServerError)
}
}))
p, err := dockertest.NewFakeDockerProvisioner(server.URL())
c.Assert(err, check.IsNil)
defer p.Destroy()
client, err := docker.NewClient(server.URL())
c.Assert(err, check.IsNil)
buf := safe.NewBuffer(nil)
err = ensureContainersStarted(p, buf, true, nil)
c.Assert(err, check.IsNil)
reqs = nil
err = ensureContainersStarted(p, buf, true, nil)
c.Assert(err, check.IsNil)
var paths []string
for _, r := range reqs {
paths = append(paths, r.Method+" "+r.URL.Path)
}
c.Assert(paths, check.DeepEquals, []string{
"POST /images/create",
"POST /containers/create",
"POST /containers/big-sibling/stop",
"DELETE /containers/big-sibling",
"DELETE /containers/big-sibling",
"DELETE /containers/big-sibling",
"POST /containers/create",
"GET /version",
"POST /containers/big-sibling/start",
})
c.Assert(reqs[3].URL.Query().Get("force"), check.Equals, "")
c.Assert(reqs[4].URL.Query().Get("force"), check.Equals, "1")
c.Assert(reqs[5].URL.Query().Get("force"), check.Equals, "1")
containers, err := client.ListContainers(docker.ListContainersOptions{All: true})
c.Assert(err, check.IsNil)
c.Assert(containers, check.HasLen, 1)
container, err := client.InspectContainer(containers[0].ID)
c.Assert(err, check.IsNil)
c.Assert(container.Name, check.Equals, nodecontainer.BsDefaultName)
}
示例13: TestProject_Deploy
func (s *CoreSuite) TestProject_Deploy(c *C) {
if !*githubFlag {
c.Skip("--github not provided")
}
m, _ := testing.NewServer("127.0.0.1:0", nil, nil)
e := &Environment{Name: "a", DockerEndPoints: []string{m.URL()}}
p := &Project{
Repository: "[email protected]:mcuadros/dockership.git",
Environments: map[string]*Environment{"foo": e},
Dockerfile: "Dockerfile",
GithubToken: githubToken,
TaskStatus: TaskStatus{},
}
input := bytes.NewBuffer(nil)
err := p.Deploy("foo", input, false)
c.Assert(err, HasLen, 0)
l, err := p.ListContainers()
c.Assert(err, HasLen, 0)
c.Assert(l, HasLen, 1)
c.Assert(l[0].DockerEndPoint, Equals, e.DockerEndPoints[0])
c.Assert(string(input.Bytes()), HasLen, 51)
}
示例14: TestSchedulerScheduleFallback
func (s *SchedulerSuite) TestSchedulerScheduleFallback(c *gocheck.C) {
server0, err := testing.NewServer(nil)
c.Assert(err, gocheck.IsNil)
defer server0.Stop()
var buf bytes.Buffer
client, _ := docker.NewClient(server0.URL())
client.PullImage(docker.PullImageOptions{Repository: "tsuru/python", OutputStream: &buf})
a1 := app.App{Name: "impius", Teams: []string{"tsuruteam", "nodockerforme"}}
cont1 := container{ID: "1", Name: "impius1", AppName: a1.Name}
err = s.storage.Apps().Insert(a1)
c.Assert(err, gocheck.IsNil)
defer s.storage.Apps().RemoveAll(bson.M{"name": a1.Name})
coll := s.storage.Collection(schedulerCollection)
err = coll.Insert(
bson.M{"_id": "server0", "address": server0.URL()},
)
c.Assert(err, gocheck.IsNil)
defer coll.RemoveAll(bson.M{"_id": "server0"})
contColl := collection()
err = contColl.Insert(cont1)
c.Assert(err, gocheck.IsNil)
defer contColl.RemoveAll(bson.M{"name": cont1.Name})
var scheduler segregatedScheduler
config := docker.Config{Cmd: []string{"/usr/sbin/sshd", "-D"}, Image: "tsuru/python"}
opts := docker.CreateContainerOptions{Name: cont1.Name, Config: &config}
node, _, err := scheduler.Schedule(opts)
c.Assert(err, gocheck.IsNil)
c.Check(node, gocheck.Equals, "server0")
}
示例15: TestHealerHealNodeWithoutIaaS
func (s *S) TestHealerHealNodeWithoutIaaS(c *check.C) {
node1, err := testing.NewServer("127.0.0.1:0", nil, nil)
c.Assert(err, check.IsNil)
cluster, err := cluster.New(nil, &cluster.MapStorage{},
cluster.Node{Address: node1.URL()},
)
c.Assert(err, check.IsNil)
var p dockerProvisioner
err = p.Initialize()
c.Assert(err, check.IsNil)
p.cluster = cluster
healer := nodeHealer{
locks: make(map[string]*sync.Mutex),
provisioner: &p,
disabledTime: 0,
failuresBeforeHealing: 1,
waitTimeNewMachine: 1 * time.Second,
}
nodes, err := p.getCluster().UnfilteredNodes()
c.Assert(err, check.IsNil)
c.Assert(nodes, check.HasLen, 1)
created, err := healer.healNode(&nodes[0])
c.Assert(err, check.ErrorMatches, ".*error creating new machine.*")
c.Assert(created.Address, check.Equals, "")
nodes, err = p.getCluster().UnfilteredNodes()
c.Assert(err, check.IsNil)
c.Assert(nodes, check.HasLen, 1)
c.Assert(urlPort(nodes[0].Address), check.Equals, urlPort(node1.URL()))
c.Assert(urlToHost(nodes[0].Address), check.Equals, "127.0.0.1")
}