func TestDeleteServerNginx(t *testing.T) { if !nginxPrep() { t.SkipNow() } err := balance.DeleteServer("not-real-thing", testServer2.Id) if err == nil { t.Errorf("Failed to DELETE nonexistant server - %v", err) } balance.SetService(&testService1) err = balance.DeleteServer(testService1.Id, testServer2.Id) if err != nil { t.Errorf("Failed to DELETE nonexistant server - %v", err) } balance.SetServer(testService1.Id, &testServer2) err = balance.DeleteServer(testService1.Id, testServer2.Id) if err != nil { t.Errorf("Failed to DELETE server - %v", err) } // todo: read from ipvsadm service, err := balance.GetService(testService1.Id) if err != nil { t.Error(err) t.FailNow() } if service.Id != testService1.Id { t.Errorf("Read service differs from written service") } }
func DeleteServer(svcId, srvId string) error { // in case of failure srv, err := database.GetServer(svcId, srvId) if err != nil { if !strings.Contains(err.Error(), "No Server Found") { return err } } // delete rule from balancer if err = balance.DeleteServer(svcId, srvId); err != nil { if !strings.Contains(err.Error(), "No Server Found") { return err } } if !database.CentralStore { // remove from backend if err = database.DeleteServer(svcId, srvId); err != nil && !strings.Contains(err.Error(), "No Server Found") { // undo balance action if uerr := balance.SetServer(svcId, srv); uerr != nil { err = fmt.Errorf("%v - %v", err.Error(), uerr.Error()) } return err } } return nil }
func SetServer(svcId string, server *core.Server) error { // // idempotent additions (don't update server on post) // if srv, _ := database.GetServer(svcId, server.Id); srv != nil { // return nil // } // apply to balancer err := balance.SetServer(svcId, server) if err != nil { return err } if !database.CentralStore { // save to backend err = database.SetServer(svcId, server) if err != nil { // undo balance action if uerr := balance.DeleteServer(svcId, server.Id); uerr != nil { err = fmt.Errorf("%v - %v", err.Error(), uerr.Error()) } return err } } return nil }
func TestDeleteServer(t *testing.T) { if skip { t.SkipNow() } err := balance.DeleteServer(testService1.Id, testServer2.Id) if err != nil { t.Errorf("Failed to DELETE server - %v", err) } // todo: read from ipvsadm service, err := balance.GetService(testService1.Id) if err != nil { t.Error(err) t.FailNow() } if service.Id != testService1.Id { t.Errorf("Read service differs from written service") } }