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") } }
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 }
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") } }