Skip to content

Commit

Permalink
Specify type when printing output
Browse files Browse the repository at this point in the history
  • Loading branch information
glinton committed Jan 24, 2017
1 parent 55d36bd commit 50a352d
Show file tree
Hide file tree
Showing 29 changed files with 415 additions and 413 deletions.
2 changes: 1 addition & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func parseBody(req *http.Request, v interface{}) error {
// read the body
b, err := ioutil.ReadAll(req.Body)
if err != nil {
config.Log.Error(err.Error())
config.Log.Error("Failed to read body - %s", err)
return BodyReadFail
}
defer req.Body.Close()
Expand Down
20 changes: 10 additions & 10 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ func TestPostCert(t *testing.T) {
var cert core.CertBundle
err = json.Unmarshal(resp, &cert)
if err != nil {
t.Errorf("Failed to POST cert - %v", err)
t.Errorf("Failed to POST cert - %s", err)
}
// bad request test
resp, err = rest("POST", "/certs", "[{\"key\":\"test.comma\", \"cert\": 1}]")
Expand Down Expand Up @@ -547,7 +547,7 @@ func rest(method, route, data string) ([]byte, error) {

res, err := http.DefaultClient.Do(req)
if err != nil {
return nil, fmt.Errorf("Unable to %v %v - %v", method, route, err)
return nil, fmt.Errorf("Unable to %s %s - %s", method, route, err)
}
defer res.Body.Close()

Expand All @@ -568,37 +568,37 @@ func initialize() {
config.RouteTls = "0.0.0.0:9443"
config.Log = lumber.NewConsoleLogger(lumber.LvlInt("FATAL"))
config.LogLevel = "FATAL"
apiAddr = fmt.Sprintf("%v:%v", config.ApiHost, config.ApiPort)
apiAddr = fmt.Sprintf("%s:%s", config.ApiHost, config.ApiPort)

// initialize database
err := database.Init()
if err != nil {
fmt.Printf("Database init failed - %v\n", err)
fmt.Printf("Database init failed - %s\n", err)
os.Exit(1)
}
// initialize balancer
balance.Balancer = &database.ScribbleDatabase{}
err = balance.Balancer.Init()
if err != nil {
fmt.Printf("Balancer init failed - %v\n", err)
fmt.Printf("Balancer init failed - %s\n", err)
os.Exit(1)
}
// initialize proxymgr
err = proxymgr.Init()
if err != nil {
fmt.Printf("Proxymgr init failed - %v\n", err)
fmt.Printf("Proxymgr init failed - %s\n", err)
os.Exit(1)
}
// initialize vipmgr
err = vipmgr.Init()
if err != nil {
fmt.Printf("Vipmgr init failed - %v\n", err)
fmt.Printf("Vipmgr init failed - %s\n", err)
os.Exit(1)
}
// initialize clusterer
err = cluster.Init()
if err != nil {
fmt.Printf("Clusterer init failed - %v\n", err)
fmt.Printf("Clusterer init failed - %s\n", err)
os.Exit(1)
}
// load saved rules
Expand All @@ -607,14 +607,14 @@ func initialize() {
// if error is not about a missing db, continue
if !strings.Contains(err.Error(), "Found") {
// todo: this requires backends to return NoServiceError in GetServices
fmt.Printf("Get services from backend failed - %v\n", err)
fmt.Printf("Get services from backend failed - %s\n", err)
os.Exit(1)
}
}
// apply saved rules
err = balance.Balancer.SetServices(services)
if err != nil {
fmt.Printf("Balancer sync failed - %v\n", err)
fmt.Printf("Balancer sync failed - %s\n", err)
os.Exit(1)
}
}
2 changes: 1 addition & 1 deletion api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func parseReqServer(req *http.Request) (*core.Server, error) {
b, err := ioutil.ReadAll(req.Body)
if err != nil {
config.Log.Error(err.Error())
config.Log.Error("Failed to read body - %s", err)
return nil, BodyReadFail
}

Expand Down
2 changes: 1 addition & 1 deletion api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func parseReqService(req *http.Request) (*core.Service, error) {
b, err := ioutil.ReadAll(req.Body)
if err != nil {
config.Log.Error(err.Error())
config.Log.Error("Failed to read body - %s", err)
return nil, BodyReadFail
}

Expand Down
10 changes: 5 additions & 5 deletions balance/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Init() error {
}
// don't break if we can't use iptables
if _, err = tab.List("filter", "INPUT"); err != nil {
config.Log.Error("Could not use iptables, continuing without - %v", err)
config.Log.Error("Could not use iptables, continuing without - %s", err)
tab = nil
}
if tab != nil {
Expand All @@ -55,15 +55,15 @@ func Init() error {
tab.DeleteChain("filter", "portal")
err = tab.NewChain("filter", "portal")
if err != nil {
return fmt.Errorf("Failed to create new chain - %v", err)
return fmt.Errorf("Failed to create new chain - %s", err)
}
err = tab.AppendUnique("filter", "portal", "-j", "RETURN")
if err != nil {
return fmt.Errorf("Failed to append to portal chain - %v", err)
return fmt.Errorf("Failed to append to portal chain - %s", err)
}
err = tab.AppendUnique("filter", "INPUT", "-j", "portal")
if err != nil {
return fmt.Errorf("Failed to append to INPUT chain - %v", err)
return fmt.Errorf("Failed to append to INPUT chain - %s", err)
}

// Allow router through by default (ports 80/443)
Expand Down Expand Up @@ -110,7 +110,7 @@ func SetServices(services []core.Service) error {
tab.ClearChain("filter", "portal")
tab.DeleteChain("filter", "portal")
tab.RenameChain("filter", "portal-old", "portal")
return fmt.Errorf("Failed to tab.Insert() - %v", err.Error())
return fmt.Errorf("Failed to tab.Insert() - %s", err)
}

tab.NewChain("filter", "portal")
Expand Down
12 changes: 6 additions & 6 deletions balance/lvs.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func (l *Lvs) SetServers(svcId string, servers []core.Server) error {

for _, isrv := range s.Servers {
if err = s.RemoveServer(isrv.Host, isrv.Port); err != nil {
return fmt.Errorf("[ipvsadm] Failed to remove server - %v:%v; %v", isrv.Host, isrv.Port, err.Error())
return fmt.Errorf("[ipvsadm] Failed to remove server - %s:%d; %s", isrv.Host, isrv.Port, err)
}
}
for _, lsrv := range lvsServers {
if err = s.AddServer(lsrv); err != nil {
return fmt.Errorf("[ipvsadm] Failed to add server - %v:%v; %v", lsrv.Host, lsrv.Port, err.Error())
return fmt.Errorf("[ipvsadm] Failed to add server - %s:%d; %s", lsrv.Host, lsrv.Port, err)
}
}
return nil
Expand Down Expand Up @@ -235,11 +235,11 @@ func (l *Lvs) SetServices(services []core.Service) error {

err := lvs.Clear()
if err != nil {
return fmt.Errorf("Failed to lvs.Clear() - %v", err.Error())
return fmt.Errorf("Failed to lvs.Clear() - %s", err)
}
err = lvs.Restore(lvsServices)
if err != nil {
return fmt.Errorf("Failed to lvs.Restore() - %v", err.Error())
return fmt.Errorf("Failed to lvs.Restore() - %s", err)
}
return nil
}
Expand All @@ -260,7 +260,7 @@ func Sync() error {
// if tab != nil {
// tab.RenameChain("filter", "portal-old", "portal")
// }
return fmt.Errorf("Failed to lvs.Save() - %v", err.Error())
return fmt.Errorf("Failed to lvs.Save() - %s", err)
}

// lvsServices := lvs.DefaultIpvs.Services
Expand All @@ -275,7 +275,7 @@ func Sync() error {
// tab.ClearChain("filter", "portal")
// tab.DeleteChain("filter", "portal")
// tab.RenameChain("filter", "portal-old", "portal")
// return fmt.Errorf("Failed to tab.Insert() - %v", err.Error())
// return fmt.Errorf("Failed to tab.Insert() - %s", err)
// }
// }
// tab.AppendUnique("filter", "INPUT", "-j", "portal")
Expand Down
30 changes: 15 additions & 15 deletions balance/lvs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestSetService(t *testing.T) {
t.SkipNow()
}
if err := balance.SetService(&testService1); err != nil {
t.Errorf("Failed to SET service - %v", err)
t.Errorf("Failed to SET service - %s", err)
t.FailNow()
}

Expand All @@ -65,12 +65,12 @@ func TestSetServices(t *testing.T) {
services = append(services, testService2)

if err := balance.SetServices(services); err != nil {
t.Errorf("Failed to SET services - %v", err)
t.Errorf("Failed to SET services - %s", err)
t.FailNow()
}

if _, err := os.Stat("/tmp/scribbleTest/services/tcp-192_168_0_15-80.json"); !os.IsNotExist(err) {
t.Errorf("Failed to clear old services on PUT - %v", err)
t.Errorf("Failed to clear old services on PUT - %s", err)
}

// todo: read from ipvsadm
Expand All @@ -90,7 +90,7 @@ func TestGetServices(t *testing.T) {
}
services, err := balance.GetServices()
if err != nil {
t.Errorf("Failed to GET services - %v", err)
t.Errorf("Failed to GET services - %s", err)
t.FailNow()
}

Expand All @@ -105,7 +105,7 @@ func TestGetService(t *testing.T) {
}
service, err := balance.GetService(testService2.Id)
if err != nil {
t.Errorf("Failed to GET service - %v", err)
t.Errorf("Failed to GET service - %s", err)
t.FailNow()
}

Expand All @@ -119,7 +119,7 @@ func TestDeleteService(t *testing.T) {
t.SkipNow()
}
if err := balance.DeleteService(testService2.Id); err != nil {
t.Errorf("Failed to GET service - %v", err)
t.Errorf("Failed to GET service - %s", err)
}

// todo: read from ipvsadm
Expand All @@ -138,7 +138,7 @@ func TestSetServer(t *testing.T) {
}
balance.SetService(&testService1)
if err := balance.SetServer(testService1.Id, &testServer1); err != nil {
t.Errorf("Failed to SET server - %v", err)
t.Errorf("Failed to SET server - %s", err)
t.FailNow()
}

Expand All @@ -163,7 +163,7 @@ func TestSetServers(t *testing.T) {
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.Errorf("Failed to SET servers - %s", err)
t.FailNow()
}

Expand All @@ -187,7 +187,7 @@ func TestGetServers(t *testing.T) {
}
service, err := balance.GetService(testService1.Id)
if err != nil {
t.Errorf("Failed to GET service - %v", err)
t.Errorf("Failed to GET service - %s", err)
t.FailNow()
}

Expand All @@ -202,7 +202,7 @@ func TestGetServer(t *testing.T) {
}
server, err := balance.GetServer(testService1.Id, testServer2.Id)
if err != nil {
t.Errorf("Failed to GET server - %v", err)
t.Errorf("Failed to GET server - %s", err)
t.FailNow()
}

Expand All @@ -217,7 +217,7 @@ func TestDeleteServer(t *testing.T) {
}
err := balance.DeleteServer(testService1.Id, testServer2.Id)
if err != nil {
t.Errorf("Failed to DELETE server - %v", err)
t.Errorf("Failed to DELETE server - %s", err)
}

// todo: read from ipvsadm
Expand Down Expand Up @@ -246,12 +246,12 @@ func toJson(v interface{}) ([]byte, error) {
func initialize() {
ifIptables, err := exec.Command("iptables", "-S").CombinedOutput()
if err != nil {
fmt.Printf("Failed to run iptables - %s%v\n", ifIptables, err.Error())
fmt.Printf("Failed to run iptables - %s%s\n", ifIptables, err)
skip = true
}
ifIpvsadm, err := exec.Command("ipvsadm", "--version").CombinedOutput()
if err != nil {
fmt.Printf("Failed to run ipvsadm - %s%v\n", ifIpvsadm, err.Error())
fmt.Printf("Failed to run ipvsadm - %s%s\n", ifIpvsadm, err)
skip = true
}

Expand All @@ -261,12 +261,12 @@ func initialize() {
// todo: find more friendly way to clear crufty rules only
err = exec.Command("iptables", "-F", "portal").Run()
if err != nil {
fmt.Printf("Failed to clear iptables - %v\n", err.Error())
fmt.Printf("Failed to clear iptables - %s\n", err)
os.Exit(1)
}
err = exec.Command("ipvsadm", "-C").Run()
if err != nil {
fmt.Printf("Failed to clear ipvsadm - %v\n", err.Error())
fmt.Printf("Failed to clear ipvsadm - %s\n", err)
os.Exit(1)
}

Expand Down
10 changes: 5 additions & 5 deletions balance/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (n *Nginx) Init() error {
// ensure config location exists
err := os.MkdirAll(config.WorkDir, 0755)
if err != nil {
return fmt.Errorf("Failed to create working directory - %v", err)
return fmt.Errorf("Failed to create working directory - %s", err)
}
n.configFile = path.Join(config.WorkDir, "portal-nginx.conf")
primerConfig := path.Join(config.WorkDir, "portal-nginx-primer.conf")
Expand All @@ -42,13 +42,13 @@ func (n *Nginx) Init() error {
// read config file and save as primer (first run generally)
cfg, err = ioutil.ReadFile(n.configFile)
if err != nil {
return fmt.Errorf("Failed to read a config file - %v", err)
return fmt.Errorf("Failed to read a config file - %s", err)
}

// persist primer config
err = ioutil.WriteFile(primerConfig, cfg, 0644)
if err != nil {
return fmt.Errorf("Failed to write primer config - %v", err)
return fmt.Errorf("Failed to write primer config - %s", err)
}
}

Expand Down Expand Up @@ -288,13 +288,13 @@ stream {
cfgFile, err := os.Create(n.configFile)
defer cfgFile.Close()
if err != nil {
return fmt.Errorf("Failed to create config file - %v", err)
return fmt.Errorf("Failed to create config file - %s", err)
}

// execute the template
err = t.ExecuteTemplate(cfgFile, "nginxConfig", n.Services)
if err != nil {
return fmt.Errorf("Failed to generate config file - %v", err)
return fmt.Errorf("Failed to generate config file - %s", err)
}

// reload nginx
Expand Down
Loading

0 comments on commit 50a352d

Please sign in to comment.