Skip to content
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

gopowermax updates to support powermax unit tests #93

Merged
merged 7 commits into from
Feb 25, 2025
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
4 changes: 3 additions & 1 deletion mock/initiatorIDList.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"SE-2E:000:iqn.1993-08.org.debian:01:8f21cc8ad2a7",
"SE-1E:000:iqn.1993-08.org.debian:01:a86eeef2c837",
"SE-2E:001:iqn.1993-08.org.debian:01:a86eeef2c837",
"SE-2E:000:iqn.1993-08.org.debian:01:a86eeef2c837"
"SE-2E:000:iqn.1993-08.org.debian:01:a86eeef2c837",
"OR-1C:001:nqn.2019-08.org.emc:sn.0x10000090fa6603b7",
"OR-1C:002:nqn.2019-08.org.dell:sn.0x10000090fa6603b7"
]
}
53 changes: 38 additions & 15 deletions mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ var Data struct {
FileIntIDtoFileInterface map[string]*types.FileInterface
}

var Filters = new(filters)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this variable accessed from unit tests in csi-powermax?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes.


type filters struct {
GetNVMePorts bool
}

var InducedErrors = new(inducedErrors)

// InducedErrors constants
Expand Down Expand Up @@ -256,6 +262,7 @@ type inducedErrors struct {
GetFileInterfaceError bool
ExecuteActionError bool
GetFreshMetrics bool
GetNVMePorts bool
}

// hasError checks to see if the specified error (via pointer)
Expand Down Expand Up @@ -563,7 +570,7 @@ func initMockCache() {
initNode1 := iscsidir1PortKey1 + ":" + iqnNode1
initNode1List = append(initNode1List, iqnNode1)
addInitiator(initNode1, iqnNode1, "GigE", []string{iscsidir1PortKey1}, "") // #nosec G20
addHost("CSI-Test-Node-1", "iSCSI", initNode1List) // #nosec G20
addHost("CSI-Test-Node-1-ISCSI", "iSCSI", initNode1List) // #nosec G20
initNode2List := make([]string, 0)
iqn1Node2 := "iqn.1993-08.org.centos:01:5ae577b352a1"
iqn2Node2 := "iqn.1993-08.org.centos:01:5ae577b352a2"
Expand All @@ -573,7 +580,7 @@ func initMockCache() {
initNode2List = append(initNode2List, iqn2Node2)
addInitiator(init1Node2, iqn1Node2, "GigE", []string{iscsidir1PortKey1}, "") // #nosec G20
addInitiator(init2Node2, iqn2Node2, "GigE", []string{iscsidir1PortKey1}, "") // #nosec G20
addHost("CSI-Test-Node-2", "iSCSI", initNode2List) // #nosec G20
addHost("CSI-Test-Node-2-ISCSI", "iSCSI", initNode2List) // #nosec G20
addMaskingView("CSI-Test-MV-1", "CSI-Test-SG-1", "CSI-Test-Node-1", "iscsi_ports") // #nosec G20

initNode3List := make([]string, 0)
Expand All @@ -590,6 +597,16 @@ func initMockCache() {
initNode3List = append(initNode3List, hba1Node3)
initNode3List = append(initNode3List, hba2Node3)
addHost("CSI-Test-Node-3-FC", "Fibre", initNode3List) // #nosec G20

nvmeDir1 := "OR-1C"
nvmedir1PortKey1 := nvmeDir1 + ":" + "001"
nqnNodeList := make([]string, 0)
nqnNode1 := "nqn.1988-11.com.dell.mock:00:e6e2d5b871f1403E169D0"
nqnInit1 := nvmedir1PortKey1 + ":" + nqnNode1
nqnNodeList = append(nqnNodeList, nqnInit1)
addInitiator(nqnNode1, nqnNode1, "OSHostAndRDF", []string{nvmedir1PortKey1}, "") // #nosec G20

addHost("CSI-Test-Node-4-NVMETCP", "NVMETCP", nqnNodeList) // #nosec G20
addTempSnapshots()
addFileObjects()
}
Expand Down Expand Up @@ -3340,7 +3357,11 @@ func handlePort(w http.ResponseWriter, r *http.Request) {
}
return
}
returnPort(w, dID, pID)
if Filters.GetNVMePorts {
returnNVMePort(w, dID, pID)
} else {
returnPort(w, dID, pID)
}
}
// return a list of Ports
returnPortIDList(w, dID)
Expand Down Expand Up @@ -3371,6 +3392,13 @@ func returnPort(w http.ResponseWriter, dID, pID string) {
returnJSONFile(Data.JSONDir, "port_template.json", w, replacements)
}

func returnNVMePort(w http.ResponseWriter, dID, pID string) {
replacements := make(map[string]string)
replacements["__PORT_ID__"] = pID
replacements["__DIRECTOR_ID__"] = dID
returnJSONFile(Data.JSONDir, "nvme_port_template.json", w, replacements)
}

func returnPortIDList(w http.ResponseWriter, dID string) {
replacements := make(map[string]string)
replacements["__DIRECTOR_ID__"] = dID
Expand Down Expand Up @@ -3482,21 +3510,16 @@ func handleHost(w http.ResponseWriter, r *http.Request) {
return
}
// Scan the initiators to see if there are any non iqn ones; then assume
// host type Fibre.
isFibre := false
for _, initiator := range createHostParam.InitiatorIDs {
if !strings.HasPrefix(initiator, "iqn.") {
isFibre = true
if strings.HasPrefix(initiator, "iqn.") {
addHost(createHostParam.HostID, "iSCSI", createHostParam.InitiatorIDs) // #nosec G20
} else if strings.HasPrefix(initiator, "nqn.") {
addHost(createHostParam.HostID, "NVMETCP", createHostParam.InitiatorIDs) // #nosec G20
} else {
addHost(createHostParam.HostID, "Fibre", createHostParam.InitiatorIDs) // #nosec G20
}
}
if isFibre {
// Might need to add the Port information here
addHost(createHostParam.HostID, "Fibre", createHostParam.InitiatorIDs) // #nosec G20
} else {
// initNode := make([]string, 0)
// initNode = append(initNode, "iqn.1993-08.org.centos:01:5ae577b352a7")
addHost(createHostParam.HostID, "iSCSI", createHostParam.InitiatorIDs) // #nosec G20
}

returnHost(w, createHostParam.HostID)

case http.MethodPut:
Expand Down
41 changes: 41 additions & 0 deletions mock/nvme_port_template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"symmetrixPort": {
"symmetrixPortKey": {
"directorId": "__DIRECTOR_ID__",
"portId": "__PORT_ID__"
},
"port_status": "ON",
"director_status": "Online",
"type": "OSAndHostRDF",
"num_of_cores": 4,
"identifier": "nqn.2019-08.org.emc:sn.0x10000090fa6603b7",
"negotiated_speed": "0",
"num_of_port_groups": 3,
"num_of_masking_views": 2,
"num_of_mapped_vols": 10,
"vcm_state": "Enabled",
"aclx": true,
"vnx_attached": false,
"avoid_reset_broadcast": false,
"environ_set": false,
"disable_q_reset_on_ua": false,
"soft_reset": false,
"scsi_3": true,
"scsi_support1": true,
"spc2_protocol_version": true,
"portgroup": [
"IS_lqam9024_PG",
"IS_lqam9024_2E_PG",
"IS_lqam9025_PG"
],
"maskingview": [
"IS_lqam9024_view",
"lqam9024_diamond_sg_mv_MV"
],
"max_speed": "0",
"iscsi_target": false,
"ip_addresses": [
"1.1.1.1"
]
}
}