Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1670 from endocode/dongsu/cleanup-error-method
Browse files Browse the repository at this point in the history
*: avoid using err.Error()
  • Loading branch information
Dongsu Park committed Aug 30, 2016
2 parents c3ec894 + dbc9102 commit fa5aa3a
Show file tree
Hide file tree
Showing 11 changed files with 203 additions and 37 deletions.
2 changes: 1 addition & 1 deletion api/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestMachinesListBadNextPageToken(t *testing.T) {

err = assertErrorResponse(rw, http.StatusBadRequest)
if err != nil {
t.Error(err.Error())
t.Error(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestUnitStateListBadNextPageToken(t *testing.T) {

err = assertErrorResponse(rw, http.StatusBadRequest)
if err != nil {
t.Error(err.Error())
t.Error(err)
}
}

Expand Down
2 changes: 1 addition & 1 deletion api/units_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestUnitsListBadNextPageToken(t *testing.T) {

err = assertErrorResponse(rw, http.StatusBadRequest)
if err != nil {
t.Error(err.Error())
t.Error(err)
}
}

Expand Down
34 changes: 18 additions & 16 deletions engine/rpcengine.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 CoreOS, Inc.
// Copyright 2016 The fleet Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -16,9 +16,10 @@ package engine

import (
"errors"
"strings"
"time"

etcdErr "github.com/coreos/etcd/error"

"github.com/coreos/fleet/log"
"github.com/coreos/fleet/machine"
"github.com/coreos/fleet/pkg/lease"
Expand Down Expand Up @@ -145,22 +146,23 @@ func rpcAcquireLeadership(reg registry.Registry, lManager lease.Manager, machID

func rpcRenewLeadership(lManager lease.Manager, l lease.Lease, ver int, ttl time.Duration) lease.Lease {
err := l.Renew(ttl)
if err != nil && strings.Contains(err.Error(), "Key not found") {
log.Errorf("Retry renew etcd operation that failed due to %v", err)
l, err = lManager.AcquireLease(engineLeaseName, l.MachineID(), ver, ttl)
if err != nil {
log.Errorf("Engine leadership re-acquisition failed: %v", err)
return nil
} else if l == nil {
log.Infof("Unable to re-acquire engine leadership")
if err != nil {
if eerr, ok := err.(*etcdErr.Error); ok && eerr.ErrorCode == etcdErr.EcodeKeyNotFound {
log.Errorf("Retry renew etcd operation that failed due to %v", err)
l, err = lManager.AcquireLease(engineLeaseName, l.MachineID(), ver, ttl)
if err != nil {
log.Errorf("Engine leadership re-acquisition failed: %v", err)
return nil
} else if l == nil {
log.Infof("Unable to re-acquire engine leadership")
return nil
}
log.Infof("Engine leadership re-acquired")
return l
} else {
log.Errorf("Engine leadership lost, renewal failed: %v", err)
return nil
}
log.Infof("Engine leadership re-acquired")
return l

} else if err != nil {
log.Errorf("Engine leadership lost, renewal failed: %v", err)
return nil
}

log.Debugf("Engine leadership renewed")
Expand Down
8 changes: 4 additions & 4 deletions fleetd/fleetd.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ func main() {
globalconf.Register("", cfgset)
cfg, err := getConfig(cfgset, *cfgPath)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

log.Debugf("Creating Server")
srv, err := server.New(*cfg, nil)
if err != nil {
log.Fatalf("Failed creating Server: %v", err.Error())
log.Fatalf("Failed creating Server: %v", err)
}
srv.Run()

Expand All @@ -120,7 +120,7 @@ func main() {

cfg, err := getConfig(cfgset, *cfgPath)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

log.Infof("Restarting server components")
Expand All @@ -135,7 +135,7 @@ func main() {
// The new server takes the original listeners.
srv, err = server.New(*cfg, oldListeners)
if err != nil {
log.Fatalf(err.Error())
log.Fatal(err)
}

srv.Run()
Expand Down
8 changes: 4 additions & 4 deletions functional/systemd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,22 +75,22 @@ ExecStart=/usr/bin/sleep 3000

err = waitForUnitState(mgr, name, unit.UnitState{"loaded", "inactive", "dead", "", hash, ""})
if err != nil {
t.Error(err.Error())
t.Error(err)
}

err = mgr.TriggerStart(name)
if err != nil {
t.Error(err.Error())
t.Error(err)
}

err = waitForUnitState(mgr, name, unit.UnitState{"loaded", "active", "running", "", hash, ""})
if err != nil {
t.Error(err.Error())
t.Error(err)
}

err = mgr.TriggerStop(name)
if err != nil {
t.Error(err.Error())
t.Error(err)
}

mgr.Unload(name)
Expand Down
1 change: 1 addition & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import:
- package: github.com/coreos/etcd
subpackages:
- client
- error
- package: github.com/coreos/go-semver
subpackages:
- semver
Expand Down
6 changes: 3 additions & 3 deletions pkg/filesystem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ import (
func TestListDirectory(t *testing.T) {
dir, err := ioutil.TempDir("", "fleet-testing-")
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}

defer os.RemoveAll(dir)

for _, name := range []string{"ping", "pong", "foo", "bar", "baz"} {
err := ioutil.WriteFile(path.Join(dir, name), []byte{}, 0400)
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}
}

Expand All @@ -43,7 +43,7 @@ func TestListDirectory(t *testing.T) {

got, err := ListDirectory(dir, filterFunc)
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}

want := []string{"baz", "ping", "pong"}
Expand Down
14 changes: 7 additions & 7 deletions systemd/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func TestHashUnitFile(t *testing.T) {
f, err := ioutil.TempFile("", "fleet-testing-")
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}

defer os.Remove(f.Name())
Expand All @@ -36,16 +36,16 @@ ExecStart=/usr/bin/sleep infinity
`

if _, err := f.Write([]byte(contents)); err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}

if err := f.Close(); err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}

hash, err := hashUnitFile(f.Name())
if err != nil {
t.Fatalf(err.Error())
t.Fatal(err)
}

want := "40ea6646945809f4b420a50475ee68503088f127"
Expand All @@ -58,7 +58,7 @@ ExecStart=/usr/bin/sleep infinity
func TestHashUnitFileDirectory(t *testing.T) {
dir, err := ioutil.TempDir("", "fleet-testing-")
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}

defer os.RemoveAll(dir)
Expand Down Expand Up @@ -88,13 +88,13 @@ func TestHashUnitFileDirectory(t *testing.T) {
for _, f := range fixtures {
err := ioutil.WriteFile(path.Join(dir, f.name), []byte(f.contents), 0400)
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}
}

hashes, err := hashUnitFiles(dir)
if err != nil {
t.Fatal(err.Error())
t.Fatal(err)
}

got := make(map[string]string, len(hashes))
Expand Down
Loading

0 comments on commit fa5aa3a

Please sign in to comment.