Skip to content

Commit 298ca28

Browse files
committed
Resolve mypy error
This is causing lint failures in the requirements job. Change-Id: I7afc10130b77bdfb419bb68b670ec7ebecb4026b Signed-off-by: Stephen Finucane <[email protected]>
1 parent d28a559 commit 298ca28

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

nova/virt/libvirt/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,17 @@ def make_reverse_cpu_traits_mapping() -> ty.Dict[str, str]:
122122
VTPM_DIR = '/var/lib/libvirt/swtpm/'
123123

124124

125+
class EncryptionOptions(ty.TypedDict):
126+
secret: str
127+
format: str
128+
129+
125130
def create_image(
126131
path: str,
127132
disk_format: str,
128133
disk_size: ty.Optional[ty.Union[str, int]],
129134
backing_file: ty.Optional[str] = None,
130-
encryption: ty.Optional[ty.Dict[str, ty.Any]] = None
135+
encryption: ty.Optional[EncryptionOptions] = None
131136
) -> None:
132137
"""Disk image creation with qemu-img
133138
:param path: Desired location of the disk image
@@ -140,7 +145,7 @@ def create_image(
140145
Can be None in the case of a COW image.
141146
:param backing_file: (Optional) Backing file to use.
142147
:param encryption: (Optional) Dict detailing various encryption attributes
143-
such as the format and passphrase.
148+
such as the format and passphrase.
144149
"""
145150
cmd = [
146151
'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'create', '-f', disk_format
@@ -170,7 +175,7 @@ def create_image(
170175
if encryption:
171176
with tempfile.NamedTemporaryFile(mode='tr+', encoding='utf-8') as f:
172177
# Write out the passphrase secret to a temp file
173-
f.write(encryption.get('secret'))
178+
f.write(encryption['secret'])
174179

175180
# Ensure the secret is written to disk, we can't .close() here as
176181
# that removes the file when using NamedTemporaryFile
@@ -180,7 +185,7 @@ def create_image(
180185
encryption_opts = [
181186
'--object', f"secret,id=sec,file={f.name}",
182187
'-o', 'encrypt.key-secret=sec',
183-
'-o', f"encrypt.format={encryption.get('format')}",
188+
'-o', f"encrypt.format={encryption['format']}",
184189
]
185190
# Supported luks options:
186191
# cipher-alg=<str> - Name of cipher algorithm and key length

0 commit comments

Comments
 (0)