@@ -898,23 +898,28 @@ func TestCreateVolumeWithVolumeSourceFromSnapshot(t *testing.T) {
898
898
}
899
899
900
900
func TestCreateVolumeWithVolumeSourceFromVolume (t * testing.T ) {
901
+
901
902
testSourceVolumeName := "test-volume-source-name"
902
903
testZonalVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , testSourceVolumeName )
903
904
testRegionalVolumeSourceID := fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , region , testSourceVolumeName )
904
- testVolumeSourceIDDifferentZone := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , "different-zone" , testSourceVolumeName )
905
+ testSecondZonalVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , "different-zone1" , testSourceVolumeName )
906
+ zonalParams := map [string ]string {
907
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : replicationTypeNone ,
908
+ }
909
+ regionalParams := map [string ]string {
910
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : replicationTypeRegionalPD ,
911
+ }
905
912
topology := & csi.TopologyRequirement {
906
913
Requisite : []* csi.Topology {
907
914
{
908
- Segments : map [string ]string {common .TopologyKeyZone : region + "-b" },
915
+ Segments : map [string ]string {common .TopologyKeyZone : zone },
909
916
},
910
917
{
911
- Segments : map [string ]string {common .TopologyKeyZone : region + "-c" },
918
+ Segments : map [string ]string {common .TopologyKeyZone : secondZone },
912
919
},
913
920
},
914
921
}
915
- regionalParams := map [string ]string {
916
- common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : "regional-pd" ,
917
- }
922
+
918
923
// Define test cases
919
924
testCases := []struct {
920
925
name string
@@ -923,67 +928,115 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
923
928
sourceVolumeID string
924
929
reqParameters map [string ]string
925
930
sourceReqParameters map [string ]string
926
- topology * csi.TopologyRequirement
931
+ sourceTopology * csi.TopologyRequirement
932
+ requestTopology * csi.TopologyRequirement
927
933
}{
928
934
{
929
- name : "success with data source of zonal volume type " ,
935
+ name : "success zonal disk clone of zonal source disk " ,
930
936
volumeOnCloud : true ,
931
937
sourceVolumeID : testZonalVolumeSourceID ,
932
- reqParameters : stdParams ,
933
- sourceReqParameters : stdParams ,
938
+ reqParameters : zonalParams ,
939
+ sourceReqParameters : zonalParams ,
940
+ sourceTopology : topology ,
941
+ requestTopology : topology ,
934
942
},
935
943
{
936
- name : "success with data source of regional volume type " ,
944
+ name : "success regional disk clone of regional source disk " ,
937
945
volumeOnCloud : true ,
938
946
sourceVolumeID : testRegionalVolumeSourceID ,
939
947
reqParameters : regionalParams ,
940
948
sourceReqParameters : regionalParams ,
941
- topology : topology ,
949
+ sourceTopology : topology ,
950
+ requestTopology : topology ,
942
951
},
943
952
{
944
- name : "fail with with data source of replication-type different from CreateVolumeRequest " ,
953
+ name : "success regional disk clone of zonal data source " ,
945
954
volumeOnCloud : true ,
946
- expErrCode : codes .InvalidArgument ,
947
- sourceVolumeID : testZonalVolumeSourceID ,
948
- reqParameters : stdParams ,
949
- sourceReqParameters : regionalParams ,
950
- topology : topology ,
951
- },
952
- {
953
- name : "fail with data source of zonal volume type that doesn't exist" ,
954
- volumeOnCloud : false ,
955
- expErrCode : codes .NotFound ,
956
955
sourceVolumeID : testZonalVolumeSourceID ,
957
- reqParameters : stdParams ,
958
- sourceReqParameters : stdParams ,
956
+ reqParameters : regionalParams ,
957
+ sourceReqParameters : zonalParams ,
958
+ sourceTopology : topology ,
959
+ requestTopology : topology ,
959
960
},
960
961
{
961
- name : "fail with data source of zonal volume type with invalid volume id format " ,
962
- volumeOnCloud : false ,
962
+ name : "fail regional disk clone with no matching replica zone of zonal data source " ,
963
+ volumeOnCloud : true ,
963
964
expErrCode : codes .InvalidArgument ,
964
- sourceVolumeID : testZonalVolumeSourceID + "invalid/format" ,
965
- reqParameters : stdParams ,
966
- sourceReqParameters : stdParams ,
965
+ sourceVolumeID : testZonalVolumeSourceID ,
966
+ reqParameters : regionalParams ,
967
+ sourceReqParameters : zonalParams ,
968
+ sourceTopology : topology ,
969
+ requestTopology : & csi.TopologyRequirement {
970
+ Requisite : []* csi.Topology {
971
+ {
972
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone1" },
973
+ },
974
+ {
975
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone2" },
976
+ },
977
+ },
978
+ },
967
979
},
968
980
{
969
- name : "fail with data source of zonal volume type with invalid disk parameters " ,
981
+ name : "fail zonal disk clone with different disk type " ,
970
982
volumeOnCloud : true ,
971
983
expErrCode : codes .InvalidArgument ,
972
- sourceVolumeID : testVolumeSourceIDDifferentZone ,
973
- reqParameters : stdParams ,
984
+ sourceVolumeID : testZonalVolumeSourceID ,
985
+ reqParameters : zonalParams ,
974
986
sourceReqParameters : map [string ]string {
975
987
common .ParameterKeyType : "different-type" ,
976
988
},
989
+ sourceTopology : topology ,
990
+ requestTopology : topology ,
991
+ },
992
+ {
993
+ name : "fail zonal disk clone with different zone" ,
994
+ volumeOnCloud : true ,
995
+ expErrCode : codes .InvalidArgument ,
996
+ sourceVolumeID : testSecondZonalVolumeSourceID ,
997
+ reqParameters : zonalParams ,
998
+ sourceReqParameters : zonalParams ,
999
+ sourceTopology : & csi.TopologyRequirement {
1000
+ Requisite : []* csi.Topology {
1001
+ {
1002
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone1" },
1003
+ },
1004
+ {
1005
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone2" },
1006
+ },
1007
+ },
1008
+ },
1009
+ requestTopology : topology ,
977
1010
},
978
1011
{
979
- name : "fail with data source of zonal volume type with invalid replication type " ,
1012
+ name : "fail zonal disk clone of regional data source " ,
980
1013
volumeOnCloud : true ,
981
1014
expErrCode : codes .InvalidArgument ,
1015
+ sourceVolumeID : testRegionalVolumeSourceID ,
1016
+ reqParameters : zonalParams ,
1017
+ sourceReqParameters : regionalParams ,
1018
+ sourceTopology : topology ,
1019
+ requestTopology : topology ,
1020
+ },
1021
+
1022
+ {
1023
+ name : "fail zonal source disk does not exist" ,
1024
+ volumeOnCloud : false ,
1025
+ expErrCode : codes .NotFound ,
982
1026
sourceVolumeID : testZonalVolumeSourceID ,
983
- reqParameters : regionalParams ,
1027
+ reqParameters : stdParams ,
984
1028
sourceReqParameters : stdParams ,
1029
+ requestTopology : topology ,
985
1030
},
986
- }
1031
+ {
1032
+ name : "fail invalid source disk volume id format" ,
1033
+ volumeOnCloud : false ,
1034
+ expErrCode : codes .InvalidArgument ,
1035
+ sourceVolumeID : testZonalVolumeSourceID + "/invalid/format" ,
1036
+ reqParameters : stdParams ,
1037
+ sourceReqParameters : stdParams ,
1038
+ requestTopology : topology ,
1039
+ }}
987
1040
988
1041
for _ , tc := range testCases {
989
1042
t .Logf ("test case: %s" , tc .name )
@@ -1001,18 +1054,15 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
1001
1054
},
1002
1055
},
1003
1056
},
1057
+ AccessibilityRequirements : tc .requestTopology ,
1004
1058
}
1005
1059
1006
1060
sourceVolumeRequest := & csi.CreateVolumeRequest {
1007
- Name : testSourceVolumeName ,
1008
- CapacityRange : stdCapRange ,
1009
- VolumeCapabilities : stdVolCaps ,
1010
- Parameters : tc .sourceReqParameters ,
1011
- }
1012
-
1013
- if tc .topology != nil {
1014
- // req.AccessibilityRequirements = tc.topology
1015
- sourceVolumeRequest .AccessibilityRequirements = tc .topology
1061
+ Name : testSourceVolumeName ,
1062
+ CapacityRange : stdCapRange ,
1063
+ VolumeCapabilities : stdVolCaps ,
1064
+ Parameters : tc .sourceReqParameters ,
1065
+ AccessibilityRequirements : tc .sourceTopology ,
1016
1066
}
1017
1067
1018
1068
if tc .volumeOnCloud {
@@ -1045,7 +1095,6 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
1045
1095
1046
1096
// Make sure the response has the source volume.
1047
1097
sourceVolume := resp .GetVolume ()
1048
- t .Logf ("response has source volume: %v " , sourceVolume )
1049
1098
if sourceVolume .ContentSource == nil || sourceVolume .ContentSource .Type == nil ||
1050
1099
sourceVolume .ContentSource .GetVolume () == nil || sourceVolume .ContentSource .GetVolume ().VolumeId == "" {
1051
1100
t .Fatalf ("Expected volume content source to have volume ID, got none" )
0 commit comments