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
This commit is contained in:
parent
52d6cd941c
commit
c17f1e14cf
|
@ -9,5 +9,6 @@ nova/virt/libvirt/machine_type_utils.py
|
||||||
nova/virt/libvirt/__init__.py
|
nova/virt/libvirt/__init__.py
|
||||||
nova/virt/libvirt/driver.py
|
nova/virt/libvirt/driver.py
|
||||||
nova/virt/libvirt/event.py
|
nova/virt/libvirt/event.py
|
||||||
|
nova/virt/libvirt/guest.py
|
||||||
nova/virt/libvirt/host.py
|
nova/virt/libvirt/host.py
|
||||||
nova/virt/libvirt/utils.py
|
nova/virt/libvirt/utils.py
|
||||||
|
|
|
@ -6032,7 +6032,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
|
|
||||||
def _add_vtpm_device(
|
def _add_vtpm_device(
|
||||||
self,
|
self,
|
||||||
guest: libvirt_guest.Guest,
|
guest: vconfig.LibvirtConfigGuest,
|
||||||
flavor: 'objects.Flavor',
|
flavor: 'objects.Flavor',
|
||||||
instance: 'objects.Instance',
|
instance: 'objects.Instance',
|
||||||
image_meta: 'objects.ImageMeta',
|
image_meta: 'objects.ImageMeta',
|
||||||
|
@ -6225,7 +6225,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
|
|
||||||
def _configure_guest_by_virt_type(
|
def _configure_guest_by_virt_type(
|
||||||
self,
|
self,
|
||||||
guest: libvirt_guest.Guest,
|
guest: vconfig.LibvirtConfigGuest,
|
||||||
instance: 'objects.Instance',
|
instance: 'objects.Instance',
|
||||||
image_meta: 'objects.ImageMeta',
|
image_meta: 'objects.ImageMeta',
|
||||||
flavor: 'objects.Flavor',
|
flavor: 'objects.Flavor',
|
||||||
|
@ -6327,7 +6327,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
|
|
||||||
def _conf_non_lxc(
|
def _conf_non_lxc(
|
||||||
self,
|
self,
|
||||||
guest: libvirt_guest.Guest,
|
guest: vconfig.LibvirtConfigGuest,
|
||||||
root_device_name: str,
|
root_device_name: str,
|
||||||
rescue: bool,
|
rescue: bool,
|
||||||
instance: 'objects.Instance',
|
instance: 'objects.Instance',
|
||||||
|
@ -7258,7 +7258,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
pause = bool(events)
|
pause = bool(events)
|
||||||
guest: libvirt_guest.Guest = None
|
guest: ty.Optional[libvirt_guest.Guest] = None
|
||||||
try:
|
try:
|
||||||
with self.virtapi.wait_for_instance_event(
|
with self.virtapi.wait_for_instance_event(
|
||||||
instance, events, deadline=timeout,
|
instance, events, deadline=timeout,
|
||||||
|
@ -7304,6 +7304,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||||
cleanup_instance_disks=cleanup_instance_disks)
|
cleanup_instance_disks=cleanup_instance_disks)
|
||||||
# Resume only if domain has been paused
|
# Resume only if domain has been paused
|
||||||
if pause:
|
if pause:
|
||||||
|
assert guest is not None
|
||||||
guest.resume()
|
guest.resume()
|
||||||
return guest
|
return guest
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ then used by all the other libvirt related classes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
import typing as ty
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
@ -41,7 +42,11 @@ from nova.i18n import _
|
||||||
from nova.virt import hardware
|
from nova.virt import hardware
|
||||||
from nova.virt.libvirt import config as vconfig
|
from nova.virt.libvirt import config as vconfig
|
||||||
|
|
||||||
libvirt = None
|
|
||||||
|
if ty.TYPE_CHECKING:
|
||||||
|
import libvirt
|
||||||
|
else:
|
||||||
|
libvirt = None
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue