Exemple #1
0
func parseConfig(cfgFile string) (*config.Config, error) {
	if strings.Trim(cfgFile, " ") == "" {
		cfgFile = os.Getenv(cfgFileEnv)
		if strings.Trim(cfgFile, " ") == "" {
			cfgFile = defaultCfgFile
		}
	}
	return config.ParseConfig(cfgFile)
}
Exemple #2
0
func (d *dnetConnection) parseConfig(cfgFile string) (*config.Config, error) {
	if strings.Trim(cfgFile, " ") == "" {
		cfgFile = os.Getenv(cfgFileEnv)
		if strings.Trim(cfgFile, " ") == "" {
			cfgFile = defaultCfgFile
		}
	}

	if err := d.parseOrchestrationConfig(cfgFile); err != nil {
		return nil, err
	}
	return config.ParseConfig(cfgFile)
}
func (c *controller) initConfig(configFile string) error {
	cfgFile := configFile
	if strings.Trim(cfgFile, " ") == "" {
		cfgFile = os.Getenv(cfgFileEnv)
		if strings.Trim(cfgFile, " ") == "" {
			cfgFile = defaultCfgFile
		}
	}
	cfg, err := config.ParseConfig(cfgFile)
	if err != nil {
		return ErrInvalidConfigFile(cfgFile)
	}
	c.Lock()
	c.cfg = cfg
	c.Unlock()
	return nil
}
func TestBadDiscovery(t *testing.T) {
	_, err := net.Dial("tcp", "discovery-stage.hub.docker.com:80")
	if err != nil {
		t.Skip("Skipping Discovery test which need connectivity to discovery-stage.hub.docker.com")
	}

	hd := NewHostDiscovery()
	cfg := &config.Config{}
	cfg.Cluster.Discovery = ""
	err = hd.StartDiscovery(&cfg.Cluster, func(hosts []net.IP) {}, func(hosts []net.IP) {})
	if err == nil {
		t.Fatal("Invalid discovery configuration must fail")
	}
	cfg, err = config.ParseConfig("libnetwork.toml")
	if err != nil {
		t.Fatal(err)
	}
	cfg.Cluster.Address = "invalid"
	err = hd.StartDiscovery(&cfg.Cluster, func(hosts []net.IP) {}, func(hosts []net.IP) {})
	if err == nil {
		t.Fatal("Invalid discovery address configuration must fail")
	}
}
func TestDiscovery(t *testing.T) {
	_, err := net.Dial("tcp", "discovery-stage.hub.docker.com:80")
	if err != nil {
		t.Skip("Skipping Discovery test which need connectivity to discovery-stage.hub.docker.com")
	}

	hd := NewHostDiscovery()
	config, err := config.ParseConfig("libnetwork.toml")
	if err != nil {
		t.Fatal(err)
	}

	err = hd.StartDiscovery(&config.Cluster, func(hosts []net.IP) {}, func(hosts []net.IP) {})
	if err != nil {
		t.Fatal(err)
	}
	time.Sleep(time.Duration(config.Cluster.Heartbeat*2) * time.Second)
	hosts, err := hd.Fetch()
	if err != nil {
		t.Fatal(err)
	}

	found := false
	for _, ip := range hosts {
		if ip.Equal(net.ParseIP(config.Cluster.Address)) {
			found = true
		}
	}
	if !found {
		t.Fatalf("Expecting hosts. But none discovered ")
	}
	err = hd.StopDiscovery()
	if err != nil {
		t.Fatal(err)
	}
}