func (s *S) TestAddBackendWithVpc(c *gocheck.C) { old, _ := config.Get("juju:elb-avail-zones") config.Unset("juju:elb-avail-zones") config.Set("juju:elb-use-vpc", true) config.Set("juju:elb-vpc-subnets", []string{"subnet-a4a3a2a1", "subnet-002200"}) config.Set("juju:elb-vpc-secgroups", []string{"sg-0900"}) defer func() { config.Set("juju:elb-avail-zones", old) config.Unset("juju:elb-use-vpc") config.Unset("juju:elb-vpc-subnets") config.Unset("juju:elb-vpc-secgroups") }() router := elbRouter{} err := router.AddBackend("tip") c.Assert(err, gocheck.IsNil) defer router.RemoveBackend("tip") resp, err := s.client.DescribeLoadBalancers("tip") c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) lbd := resp.LoadBalancerDescriptions[0] c.Assert(lbd.Subnets, gocheck.DeepEquals, []string{"subnet-a4a3a2a1", "subnet-002200"}) c.Assert(lbd.SecurityGroups, gocheck.DeepEquals, []string{"sg-0900"}) c.Assert(lbd.Scheme, gocheck.Equals, "internal") c.Assert(lbd.AvailZones, gocheck.HasLen, 0) }
func (s *HandlersSuite) TestListNodeHandlerWithoutCluster(c *gocheck.C) { var result []node config.Set("docker:segregate", true) defer config.Unset("docker:segregate") config.Set("docker:scheduler:redis-server", "127.0.0.1:6379") defer config.Unset("docker:scheduler:redis-server") dCluster = nil err := s.conn.Collection(schedulerCollection).Insert(node{Address: "host.com:4243", ID: "server01"}) c.Assert(err, gocheck.IsNil) defer s.conn.Collection(schedulerCollection).RemoveId("server01") err = s.conn.Collection(schedulerCollection).Insert(node{Address: "host.com:4243", ID: "server02"}) c.Assert(err, gocheck.IsNil) defer s.conn.Collection(schedulerCollection).RemoveId("server02") req, err := http.NewRequest("GET", "/node/", nil) rec := httptest.NewRecorder() err = listNodeHandler(rec, req, nil) c.Assert(err, gocheck.IsNil) body, err := ioutil.ReadAll(rec.Body) c.Assert(err, gocheck.IsNil) err = json.Unmarshal(body, &result) c.Assert(err, gocheck.IsNil) c.Assert(result[0].ID, gocheck.Equals, "server01") c.Assert(result[0].Address, gocheck.DeepEquals, "host.com:4243") c.Assert(result[1].ID, gocheck.Equals, "server02") c.Assert(result[1].Address, gocheck.DeepEquals, "host.com:4243") }
func (s *S) TestCommandsToRun(c *gocheck.C) { rfs := ftesting.RecordingFs{} f, err := rfs.Create("/opt/me/id_dsa.pub") c.Assert(err, gocheck.IsNil) f.Write([]byte("ssh-rsa ohwait! me@machine\n")) f.Close() old := fsystem fsystem = &rfs defer func() { fsystem = old }() config.Set("docker:ssh:sshd-path", "/opt/bin/sshd") config.Set("docker:ssh:public-key", "/opt/me/id_dsa.pub") config.Set("docker:ssh:private-key", "/opt/me/id_dsa") defer config.Unset("docker:ssh:sshd-path") defer config.Unset("docker:ssh:public-key") defer config.Unset("docker:ssh:private-key") app := testing.NewFakeApp("myapp", "python", 1) cmd, err := commandToRun(app) c.Assert(err, gocheck.IsNil) sshCmd := "/var/lib/tsuru/add-key ssh-rsa ohwait! me@machine && /opt/bin/sshd -D" expected := []string{ "docker", "run", "-d", "-t", "-p", s.port, fmt.Sprintf("%s/python", s.repoNamespace), "/bin/bash", "-c", sshCmd, } c.Assert(cmd, gocheck.DeepEquals, expected) }
func (s *S) TestDeployLogsActions(c *gocheck.C) { config.Set("git:unit-repo", "test/dir") config.Set("git:host", "gandalf.com") defer func() { config.Unset("git:unit-repo") config.Unset("git:host") }() app := testing.NewFakeApp("cribcaged", "python", 1) w := &bytes.Buffer{} p := LXCProvisioner{} err := p.Deploy(app, w) c.Assert(err, gocheck.IsNil) logs := w.String() expected := ` ---> Tsuru receiving push ---> Replicating the application repository across units ---> Installing dependencies ---> Restarting application ---> Deploy done! ` c.Assert(logs, gocheck.Equals, expected) }
func (s *ELBSuite) TestCreateELBUsingVPC(c *gocheck.C) { old, _ := config.Get("juju:elb-avail-zones") config.Unset("juju:elb-avail-zones") config.Set("juju:elb-use-vpc", true) config.Set("juju:elb-vpc-subnets", []string{"subnet-a4a3a2a1", "subnet-002200"}) config.Set("juju:elb-vpc-secgroups", []string{"sg-0900"}) defer func() { config.Set("juju:elb-avail-zones", old) config.Unset("juju:elb-use-vpc") config.Unset("juju:elb-vpc-subnets") config.Unset("juju:elb-vpc-secgroups") }() app := testing.NewFakeApp("relax", "who", 1) manager := ELBManager{} err := manager.Create(app) c.Assert(err, gocheck.IsNil) defer s.client.DeleteLoadBalancer(app.GetName()) conn, coll := manager.collection() defer conn.Close() defer coll.Remove(bson.M{"name": app.GetName()}) resp, err := s.client.DescribeLoadBalancers(app.GetName()) c.Assert(err, gocheck.IsNil) c.Assert(resp.LoadBalancerDescriptions, gocheck.HasLen, 1) lbd := resp.LoadBalancerDescriptions[0] c.Assert(lbd.Subnets, gocheck.DeepEquals, []string{"subnet-a4a3a2a1", "subnet-002200"}) c.Assert(lbd.SecurityGroups, gocheck.DeepEquals, []string{"sg-0900"}) c.Assert(lbd.Scheme, gocheck.Equals, "internal") c.Assert(lbd.AvailZones, gocheck.HasLen, 0) }
func (s *S) TestReadOnlyURLWithSSHAndPort(c *gocheck.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") config.Set("git:ssh:port", "49022") defer config.Unset("git:ssh:port") host, err := config.GetString("host") c.Assert(err, gocheck.IsNil) remote := (&Repository{Name: "lol"}).ReadOnlyURL() c.Assert(remote, gocheck.Equals, fmt.Sprintf("ssh://git@%s:49022/lol.git", host)) }
func (s *S) TestConnectDefaultSettings(c *gocheck.C) { oldURL, _ := config.Get("database:url") defer config.Set("database:url", oldURL) oldName, _ := config.Get("database:name") defer config.Set("database:name", oldName) config.Unset("database:url") config.Unset("database:name") Connect() c.Assert(Session.DB.Name, gocheck.Equals, "gandalf") c.Assert(Session.DB.Session.LiveServers(), gocheck.DeepEquals, []string{"localhost:27017"}) }
func (s *S) TestConn(c *gocheck.C) { config.Set("database:url", "127.0.0.1:27017") defer config.Unset("database:url") config.Set("database:name", "tsuru_storage_test") defer config.Unset("database:name") storage, err := Conn() c.Assert(err, gocheck.IsNil) defer storage.session.Close() err = storage.session.Ping() c.Assert(err, gocheck.IsNil) }
func (s *S) TestELBSupport(c *gocheck.C) { defer config.Unset("juju:use-elb") config.Set("juju:use-elb", true) p := JujuProvisioner{} c.Assert(p.elbSupport(), gocheck.Equals, true) config.Set("juju:use-elb", false) c.Assert(p.elbSupport(), gocheck.Equals, true) // Read config only once. p = JujuProvisioner{} c.Assert(p.elbSupport(), gocheck.Equals, false) config.Unset("juju:use-elb") p = JujuProvisioner{} c.Assert(p.elbSupport(), gocheck.Equals, false) }
func (s *S) TestReadWriteURLWithSSHAndPort(c *gocheck.C) { config.Set("git:ssh:use", true) defer config.Unset("git:ssh:use") config.Set("git:ssh:port", "49022") defer config.Unset("git:ssh:port") uid, err := config.GetString("uid") c.Assert(err, gocheck.IsNil) host, err := config.GetString("host") c.Assert(err, gocheck.IsNil) remote := (&Repository{Name: "lol"}).ReadWriteURL() expected := fmt.Sprintf("ssh://%s@%s:49022/lol.git", uid, host) c.Assert(remote, gocheck.Equals, expected) }
func (s *S) TestPushImage(c *gocheck.C) { var request *http.Request server, err := dtesting.NewServer(func(r *http.Request) { request = r }) c.Assert(err, gocheck.IsNil) defer server.Stop() config.Set("docker:registry", "localhost:3030") defer config.Unset("docker:registry") var storage mapStorage storage.StoreImage("localhost:3030/base", "server0") cmutex.Lock() oldDockerCluster := dCluster dCluster, _ = cluster.New(nil, &storage, 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) err = pushImage("localhost:3030/base") c.Assert(err, gocheck.IsNil) c.Assert(request.URL.Path, gocheck.Matches, ".*/images/localhost:3030/base/push$") }
func (s *S) TestExecuteCommandOnce(c *gocheck.C) { var handler FakeSSHServer handler.output = ". .." server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") app := testing.NewFakeApp("almah", "static", 1) p := dockerProvisioner{} container, err := s.newContainer(&newContainerOpts{AppName: app.GetName()}) c.Assert(err, gocheck.IsNil) defer s.removeTestContainer(container) container.HostAddr = host coll := collection() defer coll.Close() coll.Update(bson.M{"id": container.ID}, container) var stdout, stderr bytes.Buffer err = p.ExecuteCommandOnce(&stdout, &stderr, app, "ls", "-lh") c.Assert(err, gocheck.IsNil) c.Assert(stderr.Bytes(), gocheck.IsNil) c.Assert(stdout.String(), gocheck.Equals, ". ..") body := handler.bodies[0] input := cmdInput{Cmd: "ls", Args: []string{"-lh"}} c.Assert(body, gocheck.DeepEquals, input) }
func (s *S) TestProvisionerRestartCallsTheRestartHook(c *gocheck.C) { var handler FakeSSHServer handler.output = "caad7bbd5411" server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") var p dockerProvisioner app := testing.NewFakeApp("almah", "static", 1) newImage("tsuru/python", s.server.URL()) cont, err := s.newContainer(&newContainerOpts{AppName: app.GetName()}) c.Assert(err, gocheck.IsNil) defer s.removeTestContainer(cont) cont.HostAddr = host coll := collection() defer coll.Close() err = coll.Update(bson.M{"id": cont.ID}, cont) c.Assert(err, gocheck.IsNil) err = p.Restart(app) c.Assert(err, gocheck.IsNil) input := cmdInput{Cmd: "/var/lib/tsuru/restart"} body := handler.bodies[0] c.Assert(body, gocheck.DeepEquals, input) ip, _, _ := cont.networkInfo() path := fmt.Sprintf("/container/%s/cmd", ip) c.Assert(handler.requests[0].URL.Path, gocheck.DeepEquals, path) }
func (s *S) TestProvisionerExecuteCommand(c *gocheck.C) { var handler FakeSSHServer handler.output = ". .." server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") app := testing.NewFakeApp("starbreaker", "python", 1) container, err := s.newContainer(&newContainerOpts{AppName: app.GetName()}) c.Assert(err, gocheck.IsNil) defer s.removeTestContainer(container) container.HostAddr = host coll := collection() defer coll.Close() coll.Update(bson.M{"id": container.ID}, container) var stdout, stderr bytes.Buffer var p dockerProvisioner err = p.ExecuteCommand(&stdout, &stderr, app, "ls", "-ar") c.Assert(err, gocheck.IsNil) c.Assert(stderr.Bytes(), gocheck.IsNil) c.Assert(stdout.String(), gocheck.Equals, ". ..") body := handler.bodies[0] input := cmdInput{Cmd: "ls", Args: []string{"-ar"}} c.Assert(body, gocheck.DeepEquals, input) ip, _, _ := container.networkInfo() path := fmt.Sprintf("/container/%s/cmd", ip) c.Assert(handler.requests[0].URL.Path, gocheck.DeepEquals, path) }
func (s *S) TestProvisionerRestartCallsTheRestartHook(c *gocheck.C) { var handler FakeSSHServer handler.output = "caad7bbd5411" server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") var p dockerProvisioner app := testing.NewFakeApp("almah", "static", 1) cont := container{ ID: handler.output, AppName: app.GetName(), Type: app.GetPlatform(), IP: "10.10.10.10", HostAddr: host, } err := collection().Insert(cont) c.Assert(err, gocheck.IsNil) defer collection().RemoveId(cont.ID) err = p.Restart(app) c.Assert(err, gocheck.IsNil) input := cmdInput{Cmd: "/var/lib/tsuru/restart"} body := handler.bodies[0] c.Assert(body, gocheck.DeepEquals, input) path := "/container/10.10.10.10/cmd" c.Assert(handler.requests[0].URL.Path, gocheck.DeepEquals, path) }
func (s *S) TestDestroyWithoutBucketSupport(c *gocheck.C) { config.Unset("bucket-support") defer config.Set("bucket-support", true) h := testHandler{} ts := s.t.StartGandalfTestServer(&h) defer ts.Close() a := App{ Name: "blinded", Framework: "evergrey", Units: []Unit{{Name: "duvido", Machine: 3}}, } err := CreateApp(&a, 1, []auth.Team{s.team}) c.Assert(err, gocheck.IsNil) a.Get() err = ForceDestroy(&a) c.Assert(err, gocheck.IsNil) err = a.Get() c.Assert(err, gocheck.NotNil) qt, err := s.conn.Apps().Find(bson.M{"name": a.Name}).Count() c.Assert(err, gocheck.IsNil) c.Assert(qt, gocheck.Equals, 0) c.Assert(s.provisioner.FindApp(&a), gocheck.Equals, -1) msg, err := aqueue().Get(1e6) c.Assert(err, gocheck.IsNil) c.Assert(msg.Args, gocheck.DeepEquals, []string{a.Name}) msg.Delete() }
func (s *ELBSuite) TestDestroyWithELB(c *gocheck.C) { config.Set("juju:charms-path", "/home/charms") defer config.Unset("juju:charms-path") fexec := &etesting.FakeExecutor{} setExecut(fexec) defer setExecut(nil) app := testing.NewFakeApp("jimmy", "who", 0) p := JujuProvisioner{} err := p.Provision(app) c.Assert(err, gocheck.IsNil) err = p.Destroy(app) c.Assert(err, gocheck.IsNil) router, err := Router() c.Assert(err, gocheck.IsNil) defer router.RemoveBackend(app.GetName()) addr, err := router.Addr(app.GetName()) c.Assert(addr, gocheck.Equals, "") c.Assert(err, gocheck.NotNil) c.Assert(err, gocheck.ErrorMatches, "not found") q := getQueue(queueName) msg, err := q.Get(1e9) c.Assert(err, gocheck.IsNil) if msg.Action == addUnitToLoadBalancer && msg.Args[0] == "jimmy" { msg.Delete() } else { q.Release(msg, 0) } }
func (s *S) TestRemoveOld(c *gocheck.C) { config.Set("auth:max-simultaneous-sessions", 6) defer config.Unset("auth:max-simultaneous-sessions") user := "******" defer s.conn.Tokens().RemoveAll(bson.M{"useremail": user}) initial := time.Now().Add(-48 * time.Hour) for i := 0; i < 30; i++ { token := Token{ Token: fmt.Sprintf("blastoise-%d", i), Expires: 100 * 24 * time.Hour, Creation: initial.Add(time.Duration(i) * time.Hour), UserEmail: user, } err := s.conn.Tokens().Insert(token) c.Check(err, gocheck.IsNil) } err := removeOldTokens(user) c.Assert(err, gocheck.IsNil) var tokens []Token err = s.conn.Tokens().Find(bson.M{"useremail": user}).All(&tokens) c.Assert(err, gocheck.IsNil) c.Assert(tokens, gocheck.HasLen, 6) names := make([]string, len(tokens)) for i := range tokens { names[i] = tokens[i].Token } expected := []string{ "blastoise-24", "blastoise-25", "blastoise-26", "blastoise-27", "blastoise-28", "blastoise-29", } c.Assert(names, gocheck.DeepEquals, expected) }
func (s *S) TestDeploy(c *gocheck.C) { tmpdir, err := commandmocker.Add("ssh", "") c.Assert(err, gocheck.IsNil) defer commandmocker.Remove(tmpdir) config.Set("git:unit-repo", "test/dir") config.Set("git:ro-host", "gandalf.com") defer func() { config.Unset("git:unit-repo") config.Unset("git:ro-host") }() app := testing.NewFakeApp("cribcaged", "python", 1) w := &bytes.Buffer{} p := LXCProvisioner{} err = p.Deploy(app, w) c.Assert(err, gocheck.IsNil) }
func (s *ELBSuite) TestDestroyWithELB(c *gocheck.C) { config.Set("juju:charms-path", "/home/charms") defer config.Unset("juju:charms-path") fexec := &etesting.FakeExecutor{} execut = fexec defer func() { execut = nil }() app := testing.NewFakeApp("jimmy", "who", 0) p := JujuProvisioner{} err := p.Provision(app) c.Assert(err, gocheck.IsNil) err = p.Destroy(app) c.Assert(err, gocheck.IsNil) lb := p.LoadBalancer() defer lb.Destroy(app) // sanity addr, err := lb.Addr(app) c.Assert(addr, gocheck.Equals, "") c.Assert(err, gocheck.NotNil) c.Assert(err.Error(), gocheck.Equals, "not found") q := getQueue(queueName) msg, err := q.Get(1e9) c.Assert(err, gocheck.IsNil) if msg.Action == addUnitToLoadBalancer && msg.Args[0] == "jimmy" { msg.Delete() } else { q.Release(msg, 0) } }
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$") }
func (s *S) TestExecuteCommandOnce(c *gocheck.C) { var handler FakeSSHServer handler.output = ". .." server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") app := testing.NewFakeApp("almah", "static", 1) p := dockerProvisioner{} container := container{ID: "c-036", AppName: app.GetName(), Type: "python", IP: "10.10.10.1", HostAddr: host} err := s.conn.Collection(s.collName).Insert(container) c.Assert(err, gocheck.IsNil) defer s.conn.Collection(s.collName).Remove(bson.M{"_id": container.ID}) var stdout, stderr bytes.Buffer err = p.ExecuteCommandOnce(&stdout, &stderr, app, "ls", "-lh") c.Assert(err, gocheck.IsNil) c.Assert(err, gocheck.IsNil) c.Assert(stderr.Bytes(), gocheck.IsNil) c.Assert(stdout.String(), gocheck.Equals, ". ..") body := handler.bodies[0] input := cmdInput{Cmd: "ls", Args: []string{"-lh"}} c.Assert(body, gocheck.DeepEquals, input) }
func (s *S) TestBuildImageNameWithRegistry(c *gocheck.C) { config.Set("docker:registry", "localhost:3030") defer config.Unset("docker:registry") repository := assembleImageName("raising") expected := "localhost:3030/" + s.repoNamespace + "/raising" c.Assert(repository, gocheck.Equals, expected) }
func (s *S) TestProvisionUndefinedCharmsPath(c *gocheck.C) { config.Unset("juju:charms-path") p := JujuProvisioner{} err := p.Provision(testing.NewFakeApp("eternity", "sandman", 0)) c.Assert(err, gocheck.NotNil) c.Assert(err.Error(), gocheck.Equals, `Setting "juju:charms-path" is not defined.`) }
func (s *S) TestCreateWithoutBucketSupport(c *gocheck.C) { config.Unset("bucket-support") defer config.Set("bucket-support", true) h := testHandler{} ts := s.t.StartGandalfTestServer(&h) defer ts.Close() a := App{ Name: "sorry", Framework: "evergrey", Units: []Unit{{Machine: 3}}, } expectedHost := "localhost" config.Set("host", expectedHost) err := CreateApp(&a, 3, []auth.Team{s.team}) c.Assert(err, gocheck.IsNil) defer ForceDestroy(&a) err = a.Get() c.Assert(err, gocheck.IsNil) var retrievedApp App err = s.conn.Apps().Find(bson.M{"name": a.Name}).One(&retrievedApp) c.Assert(err, gocheck.IsNil) c.Assert(retrievedApp.Name, gocheck.Equals, a.Name) c.Assert(retrievedApp.Framework, gocheck.Equals, a.Framework) c.Assert(retrievedApp.Teams, gocheck.DeepEquals, []string{s.team.Name}) env := a.InstanceEnv(s3InstanceName) c.Assert(env, gocheck.DeepEquals, map[string]bind.EnvVar{}) message, err := aqueue().Get(1e6) c.Assert(err, gocheck.IsNil) defer message.Delete() c.Assert(message.Action, gocheck.Equals, regenerateApprc) c.Assert(message.Args, gocheck.DeepEquals, []string{a.Name}) c.Assert(s.provisioner.GetUnits(&a), gocheck.HasLen, 3) }
func (s *S) TestReplicateImageWithoutRegistryInTheImageName(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") cmutext.Lock() oldDockerCluster := dCluster dCluster, _ = cluster.New(nil, cluster.Node{ID: "server0", Address: server.URL()}) cmutext.Unlock() defer func() { cmutext.Lock() defer cmutext.Unlock() dCluster = oldDockerCluster }() var buf bytes.Buffer opts := dockerClient.PullImageOptions{ Repository: "localhost:3030/base", Registry: "http://index.docker.io", } err = dCluster.PullImage(opts, &buf) c.Assert(err, gocheck.IsNil) err = replicateImage("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$") }
func (s *S) TestReplicateImage(c *gocheck.C) { var requests int32 server, err := dtesting.NewServer(func(*http.Request) { atomic.AddInt32(&requests, 1) }) c.Assert(err, gocheck.IsNil) defer server.Stop() config.Set("docker:registry", "http://localhost:3030") defer config.Unset("docker:registry") cmutext.Lock() oldDockerCluster := dCluster dCluster, _ = cluster.New(cluster.Node{ID: "server0", Address: server.URL()}) cmutext.Unlock() defer func() { cmutext.Lock() defer cmutext.Unlock() dCluster = oldDockerCluster }() var buf bytes.Buffer err = dCluster.PullImage(dockerClient.PullImageOptions{Repository: "base", Registry: "http://index.docker.io"}, &buf) c.Assert(err, gocheck.IsNil) err = replicateImage("base") c.Assert(err, gocheck.IsNil) c.Assert(atomic.LoadInt32(&requests), gocheck.Equals, int32(3)) }
func (s *S) TestRegister(c *gocheck.C) { config.Set("queue", "unregistered") defer config.Unset("queue") Register("unregistered", beanstalkdFactory{}) _, err := Factory() c.Assert(err, gocheck.IsNil) }
func (s *S) TestDeleteConnectionError(c *C) { old, _ := config.Get("queue-server") defer config.Set("queue-server", old) config.Unset("queue-server") err := Delete(nil) c.Assert(err, NotNil) }
func (s *S) TestProvisionerExecuteCommandMultipleContainers(c *gocheck.C) { var handler FakeSSHServer handler.output = ". .." server := httptest.NewServer(&handler) defer server.Close() host, port, _ := net.SplitHostPort(server.Listener.Addr().String()) portNumber, _ := strconv.Atoi(port) config.Set("docker:ssh-agent-port", portNumber) defer config.Unset("docker:ssh-agent-port") app := testing.NewFakeApp("starbreaker", "python", 1) err := s.conn.Collection(s.collName).Insert( container{ID: "c-036", AppName: "starbreaker", Type: "python", IP: "10.10.10.1", HostAddr: host}, container{ID: "c-037", AppName: "starbreaker", Type: "python", IP: "10.10.10.2", HostAddr: host}, ) c.Assert(err, gocheck.IsNil) defer s.conn.Collection(s.collName).RemoveAll(bson.M{"_id": bson.M{"$in": []string{"c-036", "c-037"}}}) var stdout, stderr bytes.Buffer var p dockerProvisioner err = p.ExecuteCommand(&stdout, &stderr, app, "ls", "-ar") c.Assert(err, gocheck.IsNil) c.Assert(stderr.Bytes(), gocheck.IsNil) input := cmdInput{Cmd: "ls", Args: []string{"-ar"}} c.Assert(handler.bodies, gocheck.DeepEquals, []cmdInput{input, input}) path1 := "/container/10.10.10.1/cmd" path2 := "/container/10.10.10.2/cmd" c.Assert(handler.requests[0].URL.Path, gocheck.Equals, path1) c.Assert(handler.requests[1].URL.Path, gocheck.Equals, path2) }