Пример #1
0
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)
}
Пример #2
0
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)
}
Пример #3
0
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)
}
Пример #4
0
func (s *S) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "router_fake_tests")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #5
0
func (s *S) TestAddRoute(c *gocheck.C) {
	tmpdir, err := commandmocker.Add("sudo", "$*")
	c.Assert(err, gocheck.IsNil)
	defer commandmocker.Remove(tmpdir)
	config.Set("nginx:domain", "andrewzito.com")
	config.Set("nginx:routes-path", "testdata")
	rfs := &testing.RecordingFs{}
	fsystem = rfs
	defer func() {
		fsystem = nil
	}()
	var r NginxRouter
	err = r.AddRoute("name", "127.0.0.1")
	c.Assert(err, gocheck.IsNil)
	file, err := rfs.Open("testdata/name")
	c.Assert(err, gocheck.IsNil)
	data, err := ioutil.ReadAll(file)
	c.Assert(err, gocheck.IsNil)
	expected := `server {
	listen 80;
	server_name name.andrewzito.com;
	location / {
		proxy_pass http://127.0.0.1;
	}
}`
	c.Assert(string(data), gocheck.Equals, expected)
	c.Assert(commandmocker.Ran(tmpdir), gocheck.Equals, true)
	expected = "service nginx restart"
	c.Assert(commandmocker.Output(tmpdir), gocheck.Equals, expected)
}
Пример #6
0
func (s *S) TestWaitForNetworkTimeout(c *gocheck.C) {
	config.Set("lxc:ip-timeout", 1)
	config.Set("lxc:ssh-port", 2222)
	cont := container{name: "vm", ip: "localhost"}
	err := cont.waitForNetwork()
	c.Assert(err, gocheck.NotNil)
}
Пример #7
0
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)
}
Пример #8
0
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)
}
Пример #9
0
func (s *WriterSuite) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_api_writer_test")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #10
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")
}
Пример #11
0
func (s *S) SetUpSuite(c *C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Assert(err, IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_repository_tests")
	db.Connect()
}
Пример #12
0
func (s *S) SetUpSuite(c *gocheck.C) {
	config.Set("hipache:domain", "golang.org")
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "router_hipache_tests")
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #13
0
func (s *SchedulerSuite) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "docker_scheduler_tests")
	config.Set("docker:repository-namespace", "tsuru")
	s.storage, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #14
