@@ -49,6 +49,9 @@ func TestClient(t *testing.T) {
4949 // set CNS_RUN_TRANSACTION_TESTS environment to true, if you want to run CNS Transaction tests
5050 // example: export CNS_RUN_TRANSACTION_TESTS='true'
5151 run_cns_transaction_tests := os .Getenv ("CNS_RUN_TRANSACTION_TESTS" )
52+ // set CNS_RUN_SHARED_DISK_TESTS environment to true, if you want to run shared disk related tests
53+ // example: export CNS_RUN_SHARED_DISK_TESTS='true'
54+ run_shared_disk_tests_tests := os .Getenv ("CNS_RUN_SHARED_DISK_TESTS" )
5255
5356 // set CNS_RUN_MULTICLUSTER_PER_ZONE_TESTS environment to true, if you want to run tests
5457 // on deployment with Zone with multiple vSphere Clusters
@@ -332,14 +335,10 @@ func TestClient(t *testing.T) {
332335 }
333336 reCreateVolumeOperationRes := reCreateTaskResult .GetCnsVolumeOperationResult ()
334337 t .Logf ("reCreateVolumeOperationRes.: %+v" , pretty .Sprint (reCreateVolumeOperationRes ))
335- if reCreateVolumeOperationRes .Fault != nil {
336- t .Logf ("reCreateVolumeOperationRes.Fault: %+v" , pretty .Sprint (reCreateVolumeOperationRes .Fault ))
337- _ , ok := reCreateVolumeOperationRes .Fault .Fault .(* cnstypes.CnsAlreadyRegisteredFault )
338- if ! ok {
339- t .Fatalf ("Fault is not a CnsAlreadyRegisteredFault" )
340- }
338+ if reCreateVolumeOperationRes .Fault == nil {
339+ t .Logf ("re-create same volume did not fail as expected" )
341340 } else {
342- t .Fatalf ("re-create same volume should fail with CnsAlreadyRegisteredFault" )
341+ t .Fatalf ("re-creating same volume failed with fault: %+v" , pretty . Sprint ( reCreateVolumeOperationRes . Fault ) )
343342 }
344343 }
345344
@@ -1201,6 +1200,84 @@ func TestClient(t *testing.T) {
12011200 }
12021201 t .Logf ("Volume detached successfully" )
12031202
1203+ if run_shared_disk_tests_tests == "true" && isvSphereVersion91orAbove {
1204+ // Test AttachVolume API with multiwriter parameters
1205+ var cnsVolumeAttachSpecList []cnstypes.CnsVolumeAttachDetachSpec
1206+ cnsVolumeAttachSpec := cnstypes.CnsVolumeAttachDetachSpec {
1207+ VolumeId : cnstypes.CnsVolumeId {
1208+ Id : volumeId ,
1209+ },
1210+ Vm : nodeVM .Reference (),
1211+ DiskMode : "independent_persistent" ,
1212+ Sharing : "sharingMultiWriter" ,
1213+ UnitNumber : 23 ,
1214+ ControllerKey : 1000 ,
1215+ }
1216+
1217+ cnsVolumeAttachSpecList = append (cnsVolumeAttachSpecList , cnsVolumeAttachSpec )
1218+ t .Logf ("Attaching volume using the spec: %+v" , cnsVolumeAttachSpec )
1219+ attachTask , err := cnsClient .AttachVolume (ctx , cnsVolumeAttachSpecList )
1220+ if err != nil {
1221+ t .Errorf ("Failed to attach volume. Error: %+v \n " , err )
1222+ t .Fatal (err )
1223+ }
1224+ attachTaskInfo , err := GetTaskInfo (ctx , attachTask )
1225+ if err != nil {
1226+ t .Errorf ("Failed to attach volume. Error: %+v \n " , err )
1227+ t .Fatal (err )
1228+ }
1229+ attachTaskResult , err := GetTaskResult (ctx , attachTaskInfo )
1230+ if err != nil {
1231+ t .Errorf ("Failed to attach volume. Error: %+v \n " , err )
1232+ t .Fatal (err )
1233+ }
1234+ if attachTaskResult == nil {
1235+ t .Fatalf ("Empty attach task results" )
1236+ t .FailNow ()
1237+ }
1238+ attachVolumeOperationRes := attachTaskResult .GetCnsVolumeOperationResult ()
1239+ if attachVolumeOperationRes .Fault != nil {
1240+ t .Fatalf ("Failed to attach volume: fault=%+v" , attachVolumeOperationRes .Fault )
1241+ }
1242+ diskUUID := any (attachTaskResult ).(* cnstypes.CnsVolumeAttachResult ).DiskUUID
1243+ t .Logf ("Volume attached sucessfully with shared disk params. Disk UUID: %s" , diskUUID )
1244+
1245+ // Test DetachVolume API
1246+ var cnsVolumeDetachSpecList []cnstypes.CnsVolumeAttachDetachSpec
1247+ cnsVolumeDetachSpec := cnstypes.CnsVolumeAttachDetachSpec {
1248+ VolumeId : cnstypes.CnsVolumeId {
1249+ Id : volumeId ,
1250+ },
1251+ Vm : nodeVM .Reference (),
1252+ }
1253+ cnsVolumeDetachSpecList = append (cnsVolumeDetachSpecList , cnsVolumeDetachSpec )
1254+ t .Logf ("Detaching volume using the spec: %+v" , cnsVolumeDetachSpec )
1255+ detachTask , err := cnsClient .DetachVolume (ctx , cnsVolumeDetachSpecList )
1256+ if err != nil {
1257+ t .Errorf ("Failed to detach volume. Error: %+v \n " , err )
1258+ t .Fatal (err )
1259+ }
1260+ detachTaskInfo , err := GetTaskInfo (ctx , detachTask )
1261+ if err != nil {
1262+ t .Errorf ("Failed to detach volume. Error: %+v \n " , err )
1263+ t .Fatal (err )
1264+ }
1265+ detachTaskResult , err := GetTaskResult (ctx , detachTaskInfo )
1266+ if err != nil {
1267+ t .Errorf ("Failed to detach volume. Error: %+v \n " , err )
1268+ t .Fatal (err )
1269+ }
1270+ if detachTaskResult == nil {
1271+ t .Fatalf ("Empty detach task results" )
1272+ t .FailNow ()
1273+ }
1274+ detachVolumeOperationRes := detachTaskResult .GetCnsVolumeOperationResult ()
1275+ if detachVolumeOperationRes .Fault != nil {
1276+ t .Fatalf ("Failed to detach volume: fault=%+v" , detachVolumeOperationRes .Fault )
1277+ }
1278+ t .Logf ("Volume detached sucessfully" )
1279+ }
1280+
12041281 // Test QueryVolumeAsync API only for vSphere version 7.0.3 onwards
12051282 if isvSphereVersion70U3orAbove (ctx , c .ServiceContent .About ) {
12061283 queryVolumeAsyncTask , err := cnsClient .QueryVolumeAsync (ctx , queryFilter , nil )
0 commit comments