Skip to content

Commit

Permalink
iscsi library fixes based on the csi-driver-iscsi
Browse files Browse the repository at this point in the history
Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Sep 5, 2022
1 parent 366f319 commit 8566b12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion iscsi/iscsi.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ func writeInSCSIDeviceFile(hctl string, file string, content string) error {
filename := filepath.Join("/sys/class/scsi_device", hctl, "device", file)
debug.Printf("Write %q in %q.\n", content, filename)

f, err := osOpenFile(filename, os.O_TRUNC|os.O_WRONLY, 0200)
f, err := osOpenFile(filename, os.O_TRUNC|os.O_WRONLY, 0o200)
if err != nil {
debug.Printf("Error while opening file %v: %v\n", filename, err)
return err
Expand Down
18 changes: 11 additions & 7 deletions iscsi/iscsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,19 +95,23 @@ node.conn[0].iscsi.OFMarker = No
# END RECORD
`

const emptyTransportName = "iface.transport_name = \n"
const emptyDbRecord = "\n\n\n"
const testRootFS = "/tmp/iscsi-tests"
const (
emptyTransportName = "iface.transport_name = \n"
emptyDbRecord = "\n\n\n"
testRootFS = "/tmp/iscsi-tests"
)

func makeFakeExecCommand(exitStatus int, stdout string) func(string, ...string) *exec.Cmd {
return func(command string, args ...string) *exec.Cmd {
cs := []string{"-test.run=TestExecCommandHelper", "--", command}
cs = append(cs, args...)
cmd := exec.Command(os.Args[0], cs...)
es := strconv.Itoa(exitStatus)
cmd.Env = []string{"GO_WANT_HELPER_PROCESS=1",
cmd.Env = []string{
"GO_WANT_HELPER_PROCESS=1",
"STDOUT=" + stdout,
"EXIT_STATUS=" + es}
"EXIT_STATUS=" + es,
}
return cmd
}
}
Expand Down Expand Up @@ -165,7 +169,7 @@ func preparePaths(devices []Device) error {
}

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

ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0600)
ioutil.WriteFile("/tmp/connector.json", []byte("not a connector"), 0o600)
_, err = GetConnectorFromFile("/tmp/connector.json")
assert.NotNil(err)
assert.IsType(&json.SyntaxError{}, err)
Expand Down
17 changes: 10 additions & 7 deletions iscsi/iscsiadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func CreateDBEntry(tgtIQN, portal, iFace string, discoverySecrets, sessionSecret
}

return err

}

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

_, err = iscsiCmd(append(baseArgs, []string{"--discover"}...)...)
if err != nil {
//delete the discoverydb record
// delete the discoverydb record
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", tp, err)
}
Expand All @@ -111,10 +110,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error
args := []string{}
debug.Printf("Begin createCHAPEntries (discovery=%t)...", discovery)
if discovery {
args = append(baseArgs, []string{"-o", "update",
args = append(baseArgs, []string{
"-o", "update",
"-n", "discovery.sendtargets.auth.authmethod", "-v", "CHAP",
"-n", "discovery.sendtargets.auth.username", "-v", secrets.UserName,
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password}...)
"-n", "discovery.sendtargets.auth.password", "-v", secrets.Password,
}...)
if secrets.UserNameIn != "" {
args = append(args, []string{"-n", "discovery.sendtargets.auth.username_in", "-v", secrets.UserNameIn}...)
}
Expand All @@ -124,10 +125,12 @@ func createCHAPEntries(baseArgs []string, secrets Secrets, discovery bool) error

} else {

args = append(baseArgs, []string{"-o", "update",
args = append(baseArgs, []string{
"-o", "update",
"-n", "node.session.auth.authmethod", "-v", "CHAP",
"-n", "node.session.auth.username", "-v", secrets.UserName,
"-n", "node.session.auth.password", "-v", secrets.Password}...)
"-n", "node.session.auth.password", "-v", secrets.Password,
}...)
if secrets.UserNameIn != "" {
args = append(args, []string{"-n", "node.session.auth.username_in", "-v", secrets.UserNameIn}...)
}
Expand Down Expand Up @@ -156,7 +159,7 @@ func Login(tgtIQN, portal string) error {
debug.Println("Begin Login...")
baseArgs := []string{"-m", "node", "-T", tgtIQN, "-p", portal}
if _, err := iscsiCmd(append(baseArgs, []string{"-l"}...)...); err != nil {
//delete the node record from database
// delete the node record from database
iscsiCmd(append(baseArgs, []string{"-o", "delete"}...)...)
return fmt.Errorf("failed to sendtargets to portal %s, err: %v", portal, err)
}
Expand Down
1 change: 0 additions & 1 deletion iscsi/iscsiadm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ func TestCreateDBEntry(t *testing.T) {
}
})
}

}

func TestListInterfaces(t *testing.T) {
Expand Down

0 comments on commit 8566b12

Please sign in to comment.