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