Skip to content

Commit 039a9a5

Browse files
author
Takashi Matsuo
authored
[compute] fix: use unique disk name (#3493)
fixes #3010
1 parent af1f587 commit 039a9a5

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

compute/encryption/generate_wrapped_rsa_key_test.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# limitations under the License.
1313

1414
import os
15+
import uuid
1516

1617
import googleapiclient.discovery
1718

@@ -32,20 +33,22 @@ def test_create_disk():
3233
google_public_key = generate_wrapped_rsa_key.get_google_public_cert_key()
3334
wrapped_rsa_key = generate_wrapped_rsa_key.wrap_rsa_key(
3435
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()

0 commit comments

Comments
 (0)