Skip to content

Rename iscsi to iSCSI #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions integrationtests/iscsi_ps_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import (
"testing"
)

func installIscsiTarget() error {
_, err := runPowershellScript(IscsiTargetInstallScript)
func installISCSITarget() error {
_, err := runPowershellScript(iSCSITargetInstallScript)
if err != nil {
return fmt.Errorf("failed installing iSCSI target. err=%v", err)
}

return nil
}

const IscsiTargetInstallScript = `
const iSCSITargetInstallScript = `
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

Expand All @@ -30,12 +30,12 @@ Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\iSCSI Target" -Name AllowLoopBa
Restart-Service WinTarget
`

type IscsiSetupConfig struct {
type iSCSISetupConfig struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is different in Go, if it starts with uppercase then it's not exported in the package, with this change this becomes private to the package only, is this intended and ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that this is just for the tests so I think it's ok to make it private (even better than what it's now)

Iqn string `json:"iqn"`
Ip string `json:"ip"`
}

const IscsiEnvironmentSetupScript = `
const iSCSIEnvironmentSetupScript = `
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

Expand All @@ -59,7 +59,7 @@ $output = @{
$output | ConvertTo-Json | Write-Output
`

const IscsiSetChapScript = `
const iSCSISetChapScript = `
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

Expand All @@ -72,7 +72,7 @@ Set-IscsiServerTarget -TargetName $targetName -EnableChap $true -Chap $chap
`

func setChap(targetName string, username string, password string) error {
script := fmt.Sprintf(IscsiSetChapScript, targetName, username, password)
script := fmt.Sprintf(iSCSISetChapScript, targetName, username, password)
_, err := runPowershellScript(script)
if err != nil {
return fmt.Errorf("failed setting CHAP on iSCSI target=%v. err=%v", targetName, err)
Expand All @@ -81,7 +81,7 @@ func setChap(targetName string, username string, password string) error {
return nil
}

const IscsiSetReverseChapScript = `
const iSCSISetReverseChapScript = `
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

Expand All @@ -96,7 +96,7 @@ Set-IscsiServerTarget -TargetName $targetName -EnableReverseChap $true -ReverseC
`

func setReverseChap(targetName string, password string) error {
script := fmt.Sprintf(IscsiSetReverseChapScript, targetName, password)
script := fmt.Sprintf(iSCSISetReverseChapScript, targetName, password)
_, err := runPowershellScript(script)
if err != nil {
return fmt.Errorf("failed setting reverse CHAP on iSCSI target=%v. err=%v", targetName, err)
Expand All @@ -106,7 +106,7 @@ func setReverseChap(targetName string, password string) error {
}

func cleanup() error {
_, err := runPowershellScript(IscsiCleanupScript)
_, err := runPowershellScript(iSCSICleanupScript)
if err != nil {
return fmt.Errorf("failed cleaning up environment. err=%v", err)
}
Expand All @@ -121,7 +121,7 @@ func requireCleanup(t *testing.T) {
}
}

const IscsiCleanupScript = `
const iSCSICleanupScript = `
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

Expand Down Expand Up @@ -172,14 +172,14 @@ func runPowershellScript(script string) (string, error) {
return string(out), nil
}

func setupEnv(targetName string) (*IscsiSetupConfig, error) {
script := fmt.Sprintf(IscsiEnvironmentSetupScript, targetName)
func setupEnv(targetName string) (*iSCSISetupConfig, error) {
script := fmt.Sprintf(iSCSIEnvironmentSetupScript, targetName)
out, err := runPowershellScript(script)
if err != nil {
return nil, fmt.Errorf("failed setting up environment. err=%v", err)
}

config := IscsiSetupConfig{}
config := iSCSISetupConfig{}
err = json.Unmarshal([]byte(out), &config)
if err != nil {
return nil, err
Expand Down
78 changes: 39 additions & 39 deletions integrationtests/iscsi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ import (
"github.com/stretchr/testify/require"
)

const defaultIscsiPort = 3260
const defaultISCSIPort = 3260
const defaultProtoPort = 0 // default value when port is not set

func TestIscsi(t *testing.T) {
skipTestOnCondition(t, !shouldRunIscsiTests())
func TestISCSI(t *testing.T) {
skipTestOnCondition(t, !shouldRunISCSITests())

err := installIscsiTarget()
err := installISCSITarget()
require.NoError(t, err, "Failed installing iSCSI target")

t.Run("List/Add/Remove TargetPortal (Port=3260)", func(t *testing.T) {
targetPortalTest(t, defaultIscsiPort)
targetPortalTest(t, defaultISCSIPort)
})

t.Run("List/Add/Remove TargetPortal (Port not mentioned, effectively 3260)", func(t *testing.T) {
Expand Down Expand Up @@ -58,7 +58,7 @@ func e2eTest(t *testing.T) {

defer requireCleanup(t)

iscsiClient, err := iscsi.New(iscsiapi.New())
iSCSIClient, err := iscsi.New(iscsiapi.New())
require.Nil(t, err)

diskClient, err := disk.New(diskapi.New())
Expand All @@ -73,27 +73,27 @@ func e2eTest(t *testing.T) {

tp := &iscsi.TargetPortal{
TargetAddress: config.Ip,
TargetPort: defaultIscsiPort,
TargetPort: defaultISCSIPort,
}

addTpReq := &iscsi.AddTargetPortalRequest{
TargetPortal: tp,
}
_, err = iscsiClient.AddTargetPortal(context.Background(), addTpReq)
_, err = iSCSIClient.AddTargetPortal(context.Background(), addTpReq)
assert.Nil(t, err)

discReq := &iscsi.DiscoverTargetPortalRequest{TargetPortal: tp}
discResp, err := iscsiClient.DiscoverTargetPortal(context.TODO(), discReq)
discResp, err := iSCSIClient.DiscoverTargetPortal(context.TODO(), discReq)
if assert.Nil(t, err) {
assert.Contains(t, discResp.Iqns, config.Iqn)
}

connectReq := &iscsi.ConnectTargetRequest{TargetPortal: tp, Iqn: config.Iqn}
_, err = iscsiClient.ConnectTarget(context.TODO(), connectReq)
_, err = iSCSIClient.ConnectTarget(context.TODO(), connectReq)
assert.Nil(t, err)

tgtDisksReq := &iscsi.GetTargetDisksRequest{TargetPortal: tp, Iqn: config.Iqn}
tgtDisksResp, err := iscsiClient.GetTargetDisks(context.TODO(), tgtDisksReq)
tgtDisksResp, err := iSCSIClient.GetTargetDisks(context.TODO(), tgtDisksReq)
require.Nil(t, err)
require.Len(t, tgtDisksResp.DiskIDs, 1)

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

defer requireCleanup(t)

iscsiClient, err := iscsi.New(iscsiapi.New())
iSCSIClient, err := iscsi.New(iscsiapi.New())
require.Nil(t, err)

systemClient, err := system.New(systemapi.New())
Expand All @@ -132,27 +132,27 @@ func targetTest(t *testing.T) {

tp := &iscsi.TargetPortal{
TargetAddress: config.Ip,
TargetPort: defaultIscsiPort,
TargetPort: defaultISCSIPort,
}

addTpReq := &iscsi.AddTargetPortalRequest{
TargetPortal: tp,
}
_, err = iscsiClient.AddTargetPortal(context.Background(), addTpReq)
_, err = iSCSIClient.AddTargetPortal(context.Background(), addTpReq)
assert.Nil(t, err)

discReq := &iscsi.DiscoverTargetPortalRequest{TargetPortal: tp}
discResp, err := iscsiClient.DiscoverTargetPortal(context.TODO(), discReq)
discResp, err := iSCSIClient.DiscoverTargetPortal(context.TODO(), discReq)
if assert.Nil(t, err) {
assert.Contains(t, discResp.Iqns, config.Iqn)
}

connectReq := &iscsi.ConnectTargetRequest{TargetPortal: tp, Iqn: config.Iqn}
_, err = iscsiClient.ConnectTarget(context.TODO(), connectReq)
_, err = iSCSIClient.ConnectTarget(context.TODO(), connectReq)
assert.Nil(t, err)

disconReq := &iscsi.DisconnectTargetRequest{TargetPortal: tp, Iqn: config.Iqn}
_, err = iscsiClient.DisconnectTarget(context.TODO(), disconReq)
_, err = iSCSIClient.DisconnectTarget(context.TODO(), disconReq)
assert.Nil(t, err)
}

Expand All @@ -169,7 +169,7 @@ func targetChapTest(t *testing.T) {
err = setChap(targetName, username, password)
require.NoError(t, err)

iscsiClient, err := iscsi.New(iscsiapi.New())
iSCSIClient, err := iscsi.New(iscsiapi.New())
require.Nil(t, err)

systemClient, err := system.New(systemapi.New())
Expand All @@ -181,17 +181,17 @@ func targetChapTest(t *testing.T) {

tp := &iscsi.TargetPortal{
TargetAddress: config.Ip,
TargetPort: defaultIscsiPort,
TargetPort: defaultISCSIPort,
}

addTpReq := &iscsi.AddTargetPortalRequest{
TargetPortal: tp,
}
_, err = iscsiClient.AddTargetPortal(context.Background(), addTpReq)
_, err = iSCSIClient.AddTargetPortal(context.Background(), addTpReq)
assert.Nil(t, err)

discReq := &iscsi.DiscoverTargetPortalRequest{TargetPortal: tp}
discResp, err := iscsiClient.DiscoverTargetPortal(context.TODO(), discReq)
discResp, err := iSCSIClient.DiscoverTargetPortal(context.TODO(), discReq)
if assert.Nil(t, err) {
assert.Contains(t, discResp.Iqns, config.Iqn)
}
Expand All @@ -203,11 +203,11 @@ func targetChapTest(t *testing.T) {
ChapSecret: password,
AuthType: iscsi.ONE_WAY_CHAP,
}
_, err = iscsiClient.ConnectTarget(context.TODO(), connectReq)
_, err = iSCSIClient.ConnectTarget(context.TODO(), connectReq)
assert.Nil(t, err)

disconReq := &iscsi.DisconnectTargetRequest{TargetPortal: tp, Iqn: config.Iqn}
_, err = iscsiClient.DisconnectTarget(context.TODO(), disconReq)
_, err = iSCSIClient.DisconnectTarget(context.TODO(), disconReq)
assert.Nil(t, err)
}

Expand All @@ -228,7 +228,7 @@ func targetMutualChapTest(t *testing.T) {
err = setReverseChap(targetName, reverse_password)
require.NoError(t, err)

iscsiClient, err := iscsi.New(iscsiapi.New())
iSCSIClient, err := iscsi.New(iscsiapi.New())
require.Nil(t, err)

systemClient, err := system.New(systemapi.New())
Expand All @@ -243,21 +243,21 @@ func targetMutualChapTest(t *testing.T) {

tp := &iscsi.TargetPortal{
TargetAddress: config.Ip,
TargetPort: defaultIscsiPort,
TargetPort: defaultISCSIPort,
}

{
req := &iscsi.AddTargetPortalRequest{
TargetPortal: tp,
}
resp, err := iscsiClient.AddTargetPortal(context.Background(), req)
resp, err := iSCSIClient.AddTargetPortal(context.Background(), req)
assert.Nil(t, err)
assert.NotNil(t, resp)
}

{
req := &iscsi.DiscoverTargetPortalRequest{TargetPortal: tp}
resp, err := iscsiClient.DiscoverTargetPortal(context.TODO(), req)
resp, err := iSCSIClient.DiscoverTargetPortal(context.TODO(), req)
if assert.Nil(t, err) && assert.NotNil(t, resp) {
assert.Contains(t, resp.Iqns, config.Iqn)
}
Expand All @@ -266,7 +266,7 @@ func targetMutualChapTest(t *testing.T) {
{
// Try using a wrong initiator password and expect error on connection
req := &iscsi.SetMutualChapSecretRequest{MutualChapSecret: "made-up-pass"}
resp, err := iscsiClient.SetMutualChapSecret(context.TODO(), req)
resp, err := iSCSIClient.SetMutualChapSecret(context.TODO(), req)
require.NoError(t, err)
assert.NotNil(t, resp)
}
Expand All @@ -279,22 +279,22 @@ func targetMutualChapTest(t *testing.T) {
AuthType: iscsi.MUTUAL_CHAP,
}

_, err = iscsiClient.ConnectTarget(context.TODO(), connectReq)
_, err = iSCSIClient.ConnectTarget(context.TODO(), connectReq)
assert.NotNil(t, err)

{
req := &iscsi.SetMutualChapSecretRequest{MutualChapSecret: reverse_password}
resp, err := iscsiClient.SetMutualChapSecret(context.TODO(), req)
resp, err := iSCSIClient.SetMutualChapSecret(context.TODO(), req)
require.NoError(t, err)
assert.NotNil(t, resp)
}

_, err = iscsiClient.ConnectTarget(context.TODO(), connectReq)
_, err = iSCSIClient.ConnectTarget(context.TODO(), connectReq)
assert.Nil(t, err)

{
req := &iscsi.DisconnectTargetRequest{TargetPortal: tp, Iqn: config.Iqn}
resp, err := iscsiClient.DisconnectTarget(context.TODO(), req)
resp, err := iSCSIClient.DisconnectTarget(context.TODO(), req)
assert.Nil(t, err)
assert.NotNil(t, resp)
}
Expand All @@ -306,7 +306,7 @@ func targetPortalTest(t *testing.T, port uint32) {

defer requireCleanup(t)

iscsiClient, err := iscsi.New(iscsiapi.New())
iSCSIClient, err := iscsi.New(iscsiapi.New())
require.Nil(t, err)

systemClient, err := system.New(systemapi.New())
Expand All @@ -323,23 +323,23 @@ func targetPortalTest(t *testing.T, port uint32) {

listReq := &iscsi.ListTargetPortalsRequest{}

listResp, err := iscsiClient.ListTargetPortals(context.Background(), listReq)
listResp, err := iSCSIClient.ListTargetPortals(context.Background(), listReq)
if assert.Nil(t, err) {
assert.Len(t, listResp.TargetPortals, 0,
"Expect no registered target portals")
}

addTpReq := &iscsi.AddTargetPortalRequest{TargetPortal: tp}
_, err = iscsiClient.AddTargetPortal(context.Background(), addTpReq)
_, err = iSCSIClient.AddTargetPortal(context.Background(), addTpReq)
assert.Nil(t, err)

// Port 0 (unset) is handled as the default iSCSI port
expectedPort := port
if expectedPort == 0 {
expectedPort = defaultIscsiPort
expectedPort = defaultISCSIPort
}

gotListResp, err := iscsiClient.ListTargetPortals(context.Background(), listReq)
gotListResp, err := iSCSIClient.ListTargetPortals(context.Background(), listReq)
if assert.Nil(t, err) {
assert.Len(t, gotListResp.TargetPortals, 1)
assert.Equal(t, gotListResp.TargetPortals[0].TargetPort, expectedPort)
Expand All @@ -349,10 +349,10 @@ func targetPortalTest(t *testing.T, port uint32) {
remReq := &iscsi.RemoveTargetPortalRequest{
TargetPortal: tp,
}
_, err = iscsiClient.RemoveTargetPortal(context.Background(), remReq)
_, err = iSCSIClient.RemoveTargetPortal(context.Background(), remReq)
assert.Nil(t, err)

listResp, err = iscsiClient.ListTargetPortals(context.Background(), listReq)
listResp, err = iSCSIClient.ListTargetPortals(context.Background(), listReq)
if assert.Nil(t, err) {
assert.Len(t, listResp.TargetPortals, 0,
"Expect no registered target portals after delete")
Expand Down
2 changes: 1 addition & 1 deletion integrationtests/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func skipTestOnCondition(t *testing.T, condition bool) {
// used to skip iSCSI tests as they affect the test machine
// e.g. install an iSCSI target, format a disk, etc.
// Take care to use disposable clean VMs for tests
func shouldRunIscsiTests() bool {
func shouldRunISCSITests() bool {
return os.Getenv("ENABLE_ISCSI_TESTS") == "TRUE"
}

Expand Down
Loading