File tree Expand file tree Collapse file tree 1 file changed +20
-17
lines changed Expand file tree Collapse file tree 1 file changed +20
-17
lines changed Original file line number Diff line number Diff line change 12
12
# limitations under the License.
13
13
14
14
import os
15
+ import uuid
15
16
16
17
import googleapiclient .discovery
17
18
@@ -32,20 +33,22 @@ def test_create_disk():
32
33
google_public_key = generate_wrapped_rsa_key .get_google_public_cert_key ()
33
34
wrapped_rsa_key = generate_wrapped_rsa_key .wrap_rsa_key (
34
35
google_public_key , key_bytes )
35
-
36
- # Create the disk, if the encryption key is invalid, this will raise.
37
- compute .disks ().insert (
38
- project = PROJECT ,
39
- zone = 'us-central1-f' ,
40
- body = {
41
- 'name' : 'new-encrypted-disk' ,
42
- 'diskEncryptionKey' : {
43
- 'rsaEncryptedKey' : wrapped_rsa_key .decode ('utf-8' )
44
- }
45
- }).execute ()
46
-
47
- # Delete the disk.
48
- compute .disks ().delete (
49
- project = PROJECT ,
50
- zone = 'us-central1-f' ,
51
- disk = 'new-encrypted-disk' ).execute ()
36
+ disk_name = 'new-encrypted-disk-{}' .format (uuid .uuid4 ().hex )
37
+
38
+ try :
39
+ # Create the disk, if the encryption key is invalid, this will raise.
40
+ compute .disks ().insert (
41
+ project = PROJECT ,
42
+ zone = 'us-central1-f' ,
43
+ body = {
44
+ 'name' : disk_name ,
45
+ 'diskEncryptionKey' : {
46
+ 'rsaEncryptedKey' : wrapped_rsa_key .decode ('utf-8' )
47
+ }
48
+ }).execute ()
49
+ finally :
50
+ # Delete the disk.
51
+ compute .disks ().delete (
52
+ project = PROJECT ,
53
+ zone = 'us-central1-f' ,
54
+ disk = disk_name ).execute ()
You can’t perform that action at this time.
0 commit comments