示例#1
0
文件: iaas.go 项目: tsuru/tsuru
func (i *NamedIaaS) GetConfig(name string) (interface{}, error) {
	val, err := config.Get(fmt.Sprintf("iaas:custom:%s:%s", i.IaaSName, name))
	if err != nil {
		val, err = config.Get(fmt.Sprintf("iaas:%s:%s", i.BaseIaaSName, name))
	}
	return val, err
}
示例#2
0
func List() ([]PlanRouter, error) {
	routerConfig, err := config.Get("routers")
	var routers map[interface{}]interface{}
	if err == nil {
		routers, _ = routerConfig.(map[interface{}]interface{})
	}
	routersList := make([]PlanRouter, 0, len(routers))
	var keys []string
	for key := range routers {
		keys = append(keys, key.(string))
	}
	topLevelHipacheConfig, _ := config.Get("hipache")
	if topLevelHipacheConfig != nil {
		keys = append(keys, "hipache")
	}
	sort.Strings(keys)
	for _, value := range keys {
		var routerType string
		routerProperties, _ := routers[value].(map[interface{}]interface{})
		if routerProperties != nil {
			routerType, _ = routerProperties["type"].(string)
		}
		if routerType == "" {
			routerType = value
		}
		routersList = append(routersList, PlanRouter{Name: value, Type: routerType})
	}
	return routersList, nil
}
示例#3
0
文件: iaas.go 项目: tsuru/tsuru
func getDefaultIaasName() (string, error) {
	defaultIaaS, err := config.GetString("iaas:default")
	if err == nil {
		return defaultIaaS, nil
	}
	ec2ProviderName := "ec2"
	ec2Configured := false
	var configuredIaases []string
	for provider := range iaasProviders {
		if _, err = config.Get(fmt.Sprintf("iaas:%s", provider)); err == nil {
			configuredIaases = append(configuredIaases, provider)
			if provider == ec2ProviderName {
				ec2Configured = true
			}
		}
	}
	c, err := config.Get("iaas:custom")
	if err == nil {
		if v, ok := c.(map[interface{}]interface{}); ok {
			for provider := range v {
				configuredIaases = append(configuredIaases, provider.(string))
			}
		}
	}
	if len(configuredIaases) == 1 {
		return configuredIaases[0], nil
	}
	if ec2Configured {
		return ec2ProviderName, nil
	}
	return "", ErrNoDefaultIaaS
}
示例#4
0
// Check Router
// It's verify your router configuration and validate related confs.
func CheckRouter() error {
	if router, err := config.Get("docker:router"); err == nil && router == "hipache" {
		if hipache, err := config.Get("hipache"); err != nil || hipache == nil {
			return fmt.Errorf("You should configure hipache router")
		}
	}
	return nil
}
示例#5
0
func (s *S) TestGetAWSAuth(c *gocheck.C) {
	access, err := config.Get("aws:access-key-id")
	c.Assert(err, gocheck.IsNil)
	secret, err := config.Get("aws:secret-access-key")
	c.Assert(err, gocheck.IsNil)
	auth := getAWSAuth()
	c.Assert(auth.AccessKey, gocheck.Equals, access)
	c.Assert(auth.SecretKey, gocheck.Equals, secret)
}
示例#6
0
func checkBeanstalkd() error {
	if value, _ := config.Get("queue"); value == "beanstalkd" {
		return errors.New("beanstalkd is no longer supported, please use redis instead")
	}
	if _, err := config.Get("queue-server"); err == nil {
		return errors.New(`beanstalkd is no longer supported, please remove the "queue-server" setting from your config file`)
	}
	return nil
}
示例#7
0
func (factory *redisPubSubFactory) dial() (redis.Conn, error) {
	host, err := config.GetString("pubsub:redis-host")
	if err != nil {
		host, err = config.GetString("redis-queue:host")
		if err != nil {
			host = "localhost"
		}
	}
	port, err := config.Get("pubsub:redis-port")
	if err != nil {
		port, err = config.Get("redis-queue:port")
		if err != nil {
			port = "6379"
		}
	}
	port = fmt.Sprintf("%v", port)
	password, err := config.GetString("pubsub:redis-password")
	if err != nil {
		password, _ = config.GetString("redis-queue:password")
	}
	db, err := config.GetInt("pubsub:redis-db")
	if err != nil {
		db, err = config.GetInt("redis-queue:db")
		if err != nil {
			db = 3
		}
	}
	secondFloat := float64(time.Second)
	dialTimeout, err := config.GetFloat("pubsub:redis-dial-timeout")
	if err != nil {
		dialTimeout = 0.1
	}
	dialTimeout = dialTimeout * secondFloat
	readTimeout, err := config.GetFloat("pubsub:redis-read-timeout")
	if err != nil {
		readTimeout = 30 * 60
	}
	readTimeout = readTimeout * secondFloat
	writeTimeout, err := config.GetFloat("pubsub:redis-write-timeout")
	if err != nil {
		writeTimeout = 0.5
	}
	writeTimeout = writeTimeout * secondFloat
	conn, err := redis.DialTimeout("tcp", fmt.Sprintf("%s:%v", host, port), time.Duration(dialTimeout), time.Duration(readTimeout), time.Duration(writeTimeout))
	if err != nil {
		return nil, err
	}
	if password != "" {
		_, err = conn.Do("AUTH", password)
		if err != nil {
			return nil, err
		}
	}
	_, err = conn.Do("SELECT", db)
	return conn, err
}
示例#8
0
文件: iaas.go 项目: zhenruyan/tsuru
func (i *NamedIaaS) GetConfigString(name string) (string, error) {
	val, err := config.Get(fmt.Sprintf("iaas:custom:%s:%s", i.IaaSName, name))
	if err != nil {
		val, err = config.Get(fmt.Sprintf("iaas:%s:%s", i.BaseIaaSName, name))
	}
	if err != nil || val == nil {
		return "", err
	}
	return fmt.Sprintf("%v", val), nil
}
示例#9
0
// Check Schedulers
// It's verify your scheduler configuration and validate related confs.
func CheckScheduler() error {
	if scheduler, err := config.Get("docker:segregate"); err == nil && scheduler == true {
		if servers, err := config.Get("docker:servers"); err == nil && servers != nil {
			return fmt.Errorf("Your scheduler is the segregate. Please remove the servers conf in docker.")
		}
		return nil
	}
	if servers, err := config.Get("docker:servers"); err != nil || servers == nil {
		return fmt.Errorf("You should configure the docker servers.")
	}
	return nil
}
示例#10
0
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")
	conn, err := Conn()
	c.Assert(err, gocheck.IsNil)
	defer conn.Close()
	c.Assert(conn.User().Database.Name, gocheck.Equals, "gandalf")
	c.Assert(conn.User().Database.Session.LiveServers(), gocheck.DeepEquals, []string{"127.0.0.1:27017"})
}
示例#11
0
func (s *S) TestDbConfig(c *check.C) {
	oldURL, _ := config.Get("database:url")
	defer config.Set("database:url", oldURL)
	oldName, _ := config.Get("database:name")
	defer config.Set("database:name", oldName)
	url, dbname := DbConfig()
	c.Assert(url, check.Equals, oldURL)
	c.Assert(dbname, check.Equals, oldName)
	config.Unset("database:url")
	config.Unset("database:name")
	url, dbname = DbConfig()
	c.Assert(url, check.Equals, "127.0.0.1:27017")
	c.Assert(dbname, check.Equals, "gandalf")
}
示例#12
0
文件: commands.go 项目: tsuru/tsuru
func WebProcessDefaultPort() string {
	port, err := config.Get("docker:run-cmd:port")
	if err != nil {
		return "8888"
	}
	return fmt.Sprint(port)
}
示例#13
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)
}
示例#14
0
func getPort() (string, error) {
	port, err := config.Get("docker:run-cmd:port")
	if err != nil {
		return "", err
	}
	return fmt.Sprint(port), nil
}
示例#15
0
文件: hc.go 项目: tsuru/tsuru
// BuildHealthCheck creates a healthcheck function for the given routerName.
//
// It will call the HealthCheck() method in the router (only if it's also a
// HealthChecker), for each instance of it (including the "main" instance and
// all custom routers).
func BuildHealthCheck(routerName string) func() error {
	return func() error {
		routerConfig, err := config.Get("routers")
		if err != nil {
			return hc.ErrDisabledComponent
		}
		routers, _ := routerConfig.(map[interface{}]interface{})
		checkCount := 0
		for ifaceName := range routers {
			name := ifaceName.(string)
			if name != routerName {
				namedRouter := routers[name].(map[interface{}]interface{})
				if tp, _ := namedRouter["type"].(string); tp != routerName {
					continue
				}
			}
			checkCount++
			err := healthCheck(name)
			if err != nil {
				return err
			}
		}
		if checkCount == 0 {
			return hc.ErrDisabledComponent
		}
		return nil
	}
}
示例#16
0
func (s *CheckerSuite) TestCheckBeanstalkdDefinedInQueue(c *check.C) {
	old, _ := config.Get("queue")
	defer config.Set("queue", old)
	config.Set("queue", "beanstalkd")
	err := checkBeanstalkd()
	c.Assert(err.Error(), check.Equals, "beanstalkd is no longer supported, please use redis instead")
}
示例#17
0
func (s *S) TestContainerCreateUndefinedUser(c *check.C) {
	oldUser, _ := config.Get("docker:user")
	defer config.Set("docker:user", oldUser)
	config.Unset("docker:user")
	img := "tsuru/python:latest"
	s.p.Cluster().PullImage(docker.PullImageOptions{Repository: img}, docker.AuthConfiguration{})
	app := provisiontest.NewFakeApp("app-name", "python", 1)
	routertest.FakeRouter.AddBackend(app.GetName())
	defer routertest.FakeRouter.RemoveBackend(app.GetName())
	cont := Container{
		Name:    "myName",
		AppName: app.GetName(),
		Type:    app.GetPlatform(),
		Status:  "created",
	}
	err := cont.Create(&CreateArgs{
		App:         app,
		ImageID:     img,
		Commands:    []string{"docker", "run"},
		Provisioner: s.p,
	})
	c.Assert(err, check.IsNil)
	defer s.removeTestContainer(&cont)
	dcli, _ := docker.NewClient(s.server.URL())
	container, err := dcli.InspectContainer(cont.ID)
	c.Assert(err, check.IsNil)
	c.Assert(container.Config.User, check.Equals, "")
}
示例#18
0
func (s *CheckerSuite) TestCheckBeanstalkdNoQueueConfigured(c *check.C) {
	old, _ := config.Get("queue")
	defer config.Set("queue", old)
	config.Unset("queue")
	err := checkBeanstalkd()
	c.Assert(err, check.IsNil)
}
示例#19
0
文件: hc.go 项目: zhenruyan/tsuru
// BuildHealthCheck creates a healthcheck function for the given providerName.
//
// It will call the HealthCheck() method in the provider (only if it's also a
// HealthChecker), for each instance of it (including the "main" instance and
// all custom IaaSes).
func BuildHealthCheck(providerName string) func() error {
	return func() error {
		iaasConfig, err := config.Get("iaas")
		if err != nil {
			return hc.ErrDisabledComponent
		}
		iaases, _ := iaasConfig.(map[interface{}]interface{})
		for ifaceName := range iaases {
			name := ifaceName.(string)
			if name == "custom" {
				customIaases := iaases[name].(map[interface{}]interface{})
				for ifaceName := range customIaases {
					iaas := customIaases[ifaceName.(string)].(map[interface{}]interface{})
					if iaas["provider"].(string) != providerName {
						continue
					}
					name = ifaceName.(string)
				}
			} else if name != providerName {
				continue
			}
			err := healthCheck(name)
			if err != nil {
				return err
			}
		}
		return nil
	}
}
示例#20
0
文件: hc_test.go 项目: tsuru/tsuru
func (s *S) TestHealthCheckDockerRegistryV2TLS(c *check.C) {
	var request *http.Request
	server := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		request = r
		w.Write([]byte("{}"))
	}))
	defer server.Close()
	oldTransport := tsuruNet.Dial5Full60ClientNoKeepAlive.Transport
	defer func() { tsuruNet.Dial5Full60ClientNoKeepAlive.Transport = oldTransport }()
	tsuruNet.Dial5Full60ClientNoKeepAlive.Transport = &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: true,
		},
	}
	if old, err := config.Get("docker:registry"); err == nil {
		defer config.Set("docker:registry", old)
	} else {
		defer config.Unset("docker:registry")
	}
	config.Set("docker:registry", server.URL+"/")
	err := healthCheckDockerRegistry()
	c.Assert(err, check.IsNil)
	c.Assert(request.URL.Path, check.Equals, "/v2/")
	c.Assert(request.Method, check.Equals, "GET")
}
示例#21
0
func (s *S) TestCloneRepositoryUndefinedPath(c *gocheck.C) {
	old, _ := config.Get("git:unit-repo")
	config.Unset("git:unit-repo")
	defer config.Set("git:unit-repo", old)
	_, err := clone(nil, nil)
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `Tsuru is misconfigured: key "git:unit-repo" not found`)
}
示例#22
0
func (s *S) TestSSHCmdsMissingAddKeyCommand(c *gocheck.C) {
	old, _ := config.Get("docker:ssh:add-key-cmd")
	defer config.Set("docker:ssh:add-key-cmd", old)
	config.Unset("docker:ssh:add-key-cmd")
	commands, err := sshCmds()
	c.Assert(commands, gocheck.IsNil)
	c.Assert(err, gocheck.NotNil)
}
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")
}
func (s *S) TestGetPortUndefined(c *gocheck.C) {
	old, _ := config.Get("docker:run-cmd:port")
	defer config.Set("docker:run-cmd:port", old)
	config.Unset("docker:run-cmd:port")
	port, err := getPort()
	c.Assert(port, gocheck.Equals, "")
	c.Assert(err, gocheck.NotNil)
}
示例#25
0
func (s *S) TestSendEmailUndefinedUser(c *gocheck.C) {
	old, _ := config.Get("smtp:user")
	defer config.Set("smtp:user", old)
	config.Unset("smtp:user")
	err := sendEmail("*****@*****.**", []byte("Hello world!"))
	c.Assert(err, gocheck.NotNil)
	c.Assert(err.Error(), gocheck.Equals, `Setting "smtp:user" is not defined`)
}
示例#26
0
func (s *GandalfSuite) TestHealthCheckDisabled(c *check.C) {
	old, err := config.Get("git:api-server")
	c.Assert(err, check.IsNil)
	defer config.Set("git:api-server", old)
	config.Unset("git:api-server")
	err = healthCheck()
	c.Assert(err, check.Equals, hc.ErrDisabledComponent)
}
示例#27
0
func (s *BeanstalkSuite) TestConnectionRefused(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)
}
示例#28
0
func (s *ExternalSuite) TestBuildHealthCheckUnconfigured(c *check.C) {
	if old, err := config.Get("routers"); err == nil {
		defer config.Set("routers", old)
	}
	config.Unset("routers")
	fn := router.BuildHealthCheck("fake-hc")
	c.Assert(fn(), check.Equals, hc.ErrDisabledComponent)
}
示例#29
0
func (s *S) TestHealthCheckDockerRegistryUnconfigured(c *check.C) {
	if old, err := config.Get("docker:registry"); err == nil {
		defer config.Set("docker:registry", old)
	}
	config.Unset("docker:registry")
	err := healthCheckDockerRegistry()
	c.Assert(err, check.Equals, hc.ErrDisabledComponent)
}
示例#30
0
func checkConfigPresent(keys []string, fmtMsg string) error {
	for _, key := range keys {
		if _, err := config.Get(key); err != nil {
			return fmt.Errorf(fmtMsg, key)
		}
	}
	return nil
}