19
19
import static com .google .common .truth .Truth .assertThat ;
20
20
import static com .google .common .truth .Truth .assertWithMessage ;
21
21
import static org .junit .Assert .assertEquals ;
22
+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
22
23
23
24
import com .google .cloud .compute .v1 .AttachedDisk ;
24
25
import com .google .cloud .compute .v1 .AttachedDiskInitializeParams ;
37
38
import com .google .cloud .compute .v1 .SnapshotsClient ;
38
39
import compute .DeleteInstance ;
39
40
import compute .Util ;
41
+ import compute .snapshotschedule .CreateSnapshotSchedule ;
42
+ import compute .snapshotschedule .DeleteSnapshotSchedule ;
40
43
import java .io .ByteArrayOutputStream ;
41
44
import java .io .IOException ;
42
45
import java .io .PrintStream ;
@@ -81,7 +84,8 @@ public class DisksIT {
81
84
private static String SECONDARY_DISK ;
82
85
private static final long DISK_SIZE = 10L ;
83
86
private static String SECONDARY_CUSTOM_DISK ;
84
-
87
+ private static String DISK_WITH_SNAPSHOT_SCHEDULE ;
88
+ private static String SNAPSHOT_SCHEDULE ;
85
89
private ByteArrayOutputStream stdOut ;
86
90
87
91
// Check if the required environment variables are set.
@@ -113,6 +117,8 @@ public static void setup()
113
117
SECONDARY_REGIONAL_DISK = "gcloud-test-disk-secondary-regional-" + uuid ;
114
118
SECONDARY_DISK = "gcloud-test-disk-secondary-" + uuid ;
115
119
SECONDARY_CUSTOM_DISK = "gcloud-test-disk-custom-" + uuid ;
120
+ DISK_WITH_SNAPSHOT_SCHEDULE = "gcloud-test-disk-shapshot-" + uuid ;
121
+ SNAPSHOT_SCHEDULE = "gcloud-test-snapshot-schedule-" + uuid ;
116
122
117
123
// Cleanup existing stale resources.
118
124
Util .cleanUpExistingInstances ("test-disks" , PROJECT_ID , ZONE );
@@ -122,6 +128,7 @@ public static void setup()
122
128
"gcloud-test-disk-secondary-regional-" , PROJECT_ID , "us-central1" );
123
129
Util .cleanUpExistingRegionalDisks ("gcloud-test-disk-" , PROJECT_ID , REGION );
124
130
Util .cleanUpExistingSnapshots ("gcloud-test-snapshot-" , PROJECT_ID );
131
+ Util .cleanUpExistingSnapshotSchedule ("gcloud-test-snapshot-schedule-" , PROJECT_ID , REGION );
125
132
126
133
// Create disk from image.
127
134
Image debianImage = null ;
@@ -154,7 +161,8 @@ public static void setup()
154
161
TimeUnit .SECONDS .sleep (10 );
155
162
SetDiskAutodelete .setDiskAutodelete (PROJECT_ID , ZONE , INSTANCE_NAME , DISK_NAME , true );
156
163
assertThat (stdOut .toString ()).contains ("Disk autodelete field updated." );
157
-
164
+ CreateSnapshotSchedule .createSnapshotSchedule (PROJECT_ID , REGION , SNAPSHOT_SCHEDULE ,
165
+ "description" , 10 , "US" );
158
166
// Create zonal and regional blank disks for testing attach and resize.
159
167
createZonalDisk ();
160
168
createRegionalDisk ();
@@ -191,6 +199,8 @@ public static void cleanUp()
191
199
RegionalDelete .deleteRegionalDisk (PROJECT_ID , "us-central1" , SECONDARY_REGIONAL_DISK );
192
200
DeleteDisk .deleteDisk (PROJECT_ID , "us-central1-c" , SECONDARY_DISK );
193
201
DeleteDisk .deleteDisk (PROJECT_ID , "us-central1-c" , SECONDARY_CUSTOM_DISK );
202
+ DeleteDisk .deleteDisk (PROJECT_ID , ZONE , DISK_WITH_SNAPSHOT_SCHEDULE );
203
+ DeleteSnapshotSchedule .deleteSnapshotSchedule (PROJECT_ID , REGION , SNAPSHOT_SCHEDULE );
194
204
195
205
stdOut .close ();
196
206
System .setOut (out );
@@ -325,24 +335,28 @@ public void testCreateReplicatedDisk()
325
335
throws IOException , ExecutionException , InterruptedException , TimeoutException {
326
336
Status status = CreateReplicatedDisk .createReplicatedDisk (PROJECT_ID , REGION ,
327
337
replicaZones , REGIONAL_REPLICATED_DISK , 100 , DISK_TYPE );
328
- Disk disk = Util .getRegionalDisk (PROJECT_ID , REGION , REGIONAL_REPLICATED_DISK );
329
338
330
339
assertThat (status ).isEqualTo (Status .DONE );
331
- assertEquals (REGIONAL_REPLICATED_DISK , disk .getName ());
340
+ assertDoesNotThrow (() -> {
341
+ Disk disk = Util .getRegionalDisk (PROJECT_ID , REGION , REGIONAL_REPLICATED_DISK );
342
+ assertEquals (REGIONAL_REPLICATED_DISK , disk .getName ());
343
+ });
332
344
}
333
345
334
346
@ Test
335
347
public void testCreateDiskSecondaryRegional ()
336
348
throws IOException , ExecutionException , InterruptedException , TimeoutException {
337
- String diskType = String .format (
349
+ String diskType = String .format (
338
350
"projects/%s/regions/%s/diskTypes/pd-balanced" , PROJECT_ID , REGION );
339
351
Status status = CreateDiskSecondaryRegional .createDiskSecondaryRegional (
340
352
PROJECT_ID , PROJECT_ID , REGIONAL_BLANK_DISK , SECONDARY_REGIONAL_DISK ,
341
353
REGION , "us-central1" , DISK_SIZE , diskType );
342
- Disk disk = Util .getRegionalDisk (PROJECT_ID , "us-central1" , SECONDARY_REGIONAL_DISK );
343
354
344
355
assertThat (status ).isEqualTo (Status .DONE );
345
- assertEquals (SECONDARY_REGIONAL_DISK , disk .getName ());
356
+ assertDoesNotThrow (() -> {
357
+ Disk disk = Util .getRegionalDisk (PROJECT_ID , "us-central1" , SECONDARY_REGIONAL_DISK );
358
+ assertEquals (SECONDARY_REGIONAL_DISK , disk .getName ());
359
+ });
346
360
}
347
361
348
362
@ Test
@@ -353,10 +367,12 @@ public void testCreateDiskSecondaryZonal()
353
367
Status status = CreateDiskSecondaryZonal .createDiskSecondaryZonal (
354
368
PROJECT_ID , PROJECT_ID , EMPTY_DISK_NAME , SECONDARY_DISK , ZONE ,
355
369
"us-central1-c" , DISK_SIZE , diskType );
356
- Disk disk = Util .getDisk (PROJECT_ID , "us-central1-c" , SECONDARY_DISK );
357
370
358
371
assertThat (status ).isEqualTo (Status .DONE );
359
- assertEquals (SECONDARY_DISK , disk .getName ());
372
+ assertDoesNotThrow (() -> {
373
+ Disk disk = Util .getDisk (PROJECT_ID , "us-central1-c" , SECONDARY_DISK );
374
+ assertEquals (SECONDARY_DISK , disk .getName ());
375
+ });
360
376
}
361
377
362
378
@ Test
@@ -367,9 +383,24 @@ public void testCreateSecondaryCustomDisk()
367
383
Status status = CreateSecondaryCustomDisk .createSecondaryCustomDisk (
368
384
PROJECT_ID , PROJECT_ID , EMPTY_DISK_NAME , SECONDARY_CUSTOM_DISK , ZONE ,
369
385
"us-central1-c" , DISK_SIZE , diskType );
370
- Disk disk = Util .getDisk (PROJECT_ID , "us-central1-c" , SECONDARY_CUSTOM_DISK );
371
386
372
387
assertThat (status ).isEqualTo (Status .DONE );
373
- assertEquals (SECONDARY_CUSTOM_DISK , disk .getName ());
388
+ assertDoesNotThrow (() -> {
389
+ Disk disk = Util .getDisk (PROJECT_ID , "us-central1-c" , SECONDARY_CUSTOM_DISK );
390
+ assertEquals (SECONDARY_CUSTOM_DISK , disk .getName ());
391
+ });
392
+ }
393
+
394
+ @ Test
395
+ void testCreateDiskWithSnapshotSchedule ()
396
+ throws IOException , ExecutionException , InterruptedException , TimeoutException {
397
+ Status status = CreateDiskWithSnapshotSchedule .createDiskWithSnapshotSchedule (
398
+ PROJECT_ID , ZONE , DISK_WITH_SNAPSHOT_SCHEDULE , SNAPSHOT_SCHEDULE );
399
+
400
+ assertThat (status ).isEqualTo (Status .DONE );
401
+ assertDoesNotThrow (() -> {
402
+ Disk disk = Util .getDisk (PROJECT_ID , ZONE , DISK_WITH_SNAPSHOT_SCHEDULE );
403
+ assertEquals (DISK_WITH_SNAPSHOT_SCHEDULE , disk .getName ());
404
+ });
374
405
}
375
406
}
0 commit comments