@@ -1001,23 +1001,30 @@ func TestCreateVolumeWithVolumeSourceFromSnapshot(t *testing.T) {
1001
1001
}
1002
1002
1003
1003
func TestCreateVolumeWithVolumeSourceFromVolume (t * testing.T ) {
1004
+
1004
1005
testSourceVolumeName := "test-volume-source-name"
1005
1006
testZonalVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , zone , testSourceVolumeName )
1006
1007
testRegionalVolumeSourceID := fmt .Sprintf ("projects/%s/regions/%s/disks/%s" , project , region , testSourceVolumeName )
1007
- testVolumeSourceIDDifferentZone := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , "different-zone" , testSourceVolumeName )
1008
+ testSecondZonalVolumeSourceID := fmt .Sprintf ("projects/%s/zones/%s/disks/%s" , project , "different-zone1" , testSourceVolumeName )
1009
+ zonalParams := map [string ]string {
1010
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : replicationTypeNone ,
1011
+ common .ParameterKeyDiskEncryptionKmsKey : "encryption-key" ,
1012
+ }
1013
+ regionalParams := map [string ]string {
1014
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : replicationTypeRegionalPD ,
1015
+ common .ParameterKeyDiskEncryptionKmsKey : "encryption-key" ,
1016
+ }
1008
1017
topology := & csi.TopologyRequirement {
1009
1018
Requisite : []* csi.Topology {
1010
1019
{
1011
- Segments : map [string ]string {common .TopologyKeyZone : region + "-b" },
1020
+ Segments : map [string ]string {common .TopologyKeyZone : zone },
1012
1021
},
1013
1022
{
1014
- Segments : map [string ]string {common .TopologyKeyZone : region + "-c" },
1023
+ Segments : map [string ]string {common .TopologyKeyZone : secondZone },
1015
1024
},
1016
1025
},
1017
1026
}
1018
- regionalParams := map [string ]string {
1019
- common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : "regional-pd" ,
1020
- }
1027
+
1021
1028
// Define test cases
1022
1029
testCases := []struct {
1023
1030
name string
@@ -1026,67 +1033,128 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
1026
1033
sourceVolumeID string
1027
1034
reqParameters map [string ]string
1028
1035
sourceReqParameters map [string ]string
1029
- topology * csi.TopologyRequirement
1036
+ sourceTopology * csi.TopologyRequirement
1037
+ requestTopology * csi.TopologyRequirement
1030
1038
}{
1031
1039
{
1032
- name : "success with data source of zonal volume type " ,
1040
+ name : "success zonal disk clone of zonal source disk " ,
1033
1041
volumeOnCloud : true ,
1034
1042
sourceVolumeID : testZonalVolumeSourceID ,
1035
- reqParameters : stdParams ,
1036
- sourceReqParameters : stdParams ,
1043
+ reqParameters : zonalParams ,
1044
+ sourceReqParameters : zonalParams ,
1045
+ sourceTopology : topology ,
1046
+ requestTopology : topology ,
1037
1047
},
1038
1048
{
1039
- name : "success with data source of regional volume type " ,
1049
+ name : "success regional disk clone of regional source disk " ,
1040
1050
volumeOnCloud : true ,
1041
1051
sourceVolumeID : testRegionalVolumeSourceID ,
1042
1052
reqParameters : regionalParams ,
1043
1053
sourceReqParameters : regionalParams ,
1044
- topology : topology ,
1054
+ sourceTopology : topology ,
1055
+ requestTopology : topology ,
1045
1056
},
1046
1057
{
1047
- name : "fail with with data source of replication-type different from CreateVolumeRequest " ,
1058
+ name : "success regional disk clone of zonal data source " ,
1048
1059
volumeOnCloud : true ,
1049
- expErrCode : codes .InvalidArgument ,
1050
1060
sourceVolumeID : testZonalVolumeSourceID ,
1051
- reqParameters : stdParams ,
1052
- sourceReqParameters : regionalParams ,
1053
- topology : topology ,
1061
+ reqParameters : regionalParams ,
1062
+ sourceReqParameters : zonalParams ,
1063
+ sourceTopology : topology ,
1064
+ requestTopology : topology ,
1054
1065
},
1055
1066
{
1056
- name : "fail with data source of zonal volume type that doesn't exist " ,
1057
- volumeOnCloud : false ,
1058
- expErrCode : codes .NotFound ,
1067
+ name : "fail regional disk clone with no matching replica zone of zonal data source " ,
1068
+ volumeOnCloud : true ,
1069
+ expErrCode : codes .InvalidArgument ,
1059
1070
sourceVolumeID : testZonalVolumeSourceID ,
1060
- reqParameters : stdParams ,
1061
- sourceReqParameters : stdParams ,
1071
+ reqParameters : regionalParams ,
1072
+ sourceReqParameters : zonalParams ,
1073
+ sourceTopology : topology ,
1074
+ requestTopology : & csi.TopologyRequirement {
1075
+ Requisite : []* csi.Topology {
1076
+ {
1077
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone1" },
1078
+ },
1079
+ {
1080
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone2" },
1081
+ },
1082
+ },
1083
+ },
1062
1084
},
1063
1085
{
1064
- name : "fail with data source of zonal volume type with invalid volume id format" ,
1065
- volumeOnCloud : false ,
1066
- expErrCode : codes .InvalidArgument ,
1067
- sourceVolumeID : testZonalVolumeSourceID + "invalid/format" ,
1068
- reqParameters : stdParams ,
1069
- sourceReqParameters : stdParams ,
1086
+ name : "fail zonal disk clone with different disk type" ,
1087
+ volumeOnCloud : true ,
1088
+ expErrCode : codes .InvalidArgument ,
1089
+ sourceVolumeID : testZonalVolumeSourceID ,
1090
+ reqParameters : zonalParams ,
1091
+ sourceReqParameters : map [string ]string {
1092
+ common .ParameterKeyType : "different-type" ,
1093
+ },
1094
+ sourceTopology : topology ,
1095
+ requestTopology : topology ,
1070
1096
},
1071
1097
{
1072
- name : "fail with data source of zonal volume type with invalid disk parameters " ,
1098
+ name : "fail zonal disk clone with different DiskEncryptionKMSKey " ,
1073
1099
volumeOnCloud : true ,
1074
1100
expErrCode : codes .InvalidArgument ,
1075
- sourceVolumeID : testVolumeSourceIDDifferentZone ,
1076
- reqParameters : stdParams ,
1101
+ sourceVolumeID : testZonalVolumeSourceID ,
1102
+ reqParameters : zonalParams ,
1077
1103
sourceReqParameters : map [string ]string {
1078
- common .ParameterKeyType : "different-type" ,
1104
+ common .ParameterKeyType : "test-type" , common .ParameterKeyReplicationType : replicationTypeNone ,
1105
+ common .ParameterKeyDiskEncryptionKmsKey : "different-encryption-key" ,
1079
1106
},
1107
+ sourceTopology : topology ,
1108
+ requestTopology : topology ,
1080
1109
},
1081
1110
{
1082
- name : "fail with data source of zonal volume type with invalid replication type " ,
1111
+ name : "fail zonal disk clone with different zone " ,
1083
1112
volumeOnCloud : true ,
1084
1113
expErrCode : codes .InvalidArgument ,
1114
+ sourceVolumeID : testSecondZonalVolumeSourceID ,
1115
+ reqParameters : zonalParams ,
1116
+ sourceReqParameters : zonalParams ,
1117
+ sourceTopology : & csi.TopologyRequirement {
1118
+ Requisite : []* csi.Topology {
1119
+ {
1120
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone1" },
1121
+ },
1122
+ {
1123
+ Segments : map [string ]string {common .TopologyKeyZone : "different-zone2" },
1124
+ },
1125
+ },
1126
+ },
1127
+ requestTopology : topology ,
1128
+ },
1129
+ {
1130
+ name : "fail zonal disk clone of regional data source" ,
1131
+ volumeOnCloud : true ,
1132
+ expErrCode : codes .InvalidArgument ,
1133
+ sourceVolumeID : testRegionalVolumeSourceID ,
1134
+ reqParameters : zonalParams ,
1135
+ sourceReqParameters : regionalParams ,
1136
+ sourceTopology : topology ,
1137
+ requestTopology : topology ,
1138
+ },
1139
+
1140
+ {
1141
+ name : "fail zonal source disk does not exist" ,
1142
+ volumeOnCloud : false ,
1143
+ expErrCode : codes .NotFound ,
1085
1144
sourceVolumeID : testZonalVolumeSourceID ,
1086
- reqParameters : regionalParams ,
1145
+ reqParameters : stdParams ,
1087
1146
sourceReqParameters : stdParams ,
1147
+ requestTopology : topology ,
1088
1148
},
1089
- }
1149
+ {
1150
+ name : "fail invalid source disk volume id format" ,
1151
+ volumeOnCloud : false ,
1152
+ expErrCode : codes .InvalidArgument ,
1153
+ sourceVolumeID : testZonalVolumeSourceID + "/invalid/format" ,
1154
+ reqParameters : stdParams ,
1155
+ sourceReqParameters : stdParams ,
1156
+ requestTopology : topology ,
1157
+ }}
1090
1158
1091
1159
for _ , tc := range testCases {
1092
1160
t .Logf ("test case: %s" , tc .name )
@@ -1104,18 +1172,15 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
1104
1172
},
1105
1173
},
1106
1174
},
1175
+ AccessibilityRequirements : tc .requestTopology ,
1107
1176
}
1108
1177
1109
1178
sourceVolumeRequest := & csi.CreateVolumeRequest {
1110
- Name : testSourceVolumeName ,
1111
- CapacityRange : stdCapRange ,
1112
- VolumeCapabilities : stdVolCaps ,
1113
- Parameters : tc .sourceReqParameters ,
1114
- }
1115
-
1116
- if tc .topology != nil {
1117
- // req.AccessibilityRequirements = tc.topology
1118
- sourceVolumeRequest .AccessibilityRequirements = tc .topology
1179
+ Name : testSourceVolumeName ,
1180
+ CapacityRange : stdCapRange ,
1181
+ VolumeCapabilities : stdVolCaps ,
1182
+ Parameters : tc .sourceReqParameters ,
1183
+ AccessibilityRequirements : tc .sourceTopology ,
1119
1184
}
1120
1185
1121
1186
if tc .volumeOnCloud {
@@ -1148,7 +1213,6 @@ func TestCreateVolumeWithVolumeSourceFromVolume(t *testing.T) {
1148
1213
1149
1214
// Make sure the response has the source volume.
1150
1215
sourceVolume := resp .GetVolume ()
1151
- t .Logf ("response has source volume: %v " , sourceVolume )
1152
1216
if sourceVolume .ContentSource == nil || sourceVolume .ContentSource .Type == nil ||
1153
1217
sourceVolume .ContentSource .GetVolume () == nil || sourceVolume .ContentSource .GetVolume ().VolumeId == "" {
1154
1218
t .Fatalf ("Expected volume content source to have volume ID, got none" )
0 commit comments