@@ -902,52 +902,90 @@ func TestCreateVolumeWithVolumeSourceFromSnapshot(t *testing.T) {
902
902
903
903
func TestCreateVolumeWithVolumeSourceFromVolume (t * testing.T ) {
904
904
testSourceVolumeName := "test-volume-source-name"
905
- testVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , testSourceVolumeName )
905
+ testZonalVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , testSourceVolumeName )
906
+ testRegionalVolumeSourceID := fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , region , testSourceVolumeName )
906
907
testVolumeSourceIDDifferentZone := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , "different-zone" , testSourceVolumeName )
908
+ topology := & csi.TopologyRequirement {
909
+ Requisite : []* csi.Topology {
910
+ {
911
+ Segments : map [string ]string {common .TopologyKeyZone : region + "-b" },
912
+ },
913
+ {
914
+ Segments : map [string ]string {common .TopologyKeyZone : region + "-c" },
915
+ },
916
+ },
917
+ }
918
+ regionalParams := map [string ]string {
919
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : "regional-pd" ,
920
+ }
907
921
// Define test cases
908
922
testCases := []struct {
909
- name string
910
- project string
911
- volKey * meta. Key
912
- volumeOnCloud bool
913
- expErrCode codes. Code
914
- sourceVolumeID string
915
- parameters map [ string ] string
923
+ name string
924
+ volumeOnCloud bool
925
+ expErrCode codes. Code
926
+ sourceVolumeID string
927
+ reqParameters map [ string ] string
928
+ sourceReqParameters map [ string ] string
929
+ topology * csi. TopologyRequirement
916
930
}{
917
931
{
918
- name : "success with data source of volume type" ,
919
- project : "test-project" ,
920
- volKey : meta . ZonalKey ( "my-disk" , zone ) ,
921
- volumeOnCloud : true ,
922
- sourceVolumeID : testVolumeSourceID ,
932
+ name : "success with data source of zonal volume type" ,
933
+ volumeOnCloud : true ,
934
+ sourceVolumeID : testZonalVolumeSourceID ,
935
+ reqParameters : stdParams ,
936
+ sourceReqParameters : stdParams ,
923
937
},
924
938
{
925
- name : "fail with data source of volume type that doesn't exist " ,
926
- project : "test-project" ,
927
- volKey : meta . ZonalKey ( "my-disk" , zone ) ,
928
- volumeOnCloud : false ,
929
- expErrCode : codes . NotFound ,
930
- sourceVolumeID : testVolumeSourceID ,
939
+ name : "success with data source of regional volume type" ,
940
+ volumeOnCloud : true ,
941
+ sourceVolumeID : testRegionalVolumeSourceID ,
942
+ reqParameters : regionalParams ,
943
+ sourceReqParameters : regionalParams ,
944
+ topology : topology ,
931
945
},
932
946
{
933
- name : "fail with data source of volume type with invalid volume id format" ,
934
- project : "test-project" ,
935
- volKey : meta .ZonalKey ("my-disk" , zone ),
936
- volumeOnCloud : false ,
937
- expErrCode : codes .InvalidArgument ,
938
- sourceVolumeID : testVolumeSourceID + "invalid/format" ,
947
+ name : "fail with with data source of replication-type different from CreateVolumeRequest" ,
948
+ volumeOnCloud : true ,
949
+ expErrCode : codes .InvalidArgument ,
950
+ sourceVolumeID : testZonalVolumeSourceID ,
951
+ reqParameters : stdParams ,
952
+ sourceReqParameters : regionalParams ,
953
+ topology : topology ,
954
+ },
955
+ {
956
+ name : "fail with data source of zonal volume type that doesn't exist" ,
957
+ volumeOnCloud : false ,
958
+ expErrCode : codes .NotFound ,
959
+ sourceVolumeID : testZonalVolumeSourceID ,
960
+ reqParameters : stdParams ,
961
+ sourceReqParameters : stdParams ,
962
+ },
963
+ {
964
+ name : "fail with data source of zonal volume type with invalid volume id format" ,
965
+ volumeOnCloud : false ,
966
+ expErrCode : codes .InvalidArgument ,
967
+ sourceVolumeID : testZonalVolumeSourceID + "invalid/format" ,
968
+ reqParameters : stdParams ,
969
+ sourceReqParameters : stdParams ,
939
970
},
940
971
{
941
- name : "fail with data source of volume type with invalid disk parameters" ,
942
- project : "test-project" ,
943
- volKey : meta .ZonalKey ("my-disk" , zone ),
972
+ name : "fail with data source of zonal volume type with invalid disk parameters" ,
944
973
volumeOnCloud : true ,
945
974
expErrCode : codes .InvalidArgument ,
946
975
sourceVolumeID : testVolumeSourceIDDifferentZone ,
947
- parameters : map [string ]string {
976
+ reqParameters : stdParams ,
977
+ sourceReqParameters : map [string ]string {
948
978
common .ParameterKeyType : "different-type" ,
949
979
},
950
980
},
981
+ {
982
+ name : "fail with data source of zonal volume type with invalid replication type" ,
983
+ volumeOnCloud : true ,
984
+ expErrCode : codes .InvalidArgument ,
985
+ sourceVolumeID : testZonalVolumeSourceID ,
986
+ reqParameters : regionalParams ,
987
+ sourceReqParameters : stdParams ,
988
+ },
951
989
}
952
990
953
991
for _ , tc := range testCases {
@@ -958,7 +996,7 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
958
996
Name : name ,
959
997
CapacityRange : stdCapRange ,
960
998
VolumeCapabilities : stdVolCaps ,
961
- Parameters : stdParams ,
999
+ Parameters : tc . reqParameters ,
962
1000
VolumeContentSource : & csi.VolumeContentSource {
963
1001
Type : & csi.VolumeContentSource_Volume {
964
1002
Volume : & csi.VolumeContentSource_VolumeSource {
@@ -972,16 +1010,26 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
972
1010
Name : testSourceVolumeName ,
973
1011
CapacityRange : stdCapRange ,
974
1012
VolumeCapabilities : stdVolCaps ,
975
- Parameters : stdParams ,
1013
+ Parameters : tc . sourceReqParameters ,
976
1014
}
977
- if tc .parameters != nil {
978
- sourceVolumeRequest .Parameters = tc .parameters
1015
+
1016
+ if tc .topology != nil {
1017
+ // req.AccessibilityRequirements = tc.topology
1018
+ sourceVolumeRequest .AccessibilityRequirements = tc .topology
979
1019
}
980
1020
981
1021
if tc .volumeOnCloud {
982
1022
// Create the source volume.
983
- gceDriver .cs .CreateVolume (context .Background (), sourceVolumeRequest )
1023
+ sourceVolume , _ := gceDriver .cs .CreateVolume (context .Background (), sourceVolumeRequest )
1024
+ req .VolumeContentSource = & csi.VolumeContentSource {
1025
+ Type : & csi.VolumeContentSource_Volume {
1026
+ Volume : & csi.VolumeContentSource_VolumeSource {
1027
+ VolumeId : sourceVolume .GetVolume ().VolumeId ,
1028
+ },
1029
+ },
1030
+ }
984
1031
}
1032
+
985
1033
resp , err := gceDriver .cs .CreateVolume (context .Background (), req )
986
1034
t .Logf ("response: %v err: %v" , resp , err )
987
1035
if err != nil {
0 commit comments