@@ -595,12 +595,13 @@ func TestListSnapshotsArguments(t *testing.T) {
595595
596596func TestCreateVolumeArguments (t * testing.T ) {
597597 testCases := []struct {
598- name string
599- req * csi.CreateVolumeRequest
600- enableStoragePools bool
601- expVol * csi.Volume
602- expErrCode codes.Code
603- enableDiskTopology bool
598+ name string
599+ req * csi.CreateVolumeRequest
600+ enableStoragePools bool
601+ expVol * csi.Volume
602+ expErrCode codes.Code
603+ enableDiskTopology bool
604+ enableDynamicVolumes bool
604605 }{
605606 {
606607 name : "success default" ,
@@ -784,23 +785,6 @@ func TestCreateVolumeArguments(t *testing.T) {
784785 },
785786 },
786787 },
787- {
788- name : "fail with extra topology" ,
789- req : & csi.CreateVolumeRequest {
790- Name : "test-name" ,
791- CapacityRange : stdCapRange ,
792- VolumeCapabilities : stdVolCaps ,
793- Parameters : stdParams ,
794- AccessibilityRequirements : & csi.TopologyRequirement {
795- Requisite : []* csi.Topology {
796- {
797- Segments : map [string ]string {"ooblezoners" : "topology-zone" , constants .TopologyKeyZone : "top-zone" },
798- },
799- },
800- },
801- },
802- expErrCode : codes .InvalidArgument ,
803- },
804788 {
805789 name : "fail with missing topology zone" ,
806790 req : & csi.CreateVolumeRequest {
@@ -1385,13 +1369,154 @@ func TestCreateVolumeArguments(t *testing.T) {
13851369 },
13861370 },
13871371 },
1372+ {
1373+ name : "success with dynamic volumes enabled but standard type" ,
1374+ req : & csi.CreateVolumeRequest {
1375+ Name : "test-name" ,
1376+ CapacityRange : stdCapRange ,
1377+ VolumeCapabilities : stdVolCaps ,
1378+ Parameters : stdParams ,
1379+ },
1380+ expVol : & csi.Volume {
1381+ CapacityBytes : common .GbToBytes (20 ),
1382+ VolumeId : testVolumeID ,
1383+ VolumeContext : nil ,
1384+ AccessibleTopology : []* csi.Topology {
1385+ {
1386+ Segments : map [string ]string {
1387+ constants .TopologyKeyZone : zone ,
1388+ },
1389+ },
1390+ },
1391+ },
1392+ },
1393+ {
1394+ name : "success with dynamic volumes selecting disk" ,
1395+ req : & csi.CreateVolumeRequest {
1396+ Name : "test-name" ,
1397+ CapacityRange : stdCapRange ,
1398+ VolumeCapabilities : stdVolCaps ,
1399+ Parameters : map [string ]string {
1400+ parameters .ParameterKeyType : parameters .DynamicVolumeType ,
1401+ parameters .ParameterPDType : "pd-balanced" ,
1402+ parameters .ParameterHDType : "hyperdisk-balanced" ,
1403+ },
1404+ },
1405+ enableDynamicVolumes : true ,
1406+ expVol : & csi.Volume {
1407+ CapacityBytes : common .GbToBytes (20 ),
1408+ VolumeId : testVolumeID ,
1409+ VolumeContext : nil ,
1410+ AccessibleTopology : []* csi.Topology {
1411+ {
1412+ Segments : map [string ]string {
1413+ constants .TopologyKeyZone : zone ,
1414+ },
1415+ },
1416+ },
1417+ },
1418+ },
1419+ {
1420+ name : "success defaulting pd-type" ,
1421+ req : & csi.CreateVolumeRequest {
1422+ Name : "test-name" ,
1423+ CapacityRange : stdCapRange ,
1424+ VolumeCapabilities : stdVolCaps ,
1425+ Parameters : map [string ]string {
1426+ parameters .ParameterKeyType : parameters .DynamicVolumeType ,
1427+ parameters .ParameterHDType : "hyperdisk-balanced" ,
1428+ },
1429+ },
1430+ enableDynamicVolumes : true ,
1431+ expVol : & csi.Volume {
1432+ CapacityBytes : common .GbToBytes (20 ),
1433+ VolumeId : testVolumeID ,
1434+ VolumeContext : nil ,
1435+ AccessibleTopology : []* csi.Topology {
1436+ {
1437+ Segments : map [string ]string {
1438+ constants .TopologyKeyZone : zone ,
1439+ },
1440+ },
1441+ },
1442+ },
1443+ },
1444+ {
1445+ name : "success defaulting hd-type" ,
1446+ req : & csi.CreateVolumeRequest {
1447+ Name : "test-name" ,
1448+ CapacityRange : stdCapRange ,
1449+ VolumeCapabilities : stdVolCaps ,
1450+ Parameters : map [string ]string {
1451+ parameters .ParameterKeyType : parameters .DynamicVolumeType ,
1452+ parameters .ParameterPDType : "pd-balanced" ,
1453+ },
1454+ },
1455+ enableDynamicVolumes : true ,
1456+ expVol : & csi.Volume {
1457+ CapacityBytes : common .GbToBytes (20 ),
1458+ VolumeId : testVolumeID ,
1459+ VolumeContext : nil ,
1460+ AccessibleTopology : []* csi.Topology {
1461+ {
1462+ Segments : map [string ]string {
1463+ constants .TopologyKeyZone : zone ,
1464+ },
1465+ },
1466+ },
1467+ },
1468+ },
1469+ {
1470+ name : "fail with dynamic volume missing dynamic type" ,
1471+ req : & csi.CreateVolumeRequest {
1472+ Name : "test-name" ,
1473+ CapacityRange : stdCapRange ,
1474+ VolumeCapabilities : stdVolCaps ,
1475+ Parameters : map [string ]string {
1476+ parameters .ParameterHDType : "hyperdisk-balanced" ,
1477+ parameters .ParameterPDType : "pd-balanced" ,
1478+ },
1479+ },
1480+ enableDynamicVolumes : true ,
1481+ expErrCode : codes .InvalidArgument ,
1482+ },
1483+ {
1484+ name : "success with dynamic volumes selecting disk override" ,
1485+ req : & csi.CreateVolumeRequest {
1486+ Name : "test-name" ,
1487+ CapacityRange : stdCapRange ,
1488+ VolumeCapabilities : stdVolCaps ,
1489+ Parameters : map [string ]string {
1490+ parameters .ParameterKeyType : parameters .DynamicVolumeType ,
1491+ parameters .ParameterPDType : "pd-balanced" ,
1492+ parameters .ParameterHDType : "hyperdisk-balanced" ,
1493+ parameters .ParameterDiskPreference : parameters .ParameterPDType ,
1494+ },
1495+ },
1496+ enableDynamicVolumes : true ,
1497+ expVol : & csi.Volume {
1498+ CapacityBytes : common .GbToBytes (20 ),
1499+ VolumeId : testVolumeID ,
1500+ VolumeContext : nil ,
1501+ AccessibleTopology : []* csi.Topology {
1502+ {
1503+ Segments : map [string ]string {
1504+ constants .TopologyKeyZone : zone ,
1505+ },
1506+ },
1507+ },
1508+ },
1509+ },
13881510 }
13891511
13901512 // Run test cases
13911513 for _ , tc := range testCases {
13921514 t .Run (tc .name , func (t * testing.T ) {
13931515 // Setup new driver each time so no interference
1394- args := & GCEControllerServerArgs {EnableDiskTopology : tc .enableDiskTopology }
1516+ args := & GCEControllerServerArgs {
1517+ EnableDiskTopology : tc .enableDiskTopology ,
1518+ EnableDynamicVolumes : tc .enableDynamicVolumes ,
1519+ }
13951520 gceDriver := initGCEDriver (t , nil , args )
13961521 gceDriver .cs .enableStoragePools = tc .enableStoragePools
13971522
@@ -4392,18 +4517,6 @@ func TestGetZonesFromTopology(t *testing.T) {
43924517 topology : []* csi.Topology {},
43934518 expZones : sets .NewString (),
43944519 },
4395- {
4396- name : "fail: wrong key inside" ,
4397- topology : []* csi.Topology {
4398- {
4399- Segments : map [string ]string {constants .TopologyKeyZone : "test-zone" , "fake-key" : "fake-value" },
4400- },
4401- {
4402- Segments : map [string ]string {constants .TopologyKeyZone : "test-zone2" },
4403- },
4404- },
4405- expErr : true ,
4406- },
44074520 {
44084521 name : "success: no topology" ,
44094522 expZones : sets .NewString (),
0 commit comments