0
func (s *S) TestGetGitServer(c *gocheck.C) {
	gitServer, err := config.GetString("git:host")
	c.Assert(err, gocheck.IsNil)
	defer config.Set("git:host", gitServer)
	config.Set("git:host", "gandalf-host.com")
	uri := getGitServer()
	c.Assert(uri, gocheck.Equals, "gandalf-host.com")
}
Пример #15
0
func (s *ConsumptionSuite) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_api_consumption_test")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.createUserAndTeam(c)
}
Пример #16
0
func (s *BeanstalkSuite) TestConnectionResfused(c *gocheck.C) {
	old, _ := config.Get("queue-server")
	config.Set("queue-server", "127.0.0.1:11301")
	defer config.Set("queue-server", old)
	conn, err := connection()
	c.Assert(conn, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
}
Пример #17
0
func (s *ActionsSuite) SetUpSuite(c *gocheck.C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_api_actions_test")
	config.Set("auth:salt", "tsuru-salt")
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #18
0
func (s *S) TestGetPortInteger(c *gocheck.C) {
	old, _ := config.Get("docker:run-cmd:port")
	defer config.Set("docker:run-cmd:port", old)
	config.Set("docker:run-cmd:port", 8888)
	port, err := getPort()
	c.Assert(err, gocheck.IsNil)
	c.Assert(port, gocheck.Equals, "8888")
}
Пример #19
0
// TODO(fss): simplify this test. Right now, it's a little monster.
func (s *S) TestCreateApp(c *C) {
	patchRandomReader()
	defer unpatchRandomReader()
	h := testHandler{}
	ts := s.t.StartGandalfTestServer(&h)
	defer ts.Close()
	server := testing.FakeQueueServer{}
	server.Start("127.0.0.1:0")
	defer server.Stop()
	a := App{
		Name:      "appname",
		Framework: "django",
		Units:     []Unit{{Machine: 3}},
	}
	expectedHost := "localhost"
	config.Set("host", expectedHost)
	old, err := config.Get("queue-server")
	if err != nil {
		defer config.Set("queue-server", old)
	}
	config.Set("queue-server", server.Addr())

	err = CreateApp(&a, 3)
	c.Assert(err, IsNil)
	defer a.Destroy()
	c.Assert(a.State, Equals, "pending")
	var retrievedApp App
	err = db.Session.Apps().Find(bson.M{"name": a.Name}).One(&retrievedApp)
	c.Assert(err, IsNil)
	c.Assert(retrievedApp.Name, Equals, a.Name)
	c.Assert(retrievedApp.Framework, Equals, a.Framework)
	c.Assert(retrievedApp.State, Equals, a.State)
	env := a.InstanceEnv(s3InstanceName)
	c.Assert(env["TSURU_S3_ENDPOINT"].Value, Equals, s.t.S3Server.URL())
	c.Assert(env["TSURU_S3_ENDPOINT"].Public, Equals, false)
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Value, Equals, "true")
	c.Assert(env["TSURU_S3_LOCATIONCONSTRAINT"].Public, Equals, false)
	e, ok := env["TSURU_S3_ACCESS_KEY_ID"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	e, ok = env["TSURU_S3_SECRET_KEY"]
	c.Assert(ok, Equals, true)
	c.Assert(e.Public, Equals, false)
	c.Assert(env["TSURU_S3_BUCKET"].Value, HasLen, maxBucketSize)
	c.Assert(env["TSURU_S3_BUCKET"].Value, Equals, "appnamee3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3e3")
	c.Assert(env["TSURU_S3_BUCKET"].Public, Equals, false)
	env = a.InstanceEnv("")
	c.Assert(env["APPNAME"].Value, Equals, a.Name)
	c.Assert(env["APPNAME"].Public, Equals, false)
	c.Assert(env["TSURU_HOST"].Value, Equals, expectedHost)
	c.Assert(env["TSURU_HOST"].Public, Equals, false)
	expectedMessage := queue.Message{
		Action: RegenerateApprc,
		Args:   []string{a.Name},
	}
	c.Assert(server.Messages(), DeepEquals, []queue.Message{expectedMessage})
	c.Assert(s.provisioner.GetUnits(&a), HasLen, 3)
}
Пример #20
0
func (s *S) SetUpSuite(c *gocheck.C) {
	config.Set("git:api-server", "http://*****:*****@git.tsuru.io:foobar.git"}`
	s.h = &tsrTesting.TestHandler{Content: content}
	s.ts = tsrTesting.StartGandalfTestServer(s.h)
}
Пример #21
0
func (s *LogSuite) SetUpSuite(c *gocheck.C) {
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_log_api_tests")
	config.Set("auth:hash-cost", 4)
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.createUserAndTeam(c)
}
Пример #22
0
func (s *S) SetUpSuite(c *gocheck.C) {
	err := config.ReadConfigFile("../etc/gandalf.conf")
	c.Assert(err, gocheck.IsNil)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "gandalf_api_tests")
	db.Connect()
	s.tmpdir, err = commandmocker.Add("git", "")
	c.Assert(err, gocheck.IsNil)
}
Пример #23
0
func (s *InstanceSuite) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_service_instance_test")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.user = &auth.User{Email: "*****@*****.**", Password: "******"}
	s.team = &auth.Team{Name: "Raul", Users: []string{s.user.Email}}
}
Пример #24
0
func (s *S) SetUpSuite(c *gocheck.C) {
	s.collName = "collName"
	config.Set("local:collection", s.collName)
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "juju_provision_tests_s")
	var err error
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
}
Пример #25
0
func (s *ProvisionSuite) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_api_provision_test")
	config.Set("auth:hash-cost", bcrypt.MinCost)
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.createUserAndTeam(c)
}
Пример #26
0
func (s *S) SetUpSuite(c *gocheck.C) {
	var err error
	config.Set("database:url", "127.0.0.1:27017")
	config.Set("database:name", "tsuru_collector_test")
	s.conn, err = db.Conn()
	c.Assert(err, gocheck.IsNil)
	s.provisioner = ttesting.NewFakeProvisioner()
	app.Provisioner = s.provisioner
	config.Set("queue-server", "127.0.0.1:0")
}
Пример #27
0
func (s *S) TestWaitForNetwork(c *gocheck.C) {
	ln, err := net.Listen("tcp", "127.0.0.1:2222")
	c.Assert(err, gocheck.IsNil)
	defer ln.Close()
	config.Set("lxc:ip-timeout", 5)
	config.Set("lxc:ssh-port", 2222)
	cont := container{name: "vm", ip: "127.0.0.1"}
	err = cont.waitForNetwork()
	c.Assert(err, gocheck.IsNil)
}
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))
}
Пример #29
0
func (s *S) TestLoadConfigExpireDaysNotInteger(c *gocheck.C) {
	cost = 0
	tokenExpire = 0
	oldValue, err := config.Get("auth:token-expire-days")
	c.Assert(err, gocheck.IsNil)
	config.Set("auth:token-expire-days", "abacaxi")
	defer config.Set("auth:token-expire-days", oldValue)
	err = loadConfig()
	c.Assert(tokenExpire, gocheck.Equals, defaultExpiration)
}
func (s *S) TestReadWriteURLUseUidFromConfigFile(c *gocheck.C) {
	uid, err := config.GetString("uid")
	c.Assert(err, gocheck.IsNil)
	host, err := config.GetString("host")
	c.Assert(err, gocheck.IsNil)
	config.Set("uid", "test")
	defer config.Set("uid", uid)
	remote := (&Repository{Name: "f#"}).ReadWriteURL()
	c.Assert(remote, gocheck.Equals, fmt.Sprintf("test@%s:f#.git", host))
}