예제 #1
0
func TestSetServersNginx(t *testing.T) {
	if !nginxPrep() {
		t.SkipNow()
	}

	servers := []core.Server{testServer2}
	if err := balance.SetServers(testService1.Id, servers); err == nil {
		t.Errorf("Failed to fail SETTING servers - %v", err)
		t.FailNow()
	}

	balance.SetService(&testService1)

	if err := balance.SetServers(testService1.Id, servers); err != nil {
		t.Errorf("Failed to SET servers - %v", err)
		t.FailNow()
	}

	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer2)

	if service.Servers[0].Host != svc.Servers[0].Host {
		t.Errorf("Failed to clear old servers on PUT")
	}
}
예제 #2
0
파일: common.go 프로젝트: nanopack/portal
func SetServers(svcId string, servers []core.Server) error {
	// in case of failure
	oldService, err := database.GetService(svcId)
	if err != nil {
		return err
	}
	oldServers := oldService.Servers

	// implement in balancer
	err = balance.SetServers(svcId, servers)
	if err != nil {
		return err
	}

	if !database.CentralStore {
		// add to backend
		err = database.SetServers(svcId, servers)
		if err != nil {
			// undo balance action
			if uerr := balance.SetServers(svcId, oldServers); uerr != nil {
				err = fmt.Errorf("%v - %v", err.Error(), uerr.Error())
			}
			return err
		}
	}
	return nil
}
예제 #3
0
파일: lvs_test.go 프로젝트: nanopack/portal
func TestSetServers(t *testing.T) {
	if skip {
		t.SkipNow()
	}
	servers := []core.Server{}
	servers = append(servers, testServer2)
	if err := balance.SetServers(testService1.Id, servers); err != nil {
		t.Errorf("Failed to SET servers - %v", err)
		t.FailNow()
	}

	// todo: read from ipvsadm
	service, err := balance.GetService(testService1.Id)
	if err != nil {
		t.Error(err)
	}

	svc := testService1
	svc.Servers = append(svc.Servers, testServer2)

	if service.Servers[0].Host != svc.Servers[0].Host {
		t.Errorf("Failed to clear old servers on PUT")
	}
}