Skip to content

Commit 3fcd11a

Browse files
author
Balazs Gibizer
committed
Enable mypy on libvirt/guest.py
This patch fixes couple of thing that is needed to run mypy * fixed a wrong type hint in LibvirtDriver._add_vtpm_device, _configure_guest_by_virt_type, and _conf_non_lxc signature * fixed a local variable type hint in LibvirtDriver._create_guest_with_network * added an assert to _create_guest_with_network as the guest local variable can be None if we get eventlet.timeout.Timeout and CONF.vif_plugging_is_fatal is False. Change-Id: I42c579531bac61063a381598094720271364ec92 (cherry picked from commit c17f1e1)
1 parent 5f488d8 commit 3fcd11a

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

mypy-files.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ nova/virt/libvirt/machine_type_utils.py
99
nova/virt/libvirt/__init__.py
1010
nova/virt/libvirt/driver.py
1111
nova/virt/libvirt/event.py
12+
nova/virt/libvirt/guest.py
1213
nova/virt/libvirt/host.py
1314
nova/virt/libvirt/utils.py

nova/virt/libvirt/driver.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6032,7 +6032,7 @@ def _add_virtio_serial_controller(self, guest, instance):
60326032

60336033
def _add_vtpm_device(
60346034
self,
6035-
guest: libvirt_guest.Guest,
6035+
guest: vconfig.LibvirtConfigGuest,
60366036
flavor: 'objects.Flavor',
60376037
instance: 'objects.Instance',
60386038
image_meta: 'objects.ImageMeta',
@@ -6225,7 +6225,7 @@ def _get_supported_perf_events(self):
62256225

62266226
def _configure_guest_by_virt_type(
62276227
self,
6228-
guest: libvirt_guest.Guest,
6228+
guest: vconfig.LibvirtConfigGuest,
62296229
instance: 'objects.Instance',
62306230
image_meta: 'objects.ImageMeta',
62316231
flavor: 'objects.Flavor',
@@ -6327,7 +6327,7 @@ def _configure_guest_by_virt_type(
63276327

63286328
def _conf_non_lxc(
63296329
self,
6330-
guest: libvirt_guest.Guest,
6330+
guest: vconfig.LibvirtConfigGuest,
63316331
root_device_name: str,
63326332
rescue: bool,
63336333
instance: 'objects.Instance',
@@ -7258,7 +7258,7 @@ def _create_guest_with_network(self, context, xml, instance, network_info,
72587258
events = []
72597259

72607260
pause = bool(events)
7261-
guest: libvirt_guest.Guest = None
7261+
guest: ty.Optional[libvirt_guest.Guest] = None
72627262
try:
72637263
with self.virtapi.wait_for_instance_event(
72647264
instance, events, deadline=timeout,
@@ -7304,6 +7304,7 @@ def _create_guest_with_network(self, context, xml, instance, network_info,
73047304
cleanup_instance_disks=cleanup_instance_disks)
73057305
# Resume only if domain has been paused
73067306
if pause:
7307+
assert guest is not None
73077308
guest.resume()
73087309
return guest
73097310

nova/virt/libvirt/guest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"""
2929

3030
import time
31+
import typing as ty
3132

3233
from lxml import etree
3334
from oslo_log import log as logging
@@ -41,7 +42,11 @@
4142
from nova.virt import hardware
4243
from nova.virt.libvirt import config as vconfig
4344

44-
libvirt = None
45+
46+
if ty.TYPE_CHECKING:
47+
import libvirt
48+
else:
49+
libvirt = None
4550

4651
LOG = logging.getLogger(__name__)
4752

0 commit comments

Comments
 (0)