Skip to content

Commit 7f4f7cc

Browse files
authored
Merge pull request #39 from humblec/new-changes
iscsi library fixes based on the csi-driver-iscsi
2 parents c7bdbc5 + 8566b12 commit 7f4f7cc

File tree

4 files changed

+22
-16
lines changed

4 files changed

+22
-16
lines changed

iscsi/iscsi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func writeInSCSIDeviceFile(hctl string, file string, content string) error {
582582
filename := filepath.Join("/sys/class/scsi_device", hctl, "device", file)
583583
debug.Printf("Write %q in %q.\n", content, filename)
584584

585-
f, err := osOpenFile(filename, os.O_TRUNC|os.O_WRONLY, 0200)
585+
f, err := osOpenFile(filename, os.O_TRUNC|os.O_WRONLY, 0o200)
586586
if err != nil {
587587
debug.Printf("Error while opening file %v: %v\n", filename, err)
588588
return err

iscsi/iscsi_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,19 +95,23 @@ node.conn[0].iscsi.OFMarker = No
9595
# END RECORD
9696
`
9797

98-
const emptyTransportName = "iface.transport_name = \n"
99-
const emptyDbRecord = "\n\n\n"
100-
const testRootFS = "/tmp/iscsi-tests"
98+
const (
99+
emptyTransportName = "iface.transport_name = \n"
100+
emptyDbRecord = "\n\n\n"
101+
testRootFS = "/tmp/iscsi-tests"
102+
)
101103

102104
func makeFakeExecCommand(exitStatus int, stdout string) func(string, ...string) *exec.Cmd {
103105
return func(command string, args ...string) *exec.Cmd {
104106
cs := []string{"-test.run=TestExecCommandHelper", "--", command}
105107
cs = append(cs, args...)
106108
cmd := exec.Command(os.Args[0], cs...)
107109
es := strconv.Itoa(exitStatus)
108-
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1",
110+
cmd.Env = []string{
111+
"GO_WANT_HELPER_PROCESS=1",
109112
"STDOUT=" + stdout,
110-
"EXIT_STATUS=" + es}
113+
"EXIT_STATUS=" + es,
114+
}
111115
return cmd
112116
}
113117
}
@@ -165,7 +169,7 @@ func preparePaths(devices []Device) error {
165169
}
166170

167171
for _, filename := range []string{"delete", "state"} {
168-
if err := ioutil.WriteFile(filepath.Join(devicePath, filename), []byte(""), 0600); err != nil {
172+
if err := ioutil.WriteFile(filepath.Join(devicePath, filename), []byte(""), 0o600); err != nil {
169173
return err
170174
}
171175
}
@@ -735,7 +739,7 @@ func TestConnectorPersistance(t *testing.T) {
735739
assert.NotNil(err)
736740
assert.IsType(&os.PathError{}, err)
737741

738-
ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0600)
742+
ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0o600)
739743
_, err = GetConnectorFromFile("/tmp/connector.json")
740744
assert.NotNil(err)
741745
assert.IsType(&json.SyntaxError{}, err)

iscsi/iscsiadm.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ func CreateDBEntry(tgtIQN, portal, iFace string, discoverySecrets, sessionSecret
8080
}
8181

8282
return err
83-
8483
}
8584

8685
// Discoverydb discovers the iscsi target
@@ -100,7 +99,7 @@ func Discoverydb(tp, iface string, discoverySecrets Secrets, chapDiscovery bool)
10099

101100
_, err = iscsiCmd(append(baseArgs, []string{"--discover"}...)...)
102101
if err != nil {
103-
//delete the discoverydb record
102+
// delete the discoverydb record
104103
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
105104
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", tp, err)
106105
}
@@ -111,10 +110,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error
111110
args := []string{}
112111
debug.Printf("Begin createCHAPEntries (discovery=%t)...", discovery)
113112
if discovery {
114-
args = append(baseArgs, []string{"-o", "update",
113+
args = append(baseArgs, []string{
114+
"-o", "update",
115115
"-n", "discovery.sendtargets.auth.authmethod", "-v", "CHAP",
116116
"-n", "discovery.sendtargets.auth.username", "-v", secrets.UserName,
117-
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password}...)
117+
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password,
118+
}...)
118119
if secrets.UserNameIn != "" {
119120
args = append(args, []string{"-n", "discovery.sendtargets.auth.username_in", "-v", secrets.UserNameIn}...)
120121
}
@@ -124,10 +125,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error
124125

125126
} else {
126127

127-
args = append(baseArgs, []string{"-o", "update",
128+
args = append(baseArgs, []string{
129+
"-o", "update",
128130
"-n", "node.session.auth.authmethod", "-v", "CHAP",
129131
"-n", "node.session.auth.username", "-v", secrets.UserName,
130-
"-n", "node.session.auth.password", "-v", secrets.Password}...)
132+
"-n", "node.session.auth.password", "-v", secrets.Password,
133+
}...)
131134
if secrets.UserNameIn != "" {
132135
args = append(args, []string{"-n", "node.session.auth.username_in", "-v", secrets.UserNameIn}...)
133136
}
@@ -156,7 +159,7 @@ func Login(tgtIQN, portal string) error {
156159
debug.Println("Begin Login...")
157160
baseArgs := []string{"-m", "node", "-T", tgtIQN, "-p", portal}
158161
if _, err := iscsiCmd(append(baseArgs, []string{"-l"}...)...); err != nil {
159-
//delete the node record from database
162+
// delete the node record from database
160163
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
161164
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", portal, err)
162165
}

iscsi/iscsiadm_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ func TestCreateDBEntry(t *testing.T) {
185185
}
186186
})
187187
}
188-
189188
}
190189

191190
func TestListInterfaces(t *testing.T) {

0 commit comments

Comments
 (0)