Browse Source

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 c17f1e14cf)
changes/22/788722/2
Balazs Gibizer 4 months ago
parent
commit
3fcd11a403
3 changed files with 12 additions and 5 deletions
  1. +1
    -0
      mypy-files.txt
  2. +5
    -4
      nova/virt/libvirt/driver.py
  3. +6
    -1
      nova/virt/libvirt/guest.py

+ 1
- 0
mypy-files.txt View File

@ -9,5 +9,6 @@ nova/virt/libvirt/machine_type_utils.py
nova/virt/libvirt/__init__.py
nova/virt/libvirt/driver.py
nova/virt/libvirt/event.py
nova/virt/libvirt/guest.py
nova/virt/libvirt/host.py
nova/virt/libvirt/utils.py

+ 5
- 4
nova/virt/libvirt/driver.py View File

@ -6032,7 +6032,7 @@ class LibvirtDriver(driver.ComputeDriver):
def _add_vtpm_device(
self,
guest: libvirt_guest.Guest,
guest: vconfig.LibvirtConfigGuest,
flavor: 'objects.Flavor',
instance: 'objects.Instance',
image_meta: 'objects.ImageMeta',
@ -6225,7 +6225,7 @@ class LibvirtDriver(driver.ComputeDriver):
def _configure_guest_by_virt_type(
self,
guest: libvirt_guest.Guest,
guest: vconfig.LibvirtConfigGuest,
instance: 'objects.Instance',
image_meta: 'objects.ImageMeta',
flavor: 'objects.Flavor',
@ -6327,7 +6327,7 @@ class LibvirtDriver(driver.ComputeDriver):
def _conf_non_lxc(
self,
guest: libvirt_guest.Guest,
guest: vconfig.LibvirtConfigGuest,
root_device_name: str,
rescue: bool,
instance: 'objects.Instance',
@ -7258,7 +7258,7 @@ class LibvirtDriver(driver.ComputeDriver):
events = []
pause = bool(events)
guest: libvirt_guest.Guest = None
guest: ty.Optional[libvirt_guest.Guest] = None
try:
with self.virtapi.wait_for_instance_event(
instance, events, deadline=timeout,
@ -7304,6 +7304,7 @@ class LibvirtDriver(driver.ComputeDriver):
cleanup_instance_disks=cleanup_instance_disks)
# Resume only if domain has been paused
if pause:
assert guest is not None
guest.resume()
return guest


+ 6
- 1
nova/virt/libvirt/guest.py View File

@ -28,6 +28,7 @@ then used by all the other libvirt related classes
"""
import time
import typing as ty
from lxml import etree
from oslo_log import log as logging
@ -41,7 +42,11 @@ from nova.i18n import _
from nova.virt import hardware
from nova.virt.libvirt import config as vconfig
libvirt = None
if ty.TYPE_CHECKING:
import libvirt
else:
libvirt = None
LOG = logging.getLogger(__name__)


Loading…
Cancel
Save