Skip to content

Commit 481fff2

Browse files
authored
Merge pull request #44 from andyzhangx/fix-golint
cleanup: fix golint errors
2 parents 0ed912f + 8744a80 commit 481fff2

File tree

5 files changed

+22
-56
lines changed

5 files changed

+22
-56
lines changed

.github/workflows/shellcheck.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

iscsi/iscsi.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ func (c *Connector) Connect() (string, error) {
283283
}
284284

285285
if len(c.Devices) < 1 {
286-
iscsiCmd([]string{"-m", "iface", "-I", iFace, "-o", "delete"}...)
286+
_, _ = iscsiCmd([]string{"-m", "iface", "-I", iFace, "-o", "delete"}...)
287287
return "", fmt.Errorf("failed to find device path: %s, last error seen: %v", devicePaths, lastErr)
288288
}
289289

@@ -679,11 +679,14 @@ func GetConnectorFromFile(filePath string) (*Connector, error) {
679679
if c.MountTargetDevice == nil {
680680
return nil, fmt.Errorf("mountTargetDevice in the connector is nil")
681681
}
682-
if devices, err := GetSCSIDevices([]string{c.MountTargetDevice.GetPath()}, false); err != nil {
682+
devices, err := GetSCSIDevices([]string{c.MountTargetDevice.GetPath()}, false)
683+
if err != nil {
683684
return nil, err
684-
} else {
685-
c.MountTargetDevice = &devices[0]
686685
}
686+
if len(devices) == 0 {
687+
return nil, fmt.Errorf("mountTargetDevice %s not found", c.MountTargetDevice.GetPath())
688+
}
689+
c.MountTargetDevice = &devices[0]
687690

688691
if c.Devices, err = GetSCSIDevices(devicePaths, false); err != nil {
689692
return nil, err

iscsi/iscsi_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,9 @@ func Test_DisconnectNormalVolume(t *testing.T) {
322322
for _, tt := range tests {
323323
t.Run(tt.name, func(t *testing.T) {
324324
if tt.withDeviceFile {
325-
os.Create(deleteDeviceFile)
325+
_, _ = os.Create(deleteDeviceFile)
326326
} else {
327-
os.RemoveAll(testRootFS)
327+
_ = os.RemoveAll(testRootFS)
328328
}
329329

330330
device := Device{Name: "test"}
@@ -723,7 +723,8 @@ func TestConnectorPersistance(t *testing.T) {
723723
return makeFakeExecCommand(0, string(mockedOutput))(cmd, args...)
724724
}).Reset()
725725

726-
c.Persist("/tmp/connector.json")
726+
err := c.Persist("/tmp/connector.json")
727+
assert.Nil(err)
727728
c2, err := GetConnectorFromFile("/tmp/connector.json")
728729
assert.Nil(err)
729730
assert.NotNil(c2)
@@ -739,7 +740,8 @@ func TestConnectorPersistance(t *testing.T) {
739740
assert.NotNil(err)
740741
assert.IsType(&os.PathError{}, err)
741742

742-
ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0o600)
743+
err = ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0o600)
744+
assert.Nil(err)
743745
_, err = GetConnectorFromFile("/tmp/connector.json")
744746
assert.NotNil(err)
745747
assert.IsType(&json.SyntaxError{}, err)

iscsi/iscsiadm.go

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,14 @@ func Discoverydb(tp, iface string, discoverySecrets Secrets, chapDiscovery bool)
100100
_, err = iscsiCmd(append(baseArgs, []string{"--discover"}...)...)
101101
if err != nil {
102102
// delete the discoverydb record
103-
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
103+
_, _ = iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
104104
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", tp, err)
105105
}
106106
return nil
107107
}
108108

109109
func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error {
110-
args := []string{}
110+
var args []string
111111
debug.Printf("Begin createCHAPEntries (discovery=%t)...", discovery)
112112
if discovery {
113113
args = append(baseArgs, []string{
@@ -122,9 +122,7 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error
122122
if secrets.PasswordIn != "" {
123123
args = append(args, []string{"-n", "discovery.sendtargets.auth.password_in", "-v", secrets.PasswordIn}...)
124124
}
125-
126125
} else {
127-
128126
args = append(baseArgs, []string{
129127
"-o", "update",
130128
"-n", "node.session.auth.authmethod", "-v", "CHAP",
@@ -160,7 +158,7 @@ func Login(tgtIQN, portal string) error {
160158
baseArgs := []string{"-m", "node", "-T", tgtIQN, "-p", portal}
161159
if _, err := iscsiCmd(append(baseArgs, []string{"-l"}...)...); err != nil {
162160
// delete the node record from database
163-
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
161+
_, _ = iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
164162
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", portal, err)
165163
}
166164
return nil
@@ -170,21 +168,21 @@ func Login(tgtIQN, portal string) error {
170168
func Logout(tgtIQN, portal string) error {
171169
debug.Println("Begin Logout...")
172170
args := []string{"-m", "node", "-T", tgtIQN, "-p", portal, "-u"}
173-
iscsiCmd(args...)
174-
return nil
171+
_, err := iscsiCmd(args...)
172+
return err
175173
}
176174

177175
// DeleteDBEntry deletes the iscsi db entry for the specified target
178176
func DeleteDBEntry(tgtIQN string) error {
179177
debug.Println("Begin DeleteDBEntry...")
180178
args := []string{"-m", "node", "-T", tgtIQN, "-o", "delete"}
181-
iscsiCmd(args...)
182-
return nil
179+
_, err := iscsiCmd(args...)
180+
return err
183181
}
184182

185183
// DeleteIFace delete the iface
186184
func DeleteIFace(iface string) error {
187185
debug.Println("Begin DeleteIFace...")
188-
iscsiCmd([]string{"-m", "iface", "-I", iface, "-o", "delete"}...)
189-
return nil
186+
_, err := iscsiCmd([]string{"-m", "iface", "-I", iface, "-o", "delete"}...)
187+
return err
190188
}

iscsi/multipath.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ import (
1010
"time"
1111
)
1212

13-
type pathGroup struct {
14-
Paths []path `json:"paths"`
15-
}
16-
17-
type path struct {
18-
Device string `json:"dev"`
19-
}
20-
2113
// ExecWithTimeout execute a command with a timeout and returns an error if timeout is exceeded
2214
func ExecWithTimeout(command string, args []string, timeout time.Duration) ([]byte, error) {
2315
debug.Printf("Executing command '%v' with args: '%v'.\n", command, args)

0 commit comments

Comments
 (0)