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

Commit

Permalink
Fix golint warnings
Browse files Browse the repository at this point in the history
Barring transaction subpackage which contains mainly generated code,
other subpackages have had their golint warnings fixed.

We would want to ensure that all new code adheres to golint.

Signed-off-by: Prashanth Pai <ppai@redhat.com>
  • Loading branch information
prashanthpai committed Oct 27, 2016
1 parent 94fecaa commit 259c841
Show file tree
Hide file tree
Showing 17 changed files with 83 additions and 53 deletions.
12 changes: 9 additions & 3 deletions brick/brick.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Brickinfo struct {
ID uuid.UUID
}

// Brick type represents information about the brick daemon
type Brick struct {
// Externally consumable using methods of Daemon interface
binarypath string
Expand All @@ -41,14 +42,17 @@ type Brick struct {
port int
}

// Name returns human-friendly name of the brick process. This is used for logging.
func (b *Brick) Name() string {
return "glusterfsd"
}

// Path returns absolute path to the binary of brick process
func (b *Brick) Path() string {
return b.binarypath
}

// Args returns arguments to be passed to brick process during spawn.
func (b *Brick) Args() string {
if b.args != "" {
return b.args
Expand Down Expand Up @@ -76,6 +80,7 @@ func (b *Brick) Args() string {
return b.args
}

// SocketFile returns path to the brick socket file used for IPC.
func (b *Brick) SocketFile() string {

if b.socketfilepath != "" {
Expand All @@ -93,13 +98,14 @@ func (b *Brick) SocketFile() string {

// Then md5sum of the above path shall be the name of socket file.
// Example: /var/run/gluster/<md5sum-hash>.socket
checksum_data := []byte(fakeSockFilePath)
checksumData := []byte(fakeSockFilePath)
glusterdSockDir := path.Join(config.GetString("rundir"), "gluster")
b.socketfilepath = fmt.Sprintf("%s/%x.socket", glusterdSockDir, md5.Sum(checksum_data))
b.socketfilepath = fmt.Sprintf("%s/%x.socket", glusterdSockDir, md5.Sum(checksumData))

return b.socketfilepath
}

// PidFile returns path to the pid file of the brick process
func (b *Brick) PidFile() string {

if b.pidfilepath != "" {
Expand All @@ -114,7 +120,7 @@ func (b *Brick) PidFile() string {
return b.pidfilepath
}

// Returns a new instance of Brick type which implements the Daemon interface
// NewDaemon returns a new instance of Brick type which implements the Daemon interface
func NewDaemon(volName string, binfo Brickinfo) (*Brick, error) {
brickObject := &Brick{binarypath: glusterfsd, brickinfo: binfo, volName: volName}
return brickObject, nil
Expand Down
7 changes: 4 additions & 3 deletions brick/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ const (
maxPort = 65535
)

// IsPortFree returns if the specified port is free or not.
func IsPortFree(port int) bool {
// TODO: Ports can be bound to specific interfaces. This function
// should be modified to take a IP/hostname arg as well.

conn, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
if err != nil {
return false
} else {
conn.Close()
return true
}
conn.Close()
return true
}

// GetNextAvailableFreePort returns the next available free port in the range minPort to maxPort
func GetNextAvailableFreePort() int {

var p int
Expand Down
15 changes: 10 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
const (
defaultLogLevel = "debug"
defaultRestAddress = ":24007"
defaultRpcAddress = ":24008"
defaultRpcPort = 24008
defaultRPCAddress = ":24008"
defaultRPCPort = 24008

defaultConfName = "glusterd"
)
Expand All @@ -35,15 +35,20 @@ func parseFlags() {
flag.String("config", "", "Configuration file for GlusterD. By default looks for glusterd.(yaml|toml|json) in /etc/glusterd and current working directory.")
flag.String("loglevel", defaultLogLevel, "Severity of messages to be logged.")
flag.String("restaddress", defaultRestAddress, "Address to bind the REST service.")
flag.String("rpcaddress", defaultRpcAddress, "Address to bind the RPC service.")
flag.String("rpcaddress", defaultRPCAddress, "Address to bind the RPC service.")

flag.Parse()
}

// setDefaults sets defaults values for config options not available as a flag,
// and flags which don't have default values
func setDefaults() {
cwd, _ := os.Getwd()
cwd, err := os.Getwd()
if err != nil {
log.WithFields(log.Fields{
"error": err,
}).Fatal("Failed to get current working directory.")
}

wd := config.GetString("workdir")
if wd == "" {
Expand All @@ -64,7 +69,7 @@ func setDefaults() {
}

// Set the default RpcPort will be used to connect to remote GlusterDs
config.SetDefault("rpcport", defaultRpcPort)
config.SetDefault("rpcport", defaultRPCPort)
}

func dumpConfigToLog() {
Expand Down
21 changes: 10 additions & 11 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,17 @@ func Start(d Daemon, wait bool) error {
// Wait for the process to exit
err = cmd.Wait()
return err
} else {
// If the process exits at some point later, do read it's
// exit status. This should not let it be a zombie.
go func() {
err := cmd.Wait()
log.WithFields(log.Fields{
"name": d.Name(),
"pid": cmd.Process.Pid,
"status": err,
}).Debug("Daemon died.")
}()
}
// If the process exits at some point later, do read it's
// exit status. This should not let it be a zombie.
go func() {
err := cmd.Wait()
log.WithFields(log.Fields{
"name": d.Name(),
"pid": cmd.Process.Pid,
"status": err,
}).Debug("Daemon died.")
}()

// Check if the daemon is running
// TODO: Need some form of waiting period or timeout here before
Expand Down
10 changes: 5 additions & 5 deletions etcdmgmt/etcd-mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func checkETCDHealth(val time.Duration, listenClientUrls string) bool {
return true
}

// StartETCD() is to bring up etcd instance
// StartETCD will bring up etcd instance
func StartETCD(args []string) (*os.Process, error) {
start, pid := isETCDStartNeeded()
if start == false {
Expand Down Expand Up @@ -264,7 +264,7 @@ func formETCDArgs() []string {
return args
}

// ETCDStartInit() Check whether etcd environment variable present or not
// ETCDStartInit checks whether etcd environment variable present or not
// If it present then start etcd without --initial-cluster flag
// other wise start etcd normally.
func ETCDStartInit() (*os.Process, error) {
Expand Down Expand Up @@ -313,7 +313,7 @@ func ETCDStartInit() (*os.Process, error) {
return nil, err
}

//StartStandAloneETCD() will Start default etcd by considering single server node
//StartStandAloneETCD will Start default etcd by considering single server node
func StartStandAloneETCD() (*os.Process, error) {
var args []string
if etcdClient == true {
Expand All @@ -329,7 +329,7 @@ func StartStandAloneETCD() (*os.Process, error) {
return StartETCD(args)
}

// StopETCD() will Stop etcd process on the node
// StopETCD will Stop etcd process on the node
func StopETCD(etcdCtx *os.Process) error {
err := etcdCtx.Kill()
if err != nil {
Expand All @@ -345,7 +345,7 @@ func StopETCD(etcdCtx *os.Process) error {
return nil
}

// ReStartETCD() will restart etcd process
// ReStartETCD will restart etcd process
func ReStartETCD() (*os.Process, error) {
// Stop etcd process
etcdCtx := gdctx.EtcdProcessCtx
Expand Down
1 change: 1 addition & 0 deletions gdctx/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
)

var (
// GlusterdVersion is the version of the glusterd daemon
GlusterdVersion = "4.0-dev"
)

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func main() {

// Store self information in the store if GlusterD is coming up for
// first time
if gdctx.Restart == false {
if gdctx.Restart {
peer.AddSelfDetails()
}

Expand Down
2 changes: 1 addition & 1 deletion peer/self.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func AddSelfDetails() {
}

for _, memb := range mlist {
for _, _ = range memb.PeerURLs {
for _ = range memb.PeerURLs {
if memb.Name == "default" {
memberID = memb.ID
break
Expand Down
19 changes: 11 additions & 8 deletions peer/store-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ const (
)

var (
GetPeerF = GetPeer
GetPeersF = GetPeers
GetPeerByAddrF = GetPeerByAddr
GetPeerByNameF = GetPeerByName
// GetPeerF returns specified peer from the store
GetPeerF = GetPeer
// GetPeersF returns all available peers in the store
GetPeersF = GetPeers
//GetPeerByAddrF returns the peer with the given address from the store
GetPeerByAddrF = GetPeerByAddr
// GetPeerByNameF returns the peer with the given name from store
GetPeerByNameF = GetPeerByName
//GetPeerIDByAddrF returns the ID of the peer with the given address
GetPeerIDByAddrF = GetPeerIDByAddr
)

Expand Down Expand Up @@ -60,8 +65,7 @@ func GetPeer(id string) (*Peer, error) {
return &p, nil
}

// GetInitialCluster() form and returns the etcd initial cluster value in a
// string
// GetInitialCluster forms and returns the etcd initial cluster value as a string
func GetInitialCluster() (string, error) {
var initialCluster string
peers, err := GetPeersF()
Expand Down Expand Up @@ -179,8 +183,7 @@ func GetPeerIDByAddr(addr string) (uuid.UUID, error) {
p, e := GetPeerByAddrF(addr)
if e != nil {
return nil, errors.ErrPeerNotFound
} else {
return p.ID, nil
}
return p.ID, nil

}
1 change: 1 addition & 0 deletions transaction/rpc-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"google.golang.org/grpc"
)

// RunStepOn will run the step on the specified node
func RunStepOn(step string, node uuid.UUID, c TxnCtx) (TxnCtx, error) {
// TODO: I'm creating connections on demand. This should be changed so that
// we have long term connections.
Expand Down
1 change: 1 addition & 0 deletions transaction/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Step struct {
}

var (
// ErrStepFuncNotFound is returned if the stepfunc isn't found.
ErrStepFuncNotFound = errors.New("StepFunc was not found")
)

Expand Down
18 changes: 11 additions & 7 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ const (
)

var (
PathMax = unix.PathMax
// PathMax calls unix.PathMax
PathMax = unix.PathMax
// Removexattr calls unix.Removexattr
Removexattr = unix.Removexattr
Setxattr = unix.Setxattr
Getxattr = unix.Getxattr
// Setxattr calls unix.Setxattr
Setxattr = unix.Setxattr
// Getxattr calls unix.Getxattr
Getxattr = unix.Getxattr
)

//PosixPathMax represents C's POSIX_PATH_MAX
Expand All @@ -43,8 +47,8 @@ const PosixPathMax = C._POSIX_PATH_MAX
// Does lookup only after string matching IP addresses
func IsLocalAddress(host string) (bool, error) {

local_names := []string{"127.0.0.1", "localhost", "::1"}
for _, name := range local_names {
localNames := []string{"127.0.0.1", "localhost", "::1"}
for _, name := range localNames {
if host == name {
return true, nil
}
Expand Down Expand Up @@ -333,7 +337,7 @@ func InitDir(dir string) {
defer t.Close()
}

// Function to check whether the process with given pid exist or not in the system
// CheckProcessExist will check whether the process with given pid exist or not in the system
func CheckProcessExist(pid int) bool {
out, err := exec.Command("kill", "-s", "0", strconv.Itoa(pid)).CombinedOutput()
if err != nil {
Expand All @@ -345,7 +349,7 @@ func CheckProcessExist(pid int) bool {
return false
}

// GetLocalIP() function will give local IP address of this node
// GetLocalIP will give local IP address of this node
func GetLocalIP() (string, error) {
addrs, err := net.InterfaceAddrs()
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,25 @@ func TestValidateXattrSupport(t *testing.T) {
tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == nil)

// Some negative tests
var xattr_err error
var xattrErr error
baderror := errors.New("Bad")
xattr_err = baderror
xattrErr = baderror

// Now check what happens when setxattr fails
defer heketitests.Patch(&Setxattr, func(path string, attr string, data []byte, flags int) (err error) {
return xattr_err
return xattrErr
}).Restore()
tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

// Now check what happens when getxattr fails
defer heketitests.Patch(&Getxattr, func(path string, attr string, dest []byte) (sz int, err error) {
return 0, xattr_err
return 0, xattrErr
}).Restore()
tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

// Now check what happens when removexattr fails
defer heketitests.Patch(&Removexattr, func(path string, attr string) (err error) {
return xattr_err
return xattrErr
}).Restore()
tests.Assert(t, ValidateXattrSupport("/tmp/b1", "localhost", uuid.NewRandom(), true) == baderror)

Expand Down
2 changes: 2 additions & 0 deletions utils/volumeutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import (
config "github.com/spf13/viper"
)

// GetVolumeDir returns path to volume directory
func GetVolumeDir(volumeName string) string {
return path.Join(config.GetString("localstatedir"), "vols", volumeName)
}

// GetBrickVolFilePath returns path to brick volfile
func GetBrickVolFilePath(volumeName string, brickHostName string, brickPath string) string {
volumeDir := GetVolumeDir(volumeName)
brickPathWithoutSlashes := strings.Replace(brickPath, "/", "-", -1)
Expand Down
1 change: 1 addition & 0 deletions volgen/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
)

var (
// GenerateVolfileFunc will do all task from graph generation to volfile generation
GenerateVolfileFunc = GenerateVolfile
)

Expand Down
Loading

0 comments on commit 259c841

Please sign in to comment.