From c21f08f0f6e94ef32a2d36b9aa0aef88b07f821b Mon Sep 17 00:00:00 2001 From: Balazs Gibizer Date: Mon, 3 Aug 2020 17:02:28 +0200 Subject: [PATCH] Move equality check into LibvirtConfigGuestInterface This is a pure refactoring that moves the equality check of LibvirtConfigGuestInterface objects from get_interface_by_cfg() into the class itself. Later this pattern will be extended to LibvirtConfigGuestHostdevPCI objects to support detaching direct physical interfaces where PCI address based equality is needed. Part of blueprint sriov-interface-attach-detach Change-Id: I6ce9457179f65f82ff721b315e51a67ebd879673 --- nova/virt/libvirt/config.py | 14 ++++++++++++++ nova/virt/libvirt/guest.py | 11 +++-------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/nova/virt/libvirt/config.py b/nova/virt/libvirt/config.py index 32dea36113..083c6f6934 100644 --- a/nova/virt/libvirt/config.py +++ b/nova/virt/libvirt/config.py @@ -1686,6 +1686,20 @@ class LibvirtConfigGuestInterface(LibvirtConfigGuestDevice): self.device_addr = None self.mtu = None + def __eq__(self, other): + if not isinstance(other, LibvirtConfigGuestInterface): + return False + + # NOTE(arches) Skip checking target_dev for vhostuser + # vif type; target_dev is not a valid value for vhostuser. + return ( + self.mac_addr == other.mac_addr and + self.net_type == other.net_type and + self.source_dev == other.source_dev and + (self.net_type == 'vhostuser' or + self.target_dev == other.target_dev) and + self.vhostuser_path == other.vhostuser_path) + @property def uses_virtio(self): return 'virtio' == self.model diff --git a/nova/virt/libvirt/guest.py b/nova/virt/libvirt/guest.py index 1a39ce5329..e70989fb69 100644 --- a/nova/virt/libvirt/guest.py +++ b/nova/virt/libvirt/guest.py @@ -246,14 +246,9 @@ class Guest(object): # NOTE(leehom) LibvirtConfigGuestInterface get from domain and # LibvirtConfigGuestInterface generated by # nova.virt.libvirt.vif.get_config must be identical. - # NOTE(arches) Skip checking target_dev for vhostuser - # vif type; target_dev is not a valid value for vhostuser. - if (interface.mac_addr == cfg.mac_addr and - interface.net_type == cfg.net_type and - interface.source_dev == cfg.source_dev and - (cfg.net_type == 'vhostuser' or - interface.target_dev == cfg.target_dev) and - interface.vhostuser_path == cfg.vhostuser_path): + # NOTE(gibi): LibvirtConfigGuestInterface does a custom + # equality check based on available information on nova side + if cfg == interface: return interface def get_vcpus_info(self):